Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace pkg_resources for python 3.12 #247

Open
branchvincent opened this issue Jul 27, 2024 · 1 comment
Open

replace pkg_resources for python 3.12 #247

branchvincent opened this issue Jul 27, 2024 · 1 comment

Comments

@branchvincent
Copy link

Python 3.12 has removed bundled setuptools (aka pkg_resources), but it's still used here:

iam_definition_path = pkg_resources.resource_filename(__name__, "iam_definition.json")
iam_definition = json.load(open(iam_definition_path, "r"))
# And the config data
config_path = pkg_resources.resource_filename(__name__, "config.yaml")

This means 3.12 users need to manually install setuptools to have a working install:

$ python3.12 -m venv .venv
$ .venv/bin/pip install parliament
$ .venv/bin/parliament --help
Traceback (most recent call last):
  File "/tmp/.venv/bin/parliament", line 5, in <module>
    from parliament.cli import main
  File "/tmp/.venv/lib/python3.12/site-packages/parliament/__init__.py", line 13, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

The recommended replacement is importlib.resources (introduced in python 3.7 and published to PyPI as importlib_resources for backporting). There's a detailed migration guide: https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename

@iainelder
Copy link
Contributor

@branchvincent , thanks for the warning.

Before we fix this, we need to solve some prerequisites:

  • Decide which Python versions Parliament should support now
  • Run tests across all supported Python versions

Decide which Python versions Parliament should support now

I propose Parliament now should support versions Python 3.8 through 3.12.

Python.org's Devlopers Guide says the oldest supported version is Python 3.8. It will be supported until 2024-10.

setup.py was last updated in 2020-08-13. Back then Python 3.6 was still supported, and Python 3.8 was the latest version.

So the app still claims support for Python 3.6:

python_requires=">=3.6",

And claims compatibility only up to Python 3.8:

parliament/setup.py

Lines 51 to 53 in 20784b7

"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",

Run tests across all supported Python versions

Parliament has a script to run unit tests, and according to the README it's up to the developer to run the script and choose the Python environment. It would be great to run the the tests automatically across all supported Python versions.

@branchvincent , we already worked together to solve a similar problem for Sceptre, dropping support for Python 3.7 and adding support for Python 3.12. That lead to a lot of improvements in Sceptre's test infrastructure that I think we can reuse here.

I propose we adapt the unit-tests and get-tox-envlist from Sceptre's check workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants