Skip to content

Commit

Permalink
move dependencies and optional-dependencies into pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Aug 20, 2024
1 parent 4d48284 commit d9f2725
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ botocore calls eventually called.

The best way I've seen to upgrade botocore support is by performing the following:

1. Download sources of the release of botocore you're trying to upgrade to, and the version of botocore that aiobotocore is currently locked to (see setup.py) and do a folder based file comparison of the botocore folders (tools like DiffMerge are nice).
1. Download sources of the release of botocore you're trying to upgrade to, and the version of botocore that aiobotocore is currently locked to (see pyproject.toml) and do a folder based file comparison of the botocore folders (tools like DiffMerge are nice).
2. Manually apply the relevant changes to their aiobotocore equivalent(s). Note that sometimes new functions are added which will need to be overridden (like `__enter__` -> `__aenter__`)
3. Update the "extras" in setup.py to the versions which match the botocore version you are targeting.
3. Update the "project.optional-dependencies" in pyproject.toml to the versions which match the botocore version you are targeting.
4. Now do a directory diff between aiobotocore and your target version botocore directory to ensure the changes were propagated.

See next section describing types of changes we must validate and support.
Expand Down
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@ classifiers = [
'Framework :: AsyncIO',
]

dynamic = ["dependencies", "optional-dependencies"]
dependencies = [
# NOTE: When updating botocore, always keep `project.optional-dependencies` aligned
"botocore>=1.34.70,<1.34.163",
"aiohttp>=3.9.2,<4.0.0",
"wrapt>=1.10.10, <2.0.0",
"aioitertools>=0.5.1,<1.0.0",
]

[project.optional-dependencies]
awscli = [
"awscli>=1.32.70,<1.33.45",
]
boto3 = [
"boto3>=1.34.70,<1.34.163",
]

[project.urls]
Repository = "https://github.com/aio-libs/aiobotocore"
Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ setuptools==67.8.0;python_version>="3.12"
# this is needed for test_patches
dill~=0.3.3

# this is needed for test_version
tomli;python_version<"3.11"

# this is needed when running setup.py check -rms
Pygments

Expand Down
21 changes: 1 addition & 20 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
from setuptools import setup

# NOTE: If updating requirements make sure to also check Pipfile for any locks
# NOTE: When updating botocore make sure to update awscli/boto3 versions below
install_requires = [
# pegged to also match items in `extras_require`
'botocore>=1.34.70,<1.34.163',
'aiohttp>=3.9.2,<4.0.0',
'wrapt>=1.10.10, <2.0.0',
'aioitertools>=0.5.1,<1.0.0',
]

extras_require = {
'awscli': ['awscli>=1.32.70,<1.33.45'],
'boto3': ['boto3>=1.34.70,<1.34.163'],
}


setup(
install_requires=install_requires,
extras_require=extras_require,
)
setup()
2 changes: 1 addition & 1 deletion tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
# REPLACE = backwards incompatible change
# APPEND = officially supporting more versions of botocore/aiohttp

# If you're changing these, most likely need to update setup.py as well.
# If you're changing these, most likely need to update dependencies in pyproject.toml as well.
_API_DIGESTS = {
# args.py
ClientArgsCreator.get_client_args: {
Expand Down
48 changes: 37 additions & 11 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ast
import operator
import re
import sys
from datetime import datetime
from itertools import chain
from pathlib import Path
Expand All @@ -19,6 +20,11 @@

import aiobotocore

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

Check warning on line 26 in tests/test_version.py

View check run for this annotation

Codecov / codecov/patch

tests/test_version.py#L26

Added line #L26 was not covered by tests

_root_path = Path(__file__).absolute().parent.parent


Expand Down Expand Up @@ -52,9 +58,7 @@ class VersionInfo(NamedTuple):
specifier_set: SpecifierSet


def _get_boto_module_versions(
setup_content: str, ensure_plus_one_patch_range: bool = False
):
def _get_requirements_from_setup_py(setup_content: str):
parsed = ast.parse(setup_content)
top_level_vars = {"install_requires", "requires", "extras_require"}
assignments = dict()
Expand All @@ -67,13 +71,28 @@ def _get_boto_module_versions(
value = ast.literal_eval(node.value)
assignments[target_name] = value

module_versions = dict()

for ver in chain(
return chain(
assignments.get("install_requires", []),
assignments.get("requires", []),
assignments.get("extras_require", {}).values(),
):
)


def _get_requirements_from_pyproject_toml(pyproject_content: str):
content = tomllib.loads(pyproject_content)

return chain(
content["project"].get("dependencies", []),
*content["project"].get("optional-dependencies", {}).values(),
)


def _get_boto_module_versions(
requirements, ensure_plus_one_patch_range: bool = False
):
module_versions = dict()

for ver in requirements:
if isinstance(ver, str):
ver: InstallRequirement = install_req_from_line(ver)
elif isinstance(ver, list):
Expand Down Expand Up @@ -165,16 +184,21 @@ def test_release_versions():
), 'Current release must be after last release'

# get aioboto reqs
with (_root_path / 'setup.py').open() as f:
with (_root_path / 'pyproject.toml').open() as f:
content = f.read()
aioboto_reqs = _get_boto_module_versions(content, False)
aioboto_reqs = _get_boto_module_versions(
_get_requirements_from_pyproject_toml(content),
False,
)

# get awscli reqs
awscli_resp = requests.get(
f"https://raw.githubusercontent.com/aws/aws-cli/"
f"{aioboto_reqs['awscli'].least_version}/setup.py"
)
awscli_reqs = _get_boto_module_versions(awscli_resp.text)
awscli_reqs = _get_boto_module_versions(
_get_requirements_from_setup_py(awscli_resp.text)
)
assert awscli_reqs['botocore'].specifier_set.contains(
aioboto_reqs['botocore'].least_version
)
Expand All @@ -184,7 +208,9 @@ def test_release_versions():
f"https://raw.githubusercontent.com/boto/boto3/"
f"{aioboto_reqs['boto3'].least_version}/setup.py"
)
boto3_reqs = _get_boto_module_versions(boto3_resp.text)
boto3_reqs = _get_boto_module_versions(
_get_requirements_from_setup_py(boto3_resp.text)
)
assert boto3_reqs['botocore'].specifier_set.contains(
aioboto_reqs['botocore'].least_version
)
Expand Down

0 comments on commit d9f2725

Please sign in to comment.