Skip to content

Commit

Permalink
Swap out legacycrypt for crypt-r for Python 3.13+
Browse files Browse the repository at this point in the history
PR Azure#3070 pulled in legacycrypt to replace the removed crypt module.
legacycrypt hasn't been updated since it was initially pulled out of
Python's stdlib in 2019 (Python 3.7). crypt-r pulls in the module as it
was in Python 3.12. While there's been no major developments since 3.7,
it's more likely to be kept updated for any breakages in future Python
releases.

It's also already packaged for Fedora and means one less package for me
to maintain so that would be nice.
  • Loading branch information
jeremycline committed Jun 12, 2024
1 parent d655c29 commit 1cf55dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
from pwd import getpwall

from azurelinuxagent.common.exception import OSUtilError
# 'crypt' was removed in Python 3.13; use legacycrypt instead
# 'crypt' was removed in Python 3.13; use crypt-r instead
if sys.version_info[0] == 3 and sys.version_info[1] >= 13 or sys.version_info[0] > 3:
try:
from legacycrypt import crypt
from crypt_r import crypt
except ImportError:
def crypt(password, salt):
raise OSUtilError("Please install the legacycrypt Python module to use this feature.")
raise OSUtilError("Please install the crypt-r Python module to use this feature.")
else:
from crypt import crypt # pylint: disable=deprecated-module

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
distro; python_version >= '3.8'
pyasn1
legacycrypt; python_version >= '3.13'
crypt-r; python_version >= '3.13'
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def run(self):
# module was deprecated. Depending on the Linux distribution the
# implementation may be broken prior to Python 3.8 where the functionality
# will be removed from Python 3.
# * In version 3.13 of Python, the crypt module was removed and legacycrypt is
# * In version 3.13 of Python, the crypt module was removed and crypt-r is
# required instead.
requires = [
"distro;python_version>='3.8'",
"legacycrypt;python_version>='3.13'",
"crypt-r;python_version>='3.13'",
]

modules = [] # pylint: disable=invalid-name
Expand Down

0 comments on commit 1cf55dd

Please sign in to comment.