Reputation: 504
PEP 508 describes how to set additional specifications for dependencies. This can be used for example to specify that a dependency should only be installed on Linux systems.
Is there any way to use this syntax to specify a minumum pip
version for a package?
My use case: one dependency is built with manylinux2010
and requires pip
>= 19.0. I would like the dependency to be installed when pip
>= 19.0, and ignored otherwise. This is different from Include minimum pip version in setup.py where the author wants to restrict the pip
version for the whole project.
Thanks!
Upvotes: 0
Views: 199
Reputation: 22275
You could make an ugly hack like this in setup.py
:
import pkg_resources
import setuptools
install_requires = [
# ...
]
try:
pip_dist = pkg_resources.get_distribution('pip')
except:
pass
else:
if pip_dist.parsed_version > pkg_resources.parse_version('19'):
install_requires.append('Library')
setuptools.setup(
# ...
install_requires=install_requires,
)
This is written off the top of my head (pseudo code), untested, tweaking will most likely be required.
I definitely would not recommend doing this, this has lots of red flags, goes against many best practice recommendations.
Most importantly the condition on pip's version number will not be respected as soon as build isolation is involved or if installing from a wheel (wheels do not contain the setup.py
file).
Upvotes: 1
Reputation: 139
In your setup.py, add the below snippet before anything.
Code:
import pip
if pip.__version__ < '19':
raise RuntimeError('Required pip>=19.0 to install')
import spam
import foo
...
...
setup(...)
This will check if the pip dependency is maintained or not.
Upvotes: 0