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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.11 and test 3.12-dev #545

Merged
merged 12 commits into from Jun 16, 2023

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Nov 15, 2022

Problem

Python 3.11 was released on 2022-10-24 馃殌

image

We should test it and declare support via the Trove classifier.

Solution

Add to tox.ini for local and CI testing, add to GitHub Actions for CI, and add the Trove classifier to declare support.

Also bump GitHub Actions and add colour to CI logs for readability.

Commandments

  • Write PEP8 compliant code.
  • Cover it with tests.
  • Update CHANGES.rst file to describe the changes, and quote according issue with GH-<issue_number>.
  • Pay attention to backward compatibility, or if it breaks it, explain why.
  • Update documentation (if relevant).

@codecov
Copy link

codecov bot commented Nov 15, 2022

Codecov Report

Merging #545 (cb292c2) into master (3dc511c) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #545   +/-   ##
=======================================
  Coverage   95.12%   95.12%           
=======================================
  Files           6        6           
  Lines         820      820           
=======================================
  Hits          780      780           
  Misses         40       40           
Impacted Files Coverage 螖
model_utils/__init__.py 100.00% <100.00%> (酶)

馃摚 We鈥檙e building smart automated test selection to slash your CI/CD build times. Learn more

@foarsitter
Copy link
Contributor

Is 3.12-dev allowed to fail? Otherwise it looks good to me.

Needless to say it would be easier that the PR only adds the changes the title says.

@hugovk hugovk changed the title Add support for Python 3.11 Add support for Python 3.11 and test 3.12-dev Apr 6, 2023
@hugovk
Copy link
Member Author

hugovk commented Apr 6, 2023

Is 3.12-dev allowed to fail? Otherwise it looks good to me.

No, it can also fail the build. I think that's fine: 3.12 is almost in beta and should be pretty stable.

  • If there's a failure, it's good to know about it sooner rather than later, so we can fix it here and be ready for the 3.12 release, and also not to block people who depend on django-model-util for their own prep.

  • If it's not a quick fix, it's easy to temporarily skip 3.12-dev in the build.

  • If it's a problem in CPython itself, even better, we can report upstream and get it fixed for everyone before the full release!

Needless to say it would be easier that the PR only adds the changes the title says.

I've changed the title to also say we're testing 3.12-dev here, or can also split it out to another PR if you prefer.

@foarsitter
Copy link
Contributor

What you describe in point three is a good one.

Copy link
Contributor

@foarsitter foarsitter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk forgot about this PR but found it again wondering why there was no 3.11 in the matrix. Resolved the conflict and I think we should merge It even 3.12 is failing. Agree?

@hugovk
Copy link
Member Author

hugovk commented Jun 15, 2023

Aha! Good to see a 3.12 failure, it's a valid failure showing there's something to fix in django-model-util (this is bullet point 1 above :)

    File "/home/runner/work/django-model-utils/django-model-utils/model_utils/__init__.py", line 1, in <module>
      from pkg_resources import DistributionNotFound, get_distribution
  ModuleNotFoundError: No module named 'pkg_resources'

https://docs.python.org/3.12/whatsnew/3.12.html#removed says:

easy_install, pkg_resources, setuptools and distutils are no longer provided by default in environments created with venv or bootstrapped with ensurepip, since they are part of the setuptools package. For projects relying on these at runtime, the setuptools project should be declared as a dependency and installed separately (typically, using pip).

I've pushed a commit to also install setuptools when we're on 3.12 or higher.


Alternatively, we're using pkg_resources to get the distribution version. Instead we can use importlib.metadata from the stdlib from 3.8+ (and a backport for 3.7), like this:

try:
    # Python 3.8+
    import importlib.metadata as importlib_metadata
except ImportError:
    # Python 3.7 and lower
    import importlib_metadata
import importlib.metadata

__version__ = importlib.metadata.version(__name__)

Or, we're in luck, Python 3.7 is end-of-life this month (https://devguide.python.org/versions/) so we could drop that backport and simplify it to:

import importlib.metadata
__version__ = importlib.metadata.version(__name__)

That would be my recommendation. What do you think?

@foarsitter
Copy link
Contributor

Thanks for providing an extensive explanation about the issue, couldn't find an easy solution myself.

Using importlib is a more future proof approach I suppose so has my preferences.

Do you want to update the pull-request or merge this and use importlib when 3.7 is EOL?

@hugovk
Copy link
Member Author

hugovk commented Jun 15, 2023

I'll update this PR. Do you want to wait until the official EOL (2023-06-27) or are we close enough already? Many projects have already started dropping it.

@foarsitter
Copy link
Contributor

We are close enough if you ask me. 3.7 users won't miss any new features or something so can stick to 4.3.1.

setup.py Show resolved Hide resolved
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing 3.7 here and we can merge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

@hugovk
Copy link
Member Author

hugovk commented Jun 15, 2023

I need to upgrade Read the Docs to use a new Python version than 3.7. Coming up!

@hugovk
Copy link
Member Author

hugovk commented Jun 15, 2023

Ready!

CHANGES.rst Outdated Show resolved Hide resolved
@foarsitter
Copy link
Contributor

Since this PR contains a lot of different changes squashing doesn't seem right, thoughts?

@hugovk
Copy link
Member Author

hugovk commented Jun 15, 2023

Either way is fine for me, I usually don't worry too much it :)

@foarsitter
Copy link
Contributor

That suits me well, reading git history still isn't something I do for leisure.

Thanks for your contribution!

@blag
Copy link

blag commented Nov 1, 2023

Can we get a release with this change? The current available version, 4.3.1, has an issue on the latest Pythons.

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

Successfully merging this pull request may close these issues.

None yet

3 participants