AwesomeVersion throwing an error with version string 0.13.0-0858859
jamezpolley opened this issue · comments
The problem
blakeblackshear/frigate-hass-integration#543
Version A properties:
{
"string": "0.13.0-0858859",
"alpha": false,
"beta": false,
"dev": false,
"major": null,
"micro": null,
"minor": null,
"modifier_type": null,
"modifier": null,
"patch": null,
"prefix": null,
"release_candidate": false,
"sections": 3,
"simple": false,
"strategy": "unknown",
"valid": false,
"year": null
}
Previous release works "fine" (I mean, for values of "fine" that include "there's no signifier that this is a beta")
Version A properties:
{
"string": "0.13.0-1c27ee2",
"alpha": false,
"beta": false,
"dev": false,
"major": "0",
"micro": "0",
"minor": "13",
"modifier_type": null,
"modifier": "1c27ee2",
"patch": "0",
"prefix": null,
"release_candidate": false,
"sections": 3,
"simple": false,
"strategy": "SemVer",
"valid": true,
"year": "0"
}
Operating system
whatever https://ludeeus.github.io/awesomeversion/ runs
Python version
3.8
Problem-relevant code
from awesomeversion import AwesomeVersion
AwesomeVersion("0.13.0-0858859") <= AwesomeVersion("0.8.4")
Traceback/Error logs
Traceback (most recent call last):
File "/home/pyodide/pyscript/_internal.py", line 104, in run_pyscript
result = eval_code(code, globals=__main__.__dict__)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python311.zip/_pyodide/_base.py", line 468, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File "/lib/python311.zip/_pyodide/_base.py", line 310, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 1, in <module>
File "<exec>", line 54, in extract_awesomeversion_properties
File "/lib/python3.11/site-packages/awesomeversion/awesomeversion.py", line 199, in __ne__
return not self.__eq__(compareto)
^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/awesomeversion/awesomeversion.py", line 163, in __eq__
raise AwesomeVersionCompareException("Not a valid AwesomeVersion object")
awesomeversion.exceptions.AwesomeVersionCompareException: Not a valid AwesomeVersion object
Additional information
I am guessing this is related to https://stackoverflow.com/questions/31447694/why-does-python-3-allow-00-as-a-literal-for-0-but-not-allow-01-as-a-literal (which points at https://docs.python.org/3/reference/lexical_analysis.html#integer-literals) - the modifier is an integer with a leading 0.
0.13.0-0A58859 works; but anything where the second digit is 1-9 fails.
0.13.0-0 works; 0.13.0-01 fails.
I can not see that it's a valid version.
Can you point me to the documentation for semver version that allows it?
I got similar errors with two workflows for HomeAssistant/HACS custom components:
- https://github.com/jpcornil-git/HA-mcp23017/actions/runs/6307379383/job/17123912685
- https://github.com/jpcornil-git/HA-sma/actions/runs/6307387670/job/17123931671
May be related to this commit ?
https://github.com/hacs/integration/pull/3274/files
Vastly unrelated to this issue... rerun the job.
I have looked at the semver docs, which are close to what's being tried here.
https://semver.org/
0 is not allowed. It has to be a positive number [1-9], so I will not change the code here to allow invalid strings.
I suggest you prefix the modifier with a string identifier like dev/beta/build
0 is not allowed. It has to be a positive number [1-9], so I will not change the code here to allow invalid strings.
I agree that allowing invalid strings would be the wrong thing to do here. Would it be useful if AwesomeVersion could detect that this version is not valid and explicitly report why it's invalid, instead of a generic "Not a valid AwesomeVersion object"?
If you think that's useful, that's probably a patch I could work on.
It is a valid object. You just can't use it to compare with.
If you want it to raise during creation if its not a valid semver string you can already do that with:
from awesomeversion import AwesomeVersion, AwesomeVersionStrategy
AwesomeVersion("0.13.0-0858859", ensure_strategy=AwesomeVersionStrategy.SEMVER)
Or if you want to check if its comparable before comparing:
from awesomeversion import AwesomeVersion, AwesomeVersionStrategy
version = AwesomeVersion("0.13.0-0858859")
if version.strategy != AwesomeVersionStrategy.UNKNOWN:
version <= AwesomeVersion("0.8.4")