Skip to content

Failed installation: setup.py import assumes deps already installed #37

@dfernandez-at-wiris

Description

@dfernandez-at-wiris

When installing ipregistry 2.0.0 in our CI server we get the following errors:

#8 7.073 Collecting ipregistry==2.0.0
#8 7.144   Downloading ipregistry-2.0.0.tar.gz (5.8 kB)
#8 7.338     ERROR: Command errored out with exit status 1:
#8 7.338      command: /var/lang/bin/python3.8 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-paikyw6j
#8 7.338          cwd: /tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/
#8 7.338     Complete output (9 lines):
#8 7.338     Traceback (most recent call last):
#8 7.338       File "<string>", line 1, in <module>
#8 7.338       File "/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/setup.py", line 3, in <module>
#8 7.338         from ipregistry import __version__
#8 7.338       File "/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/ipregistry/__init__.py", line 5, in <module>
#8 7.338         from .cache import *
#8 7.338       File "/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/ipregistry/cache.py", line 17, in <module>
#8 7.338         import abc, six
#8 7.338     ModuleNotFoundError: No module named 'six'
#8 7.338     ----------------------------------------
#8 7.342 WARNING: Discarding https://files.pythonhosted.org/packages/aa/eb/791256c45052d3fde4fe7e6d10b489f025b943ce56cfde691cff46dd1090/ipregistry-2.0.0.tar.gz#sha256=f07a5f9b8b791b83f648f47475e53d600a91cc52d8f7658486d946a87bb9bad0 (from https://pypi.org/simple/ipregistry/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#8 7.342 ERROR: Could not find a version that satisfies the requirement ipregistry==2.0.0 (from versions: 1.0.0, 1.1.0, 2.0.0, 2.0.1, 3.0.0, 3.1.0)
#8 7.342 ERROR: No matching distribution found for ipregistry==2.0.0
#8 7.463 WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
#8 7.463 You should consider upgrading via the '/var/lang/bin/python3.8 -m pip install --upgrade pip' command.
#8 ERROR: process "/bin/sh -c pip install --no-cache-dir -r /tmp/requirements.txt" did not complete successfully: exit code: 1
------
 > [4/7] RUN pip install --no-cache-dir -r /tmp/requirements.txt:
#8 7.338         from .cache import *
#8 7.338       File "/tmp/pip-install-s1_fc88h/ipregistry_0f83ab2a0e3d4d13bdf0bb70c6d21a9e/ipregistry/cache.py", line 17, in <module>
#8 7.338         import abc, six
#8 7.338     ModuleNotFoundError: No module named 'six'
#8 7.338     ----------------------------------------
#8 7.342 WARNING: Discarding https://files.pythonhosted.org/packages/aa/eb/791256c45052d3fde4fe7e6d10b489f025b943ce56cfde691cff46dd1090/ipregistry-2.0.0.tar.gz#sha256=f07a5f9b8b791b83f648f47475e53d600a91cc52d8f7658486d946a87bb9bad0 (from https://pypi.org/simple/ipregistry/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#8 7.342 ERROR: Could not find a version that satisfies the requirement ipregistry==2.0.0 (from versions: 1.0.0, 1.1.0, 2.0.0, 2.0.1, 3.0.0, 3.1.0)
#8 7.342 ERROR: No matching distribution found for ipregistry==2.0.0

The reason seems to be that setup.py imports from the module (from ipregistry import __version__). This import in turn causes __init__.py to run several other imports, basically trying to import all of its dependencies, like that import abc, six you see above. Because the deps are not yet installed, the whole process fails. This all happens before the installation begins.

In our case, this was solved by manually installing ALL dependencies in our CI server before beginning the build process (and in our local dev environment for development). This is not only quite inconvenient, but could cause dependency problems in monorepo-style projects.

A suggestion for a simple and quick fix would be to store the __version__ variable in a separate version.py. This way __init__.py would import from it and setup.py would not require importing all dependencies of the (yet to install) package.

Additionally, the reason we are using version ipregistry 2.0.0 is that requirements are very strict (all are ==), which means that our dependency management tool (poetry) won't be able to find a compatible combination of dependency versions with the other packages we're using. Seeing as this package is seldomly updated and its dependencies are a few, fairly stable packages like requests, I'd suggest relaxing those requirements to allow for patches or even minor version upgrades (e.g. requests>=2.22.0,<3).

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions