Skip to content

Commit

Permalink
add PEP 621 compatible [project] table to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Aug 21, 2024
1 parent 2eecf60 commit 34f8dcc
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 80 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
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,56 @@
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "aiobotocore"
description = "Async client for aws services using botocore and aiohttp"
requires-python = ">=3.8"
authors = [
{ name = "Nikolay Novik", email = "[email protected]" },
]
license = { text = "Apache License 2.0" }
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Environment :: Web Environment',
'Framework :: AsyncIO',
]

dynamic = ["version", "readme"]

dependencies = [
"botocore >=1.34.70, <1.34.163", # NOTE: When updating, always keep `project.optional-dependencies` aligned
"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"
PyPI = "https://pypi.org/project/aiobotocore/"
Documentation = "https://aiobotocore.readthedocs.io"

[tool.setuptools.dynamic]
version = { attr = "aiobotocore.__version__" }
readme = { file = ["README.rst", "CHANGES.rst"] }

[tool.pytest.ini_options]
asyncio_mode = "auto"
cache_dir = "/tmp/pytest_aiobotocore_cache"
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
67 changes: 1 addition & 66 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,3 @@
import os
import re

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'],
}


def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()


def read_version():
regexp = re.compile(r"^__version__\W*=\W*'([\d.abrc]+)'")
init_py = os.path.join(
os.path.dirname(__file__), 'aiobotocore', '__init__.py'
)
with open(init_py) as f:
for line in f:
match = regexp.match(line)
if match is not None:
return match.group(1)
raise RuntimeError('Cannot find version in aiobotocore/__init__.py')


setup(
name='aiobotocore',
version=read_version(),
description='Async client for aws services using botocore and aiohttp',
long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))),
long_description_content_type='text/x-rst',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Environment :: Web Environment',
'Framework :: AsyncIO',
],
author="Nikolay Novik",
author_email="[email protected]",
url='https://github.com/aio-libs/aiobotocore',
download_url='https://pypi.python.org/pypi/aiobotocore',
license='Apache License 2.0',
python_requires='>=3.8',
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 34f8dcc

Please sign in to comment.