Skip to content

Commit bd9ec89

Browse files
DavidMinarschclaude
andcommitted
fix: strict PEP 440 version parsing, update docs and schema description
Address review feedback: remove InvalidVersion fallback that created mixed str/Version types causing TypeError in comparisons. Instead, non-PEP 440 versions (e.g. 1.0.0-0.3.7) are rejected explicitly. - Revert fallback in PackageVersion.__init__ to strict Version() parsing - Add test verifying non-PEP 440 forms are rejected - Update schema description from semver reference to PEP 440 - Update docs/config.md and test docs to reference PEP 440 - Update API docs from semver.VersionInfo to packaging.version.Version Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ad39dae commit bd9ec89

5 files changed

Lines changed: 19 additions & 24 deletions

File tree

aea/configurations/data_types.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040

4141
from packaging.specifiers import SpecifierSet
42-
from packaging.version import InvalidVersion, Version
42+
from packaging.version import Version
4343

4444
from aea.configurations.constants import (
4545
AGENT,
@@ -122,13 +122,7 @@ def __init__(self, version_like: PackageVersionLike) -> None:
122122
if isinstance(version_like, str) and version_like in ("any", "latest"):
123123
self._version = version_like
124124
elif isinstance(version_like, str):
125-
try:
126-
self._version = Version(version_like)
127-
except InvalidVersion:
128-
# Semver prerelease forms (e.g. 1.0.0-0.3.7) are not PEP 440
129-
# but are allowed by the schema regex. Store as raw string so
130-
# config loading does not crash.
131-
self._version = version_like
125+
self._version = Version(version_like)
132126
elif isinstance(version_like, Version):
133127
self._version = version_like
134128
else:

aea/configurations/schemas/definitions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"semantic_version": {
7676
"type": "string",
77-
"description": "A semantic version number. See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string",
77+
"description": "A version string. Supports PEP 440 versions (MAJOR.MINOR.PATCH with optional pre-release suffixes like rc1, a1, b1).",
7878
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
7979
},
8080
"pep440_version": {

docs/config.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The `aea-config.yaml` defines the AEA project. The compulsory components are lis
1414
``` yaml
1515
agent_name: my_agent # Name of the AEA project (must satisfy PACKAGE_REGEX)
1616
author: fetchai # Author handle of the project's author (must satisfy AUTHOR_REGEX)
17-
version: 0.1.0 # Version of the AEA project (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
17+
version: 0.1.0 # Version of the AEA project (a version in MAJOR.MINOR.PATCH format, see PEP 440)
1818
description: A demo project # Description of the AEA project
1919
license: Apache-2.0 # License of the AEA project
2020
aea_version: '>=2.0.0, <3.0.0' # AEA framework version(s) compatible with the AEA project (a version number that matches PEP 440 version schemes, or a comma-separated list of PEP 440 version specifiers, see https://www.python.org/dev/peps/pep-0440/#version-specifiers)
@@ -91,7 +91,7 @@ The `connection.yaml`, which is present in each connection package, has the foll
9191
``` yaml
9292
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
9393
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
94-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
94+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
9595
type: connection # The type of the package; for connections, it must be "connection"
9696
description: A scaffold connection # Description of the package
9797
license: Apache-2.0 # License of the package
@@ -117,7 +117,7 @@ The `contract.yaml`, which is present in each contract package, has the followin
117117
``` yaml
118118
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
119119
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
120-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
120+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
121121
type: contract # The type of the package; for contracts, it must be "contract"
122122
description: A scaffold contract # Description of the package
123123
license: Apache-2.0 # License of the package
@@ -139,7 +139,7 @@ The `protocol.yaml`, which is present in each protocol package, has the followin
139139
``` yaml
140140
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
141141
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
142-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
142+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
143143
type: protocol # The type of the package; for protocols, it must be "protocol"
144144
description: A scaffold protocol # Description of the package
145145
license: Apache-2.0 # License of the package
@@ -158,7 +158,7 @@ The `skill.yaml`, which is present in each protocol package, has the following r
158158
``` yaml
159159
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
160160
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
161-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
161+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
162162
type: skill # The type of the package; for skills, it must be "skill"
163163
description: A scaffold skill # Description of the package
164164
license: Apache-2.0 # License of the package

tests/test_configurations/test_base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,14 @@ def test_package_version_str_format():
10401040
assert str(pv) == version_str
10411041

10421042

1043-
def test_package_version_semver_prerelease_fallback():
1044-
"""Test that semver prerelease forms that aren't PEP 440 don't crash."""
1043+
def test_package_version_rejects_non_pep440():
1044+
"""Test that non-PEP 440 semver prerelease forms are rejected explicitly."""
1045+
from packaging.version import InvalidVersion
1046+
10451047
exotic = ["1.0.0-0.3.7", "1.0.0-x.7.z.92"]
10461048
for version_str in exotic:
1047-
pv = PackageVersion(version_str)
1048-
assert str(pv) == version_str
1049-
assert pv == PackageVersion(version_str)
1049+
with pytest.raises(InvalidVersion):
1050+
PackageVersion(version_str)
10501051

10511052

10521053
def test_public_id_with_version_object():

tests/test_docs/test_bash_yaml/md_files/bash-config.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LEDGER_ID_REGEX: "^[^\\d\\W]\\w*\\Z"
77
``` yaml
88
agent_name: my_agent # Name of the AEA project (must satisfy PACKAGE_REGEX)
99
author: fetchai # Author handle of the project's author (must satisfy AUTHOR_REGEX)
10-
version: 0.1.0 # Version of the AEA project (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
10+
version: 0.1.0 # Version of the AEA project (a version in MAJOR.MINOR.PATCH format, see PEP 440)
1111
description: A demo project # Description of the AEA project
1212
license: Apache-2.0 # License of the AEA project
1313
aea_version: '>=2.0.0, <3.0.0' # AEA framework version(s) compatible with the AEA project (a version number that matches PEP 440 version schemes, or a comma-separated list of PEP 440 version specifiers, see https://www.python.org/dev/peps/pep-0440/#version-specifiers)
@@ -71,7 +71,7 @@ models: # override configurations for mo
7171
``` yaml
7272
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
7373
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
74-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
74+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
7575
type: connection # The type of the package; for connections, it must be "connection"
7676
description: A scaffold connection # Description of the package
7777
license: Apache-2.0 # License of the package
@@ -93,7 +93,7 @@ is_abstract: false # An optional boolean that if `t
9393
``` yaml
9494
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
9595
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
96-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
96+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
9797
type: contract # The type of the package; for contracts, it must be "contract"
9898
description: A scaffold contract # Description of the package
9999
license: Apache-2.0 # License of the package
@@ -111,7 +111,7 @@ dependencies: {} # The python dependencies the pa
111111
``` yaml
112112
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
113113
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
114-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
114+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
115115
type: protocol # The type of the package; for protocols, it must be "protocol"
116116
description: A scaffold protocol # Description of the package
117117
license: Apache-2.0 # License of the package
@@ -126,7 +126,7 @@ dependencies: {} # The python dependencies the pa
126126
``` yaml
127127
name: scaffold # Name of the package (must satisfy PACKAGE_REGEX)
128128
author: fetchai # Author handle of the package's author (must satisfy AUTHOR_REGEX)
129-
version: 0.1.0 # Version of the package (a semantic version number, see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string")
129+
version: 0.1.0 # Version of the package (a version in MAJOR.MINOR.PATCH format, see PEP 440)
130130
type: skill # The type of the package; for skills, it must be "skill"
131131
description: A scaffold skill # Description of the package
132132
license: Apache-2.0 # License of the package

0 commit comments

Comments
 (0)