pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.45k stars 1.18k forks source link

[BUG] 71.0.4 and 71.1.0 fail with `ImportError: cannot import name 'tarfile' from 'backports'` #4509

Closed cacti77 closed 1 month ago

cacti77 commented 1 month ago

setuptools version

71.0.4, 71.1.0

Python version

3.10.10

OS

ubuntu 22.04.4 LTS

Additional environment information

Azure DevOps with the 'ubuntu-latest' VM image hosting the Docker image jupyter/pyspark-notebook:spark-3.3.2 from here. This Docker container uses Python 3.10.10.

Description

I tried to create a source distribution of my Python package using python setup.py sdist with setuptools 71.0.4 or 71.1.0 and get this error:

ImportError: cannot import name 'tarfile' from 'backports' (/opt/conda/lib/python3.10/site-packages/backports/__init__.py)

The source distribution was created successfully, however, with setuptools 70.3.0.

I created this issue after feedback from my comment at https://github.com/pypa/setuptools/issues/4476#issuecomment-2242929228

Expected behavior

The source distribution should be created without error.

How to Reproduce

After installing our requirements with pip, and then upgrading pip and setuptools with:

python -m pip install --upgrade pip setuptools

then:

python -m pip list

shows:

Package                       Version
----------------------------- -----------
aiofiles                      22.1.0
aiosqlite                     0.18.0
alembic                       1.10.3
altair                        4.2.2
anyio                         3.6.2
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
asttokens                     2.2.1
async-generator               1.10
attrs                         22.2.0
Babel                         2.12.1
backcall                      0.2.0
backports.functools-lru-cache 1.6.4
beautifulsoup4                4.12.2
bleach                        6.0.0
blinker                       1.6.1
bokeh                         2.4.3
boltons                       23.0.0
Bottleneck                    1.3.7
brotlipy                      0.7.0
cached-property               1.5.2
certifi                       2022.12.7
certipy                       0.1.3
cffi                          1.15.1
charset-normalizer            3.1.0
click                         8.1.3
cloudpickle                   2.2.1
colorama                      0.4.6
comm                          0.1.3
conda                         23.3.1
conda-package-handling        2.0.2
conda_package_streaming       0.7.0
contourpy                     1.0.7
cryptography                  40.0.1
cycler                        0.11.0
Cython                        0.29.34
cytoolz                       0.12.0
dask                          2023.3.2
debugpy                       1.6.7
decorator                     5.1.1
defusedxml                    0.7.1
dill                          0.3.6
distributed                   2023.3.2.1
entrypoints                   0.4
et-xmlfile                    1.1.0
executing                     1.2.0
fastjsonschema                2.16.3
flit_core                     3.8.0
fonttools                     4.39.3
fsspec                        2023.4.0
gmpy2                         2.1.2
greenlet                      2.0.2
h5py                          3.8.0
HeapDict                      1.0.1
idna                          3.4
imagecodecs                   2023.1.23
imageio                       2.27.0
importlib-metadata            6.2.1
importlib-resources           5.12.0
ipykernel                     6.22.0
ipympl                        0.9.3
ipython                       8.12.0
ipython-genutils              0.2.0
ipywidgets                    8.0.6
jedi                          0.18.2
Jinja2                        3.1.2
joblib                        1.2.0
json5                         0.9.5
jsonpatch                     1.32
jsonpointer                   2.0
jsonschema                    4.17.3
jupyter_client                8.1.0
jupyter_core                  5.3.0
jupyter-events                0.6.3
jupyter_server                2.5.0
jupyter_server_fileid         0.9.0
jupyter_server_terminals      0.4.4
jupyter_server_ydoc           0.8.0
jupyter-telemetry             0.1.0
jupyter-ydoc                  0.2.3
jupyterhub                    3.1.1
jupyterlab                    3.6.3
jupyterlab-pygments           0.2.2
jupyterlab_server             2.22.0
jupyterlab-widgets            3.0.7
kiwisolver                    1.4.4
lazy_loader                   0.2
libmambapy                    1.4.2
llvmlite                      0.39.1
locket                        1.0.0
lxml                          5.2.2
lz4                           4.3.2
Mako                          1.2.4
mamba                         1.4.2
MarkupSafe                    2.1.2
matplotlib                    3.7.1
matplotlib-inline             0.1.6
mistune                       2.0.5
mpmath                        1.3.0
msgpack                       1.0.5
munkres                       1.1.4
nbclassic                     0.5.5
nbclient                      0.7.3
nbconvert                     7.3.0
nbformat                      5.8.0
nest-asyncio                  1.5.6
networkx                      3.1
notebook                      6.5.4
notebook_shim                 0.2.2
numba                         0.56.4
numexpr                       2.8.4
numpy                         1.23.5
oauthlib                      3.2.2
openpyxl                      3.1.1
packaging                     23.0
pamela                        1.0.0
pandas                        2.0.0
pandocfilters                 1.5.0
parso                         0.8.3
partd                         1.3.0
patsy                         0.5.3
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        9.5.0
pip                           24.1.2
pkgutil_resolve_name          1.3.10
platformdirs                  3.2.0
pluggy                        1.0.0
pooch                         1.7.0
prometheus-client             0.16.0
prompt-toolkit                3.0.38
protobuf                      4.21.12
psutil                        5.9.4
ptyprocess                    0.7.0
pure-eval                     0.2.2
py-cpuinfo                    9.0.0
pyarrow                       11.0.0
pycosat                       0.6.4
pycparser                     2.21
pycurl                        7.45.1
Pygments                      2.14.0
PyJWT                         2.6.0
pyOpenSSL                     23.1.1
pyparsing                     3.0.9
pyrsistent                    0.19.3
PySocks                       1.7.1
python-dateutil               2.8.2
python-json-logger            2.0.7
pytz                          2023.3
PyWavelets                    1.4.1
PyYAML                        6.0
pyzmq                         25.0.2
requests                      2.28.2
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
ruamel.yaml                   0.17.21
ruamel.yaml.clib              0.2.7
scikit-image                  0.20.0
scikit-learn                  1.2.2
scipy                         1.10.1
seaborn                       0.12.2
Send2Trash                    1.8.0
setuptools                    71.1.0
six                           1.16.0
sniffio                       1.3.0
sortedcontainers              2.4.0
soupsieve                     2.3.2.post1
SQLAlchemy                    2.0.9
stack-data                    0.6.2
statsmodels                   0.13.5
sympy                         1.11.1
tables                        3.8.0
tblib                         1.7.0
terminado                     0.17.1
threadpoolctl                 3.1.0
tifffile                      2023.3.21
tinycss2                      1.2.1
tomli                         2.0.1
toolz                         0.12.0
tornado                       6.2
tqdm                          4.65.0
traitlets                     5.9.0
typing_extensions             4.5.0
tzdata                        2023.3
unicodedata2                  15.0.0
urllib3                       1.26.15
wcwidth                       0.2.6
webencodings                  0.5.1
websocket-client              1.5.1
wheel                         0.40.0
widgetsnbextension            4.0.7
xlrd                          2.0.1
y-py                          0.5.9
ypy-websocket                 0.8.2
zict                          2.2.0
zipp                          3.15.0
zstandard                     0.19.0

Then we call python setup.py sdist to build our package.

Output

Error message from python setup.py sdist when using setuptools 71.1.0 as above:

Traceback (most recent call last):
  File "/__w/1/s/prodaps-python/setup.py", line 30, in <module>
    import setuptools
  File "/home/jovyan/.local/lib/python3.10/site-packages/setuptools/__init__.py", line 21, in <module>
    from .dist import Distribution
  File "/home/jovyan/.local/lib/python3.10/site-packages/setuptools/dist.py", line 29, in <module>
    from . import _entry_points
  File "/home/jovyan/.local/lib/python3.10/site-packages/setuptools/_entry_points.py", line 6, in <module>
    from jaraco.text import yield_lines
  File "/home/jovyan/.local/lib/python3.10/site-packages/setuptools/_vendor/jaraco/text/__init__.py", line 12, in <module>
    from jaraco.context import ExceptionTrap
  File "/home/jovyan/.local/lib/python3.10/site-packages/setuptools/_vendor/jaraco/context.py", line 17, in <module>
    from backports import tarfile
ImportError: cannot import name 'tarfile' from 'backports' (/opt/conda/lib/python3.10/site-packages/backports/__init__.py)

The same error message resulted with setuptools 71.0.4 too.

glatterf42 commented 1 month ago

I can confirm that this error persists for our tests on GitHub Actions with the windows runners, using Python 3.8 and Setuptools 71.0.4. Curiously, though, it only happens when pinning another package (JPype1) to a specific version (1.2.1). Using it's latest version does not result in the same error. Please see here for the complete information on today's CI run.

glatterf42 commented 1 month ago

Sorry, didn't know #4508 was already opened. These are duplicates, it seems.

glatterf42 commented 1 month ago

One difference I notice between our windows-latest-miniconda- and windows-latest-miniconda-JPype1=1.2.1 tests is that the latter installs pyam v1.9.0 due to the pin, which directly imports from setuptools_scm (get_version(), using v8.1.0). The former installs pyam v2.2.2, which doesn't rely on setuptools_scm anymore, so this package is never installed and the workflow passes just fine.

jaraco commented 1 month ago

Closing as a dupe of #4508 unless we find otherwise.

jaraco commented 1 month ago

I apologize. I see now I directed the reporter to file a separate ticket for this issue if 71.0.4 didn't fix the issue. I missed the association. Is this issue still impacting users?

glatterf42 commented 1 month ago

My error case has been resolved, thanks :)

cacti77 commented 3 weeks ago

I apologize. I see now I directed the reporter to file a separate ticket for this issue if 71.0.4 didn't fix the issue. I missed the association. Is this issue still impacting users?

Unfortunately I'm constrained to use a particular Docker image (and hence conda version) for now and have worked around it by doing: python -m pip install --upgrade pip "setuptools<71"

So until I upgrade to a Docker image that uses a later version of conda I can't test this isn't an issue any more, unless I'm mistaken. I'd also rather not issue conda commands in my environment.