Skip to content

Commit 57cf1d0

Browse files
Merge pull request #859 from valory-xyz/feat/remove-semver-dependency
chore: remove semver dependency
2 parents eb759c3 + bd9ec89 commit 57cf1d0

12 files changed

Lines changed: 84 additions & 40 deletions

File tree

aea/cli/generate_all_protocols.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from typing import Any, List, Tuple, cast
4444

4545
import click
46-
import semver
46+
from packaging.version import Version
4747

4848
from aea.cli.registry.utils import download_file, extract, request_api
4949
from aea.common import JSONLike
@@ -276,8 +276,8 @@ def _bump_protocol_specification_id(
276276
) -> None:
277277
"""Bump spec id version."""
278278
spec_id: PublicId = configuration.protocol_specification_id # type: ignore
279-
old_version = semver.VersionInfo.parse(spec_id.version)
280-
new_version = str(old_version.bump_minor())
279+
old_version = Version(spec_id.version)
280+
new_version = f"{old_version.major}.{old_version.minor + 1}.0"
281281
new_spec_id = PublicId(spec_id.author, spec_id.name, new_version)
282282
configuration.protocol_specification_id = new_spec_id
283283
with (package_path / DEFAULT_PROTOCOL_CONFIG_FILE).open("w") as file_output:

aea/configurations/data_types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
cast,
3939
)
4040

41-
import semver
4241
from packaging.specifiers import SpecifierSet
42+
from packaging.version import Version
4343

4444
from aea.configurations.constants import (
4545
AGENT,
@@ -62,7 +62,7 @@
6262
)
6363

6464
T = TypeVar("T")
65-
PackageVersionLike = Union[str, semver.VersionInfo]
65+
PackageVersionLike = Union[str, Version]
6666

6767
PACKAGE_NAME_RE = r"[a-zA-Z0-9_-]+"
6868
VERSION_SPECIFIER_RE = r"(>|<|=|~|\*)+.*"
@@ -117,13 +117,13 @@ def __init__(self, version_like: PackageVersionLike) -> None:
117117
"""
118118
Initialize a package version.
119119
120-
:param version_like: a string, os a semver.VersionInfo object.
120+
:param version_like: a string, or a packaging.version.Version object.
121121
"""
122122
if isinstance(version_like, str) and version_like in ("any", "latest"):
123123
self._version = version_like
124124
elif isinstance(version_like, str):
125-
self._version = semver.VersionInfo.parse(version_like)
126-
elif isinstance(version_like, semver.VersionInfo):
125+
self._version = Version(version_like)
126+
elif isinstance(version_like, Version):
127127
self._version = version_like
128128
else:
129129
raise ValueError("Version type not valid.")

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/api/configurations/data_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Initialize a package version.
6161

6262
**Arguments**:
6363

64-
- `version_like`: a string, os a semver.VersionInfo object.
64+
- `version_like`: a string, or a packaging.version.Version object.
6565

6666
<a id="aea.configurations.data_types.PackageVersion.is_any"></a>
6767

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

scripts/update_package_versions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
from typing import Any, Dict, List, Optional, Pattern, Set
3939

4040
import click
41-
import semver
4241
import yaml
4342
from click.testing import CliRunner
43+
from packaging.version import Version
4444

4545
from aea.cli import cli
4646
from aea.cli.ipfs_hash import update_hashes
@@ -397,7 +397,7 @@ def _sort_in_update_order(package_ids: Set[PackageId]) -> List[PackageId]:
397397
return sorted(
398398
package_ids,
399399
key=lambda x: (
400-
semver.VersionInfo.parse(x.public_id.version),
400+
Version(x.public_id.version),
401401
x.public_id.author,
402402
x.public_id.name,
403403
x.package_type.value,
@@ -410,8 +410,9 @@ def minor_version_difference(
410410
current_public_id: PublicId, deployed_public_id: PublicId
411411
) -> int:
412412
"""Check the minor version difference."""
413-
diff = semver.compare(current_public_id.version, deployed_public_id.version)
414-
return diff
413+
current = Version(current_public_id.version)
414+
deployed = Version(deployed_public_id.version)
415+
return (current > deployed) - (current < deployed)
415416

416417

417418
def _can_disambiguate_from_context(
@@ -705,7 +706,7 @@ def process_package(self, package_id: PackageId, is_ambiguous: bool) -> None:
705706
def get_new_package_version(self, current_public_id: PublicId) -> str:
706707
"""Get new package version according to command line options provided."""
707708

708-
ver = semver.VersionInfo.parse(current_public_id.version)
709+
ver = Version(current_public_id.version)
709710

710711
if self.option_ask_version:
711712
while True:
@@ -714,7 +715,7 @@ def get_new_package_version(self, current_public_id: PublicId) -> str:
714715
)
715716

716717
try:
717-
new_ver = semver.VersionInfo.parse(new_version)
718+
new_ver = Version(new_version)
718719
if new_ver <= ver:
719720
print("Version is lower or the same. Enter a new one.")
720721
continue
@@ -723,9 +724,9 @@ def get_new_package_version(self, current_public_id: PublicId) -> str:
723724
print(f"Version parse error: {e}. Enter a new one")
724725
continue
725726
elif self.option_update_version == "minor":
726-
new_version = ver.bump_minor()
727+
new_version = f"{ver.major}.{ver.minor + 1}.0"
727728
elif self.option_update_version == "patch":
728-
new_version = ver.bump_patch()
729+
new_version = f"{ver.major}.{ver.minor}.{ver.micro + 1}"
729730
else:
730731
raise RuntimeError("unknown version update mode")
731732

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ ignore_errors = True
7979
[mypy-oef.*]
8080
ignore_missing_imports = True
8181

82-
[mypy-semver.*]
83-
ignore_missing_imports = True
84-
8582
[mypy-eth_keys.*]
8683
ignore_missing_imports = True
8784

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def get_all_extras() -> Dict:
3737
"pytest>=8.2,<10",
3838
"coverage>=6.4.4,<8.0.0",
3939
"jsonschema<4.24.0,>=4.20.0",
40-
"semver>=2.9.1,<3.0.0",
4140
]
4241

4342
extras = {
@@ -53,7 +52,6 @@ def get_all_extras() -> Dict:
5352
all_extras = get_all_extras()
5453

5554
base_deps = [
56-
"semver>=2.9.1,<3.0.0",
5755
"base58>=1.0.3,<3.0.0",
5856
"jsonschema<4.24.0,>=4.20.0",
5957
"packaging==26",

tests/strategies/data_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import collections
2323
import re
2424

25-
import semver
2625
from hypothesis import strategies as st
2726
from packaging.specifiers import Specifier, SpecifierSet
27+
from packaging.version import Version
2828

2929
from aea.configurations.data_types import (
3030
ComponentId,
@@ -58,7 +58,7 @@
5858

5959

6060
version_info_strategy = st.builds(
61-
lambda kwargs: semver.VersionInfo(**kwargs),
61+
lambda kwargs: Version(f"{kwargs['major']}.{kwargs['minor']}.{kwargs['patch']}"),
6262
st.fixed_dictionaries(
6363
dict(
6464
major=positive_integer_strategy,
@@ -67,7 +67,7 @@
6767
),
6868
),
6969
)
70-
st.register_type_strategy(semver.VersionInfo, version_info_strategy)
70+
st.register_type_strategy(Version, version_info_strategy)
7171

7272

7373
package_version_strategy = st.builds(
@@ -81,7 +81,7 @@
8181
dict(
8282
author=st.from_type(SimpleId),
8383
name=st.from_type(SimpleId),
84-
version=st.from_type(semver.VersionInfo),
84+
version=st.from_type(Version),
8585
package_hash=st.from_type(IPFSHash),
8686
)
8787
)

tests/test_configurations/test_base.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from unittest.mock import Mock
3232

3333
import pytest
34-
import semver
3534
import yaml
3635
from packaging.specifiers import SpecifierSet
3736

@@ -609,8 +608,10 @@ def test_configuration_ordered_json():
609608

610609
def test_public_id_versions():
611610
"""Test that a public id version can be initialized with different objects."""
611+
from packaging.version import Version
612+
612613
PublicId("author", "name", "0.1.0")
613-
PublicId("author", "name", semver.VersionInfo(major=0, minor=1, patch=0))
614+
PublicId("author", "name", Version("0.1.0"))
614615

615616

616617
def test_public_id_invalid_version():
@@ -1010,6 +1011,54 @@ def test_package_version_lt():
10101011
assert v1 < v2 < v3
10111012

10121013

1014+
def test_package_version_from_version_object():
1015+
"""Test PackageVersion accepts packaging.version.Version objects."""
1016+
from packaging.version import Version
1017+
1018+
v = Version("1.2.3")
1019+
pv = PackageVersion(v)
1020+
assert str(pv) == "1.2.3"
1021+
1022+
# Comparison with string-constructed version
1023+
pv_str = PackageVersion("1.2.3")
1024+
assert pv == pv_str
1025+
1026+
# Ordering
1027+
pv_lower = PackageVersion(Version("1.1.0"))
1028+
pv_higher = PackageVersion(Version("2.0.0"))
1029+
assert pv_lower < pv < pv_higher
1030+
1031+
# str round-trip
1032+
assert PackageVersion(str(pv)) == pv
1033+
1034+
1035+
def test_package_version_str_format():
1036+
"""Test PackageVersion string representation matches semver format."""
1037+
cases = ["0.1.0", "1.0.0", "1.2.3", "10.20.30"]
1038+
for version_str in cases:
1039+
pv = PackageVersion(version_str)
1040+
assert str(pv) == version_str
1041+
1042+
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+
1047+
exotic = ["1.0.0-0.3.7", "1.0.0-x.7.z.92"]
1048+
for version_str in exotic:
1049+
with pytest.raises(InvalidVersion):
1050+
PackageVersion(version_str)
1051+
1052+
1053+
def test_public_id_with_version_object():
1054+
"""Test PublicId can be initialized with a packaging.version.Version."""
1055+
from packaging.version import Version
1056+
1057+
pid = PublicId("author", "name", Version("0.1.0"))
1058+
assert str(pid.package_version) == "0.1.0"
1059+
assert pid == PublicId("author", "name", "0.1.0")
1060+
1061+
10131062
class TestDependencyGetPipInstallArgs:
10141063
"""Test 'get_pip_install_args' of 'Dependency' class."""
10151064

0 commit comments

Comments
 (0)