Skip to content

Commit

Permalink
Use distutils from Python standard library
Browse files Browse the repository at this point in the history
setuptools 60.0 switched from standard library distutils to its own
local distutils by default [1]. setuptools' own distutils version
doesn't support building with 2to3 translation anymore [2].

However, the current pycryptodomex version (3.6) relies on distutils
2to3 translation support for correct Python 3 builds. Building with the
setuptools distutils version results in run-time errors such as

  . . .
    File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/cms-1.5.dev0-py3.8.egg/cmscommon/crypto.py", line 31, in <module>
      from Cryptodome.Cipher import AES
    File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/Cryptodome/Cipher/__init__.py", line 31, in <module>
      from Cryptodome.Cipher._mode_ctr import _create_ctr_cipher
    File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/Cryptodome/Cipher/_mode_ctr.py", line 37, in <module>
      from Cryptodome.Util.number import long_to_bytes
    File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/Cryptodome/Util/number.py", line 399
      s = pack('>I', n & 0xffffffffL) + s
                                   ^
  SyntaxError: invalid syntax

We set the SETUPTOOLS_USE_DISTUTILS environment variable to continue
using the system distutils version with 2to3 translation support for
now. The variable can be removed later when we update to a newer
pycryptodomex version.

In the documentation, we also pass the environment variable to the
"setup.py install" command for consistency.

[1] pypa/setuptools@f7a55da
[2] pypa/setuptools@d989cdb
  • Loading branch information
andreyv committed Dec 20, 2021
1 parent 5a1a1f3 commit 1621394
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Install requirements
run: |
# Use distutils from the standard library for 2to3 translation
export SETUPTOOLS_USE_DISTUTILS="stdlib"
pip install -U pip setuptools wheel
pip install -r requirements.txt
pip install -r dev-requirements.txt
Expand Down
7 changes: 5 additions & 2 deletions docs/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ Assuming you have ``pip`` installed, you can do this:

.. sourcecode:: bash

sudo pip3 install -r requirements.txt
sudo python3 setup.py install
export SETUPTOOLS_USE_DISTUTILS="stdlib"
sudo --preserve-env=SETUPTOOLS_USE_DISTUTILS pip3 install -r requirements.txt
sudo --preserve-env=SETUPTOOLS_USE_DISTUTILS python3 setup.py install

This command installs python dependencies globally. Note that on some distros, like Arch Linux, this might interfere with the system package manager. If you want to perform the installation in your home folder instead, then you can do this instead:

.. sourcecode:: bash

export SETUPTOOLS_USE_DISTUTILS="stdlib"
pip3 install --user -r requirements.txt
python3 setup.py install --user

Expand All @@ -176,6 +178,7 @@ After the activation, the ``pip`` command will *always* be available (even if it

.. sourcecode:: bash

export SETUPTOOLS_USE_DISTUTILS="stdlib"
pip3 install -r requirements.txt
python3 setup.py install

Expand Down

0 comments on commit 1621394

Please sign in to comment.