Skip to content

Use looseversion instead of deprecated distutils #1391

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

Merged
merged 6 commits into from
Apr 22, 2025

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Apr 22, 2025

This PR addresses the following warning observed when running the make_release.py script:

etc/make_release.py:42: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.version import LooseVersion

This is a followup to #1280 and #1244, which applied a <3.12 Python version restriction to workaround the aforementioned removal of the distutils package. This PR proposes using the looseversion package instead to obtain LooseVersion. This package was already added to the list of make_release.py dependencies in #1244 but was left unused (possibly overlooked?).

This permits the removal of the Python 3.12 version restriction, which in turn revealed the following warning:

etc/make_release.py:593: SyntaxWarning: invalid escape sequence '\w'
  token_re = re.compile('^(?:Token - )?(?P<tok>\w{40}).*$')

This is apparently due to 3.12 promoting unrecognized escape sequences to a SyntaxWarning (and eventually a SyntaxError). I believe a simple addition of an escape \ -> \\ is sufficient in this case.

These changes (should) allow for compatibility with Python 3.10 through Python 3.13. ("Should" as the full script is not yet tested without --dry-run.)

@eramongodb eramongodb requested a review from kevinAlbs April 22, 2025 15:29
@eramongodb eramongodb self-assigned this Apr 22, 2025
@eramongodb eramongodb requested a review from a team as a code owner April 22, 2025 15:29
@@ -621,7 +621,7 @@ def read_github_creds(github_token_file):
Read the GitHub token from the specified file and return it as a string.
"""

token_re = re.compile('^(?:Token - )?(?P<tok>\w{40}).*$')
token_re = re.compile('^(?:Token - )?(?P<tok>\\w{40}).*$')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
token_re = re.compile('^(?:Token - )?(?P<tok>\\w{40}).*$')
token_re = re.compile(r'^(?:Token - )?(?P<tok>\w{40}).*$')

Consider using a raw string to treat the backslash as a literal character. Raw strings appear frequently in https://docs.python.org/3/library/re.html.

@eramongodb eramongodb merged commit 5c47a41 into mongodb:master Apr 22, 2025
1 check was pending
@eramongodb eramongodb deleted the cxx-make_release branch April 22, 2025 20:20
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.

2 participants