2021年5月5日星期三

Pip installs console_scripts entry point even when required extra is not present

Given this fairly minimal setup.py (greenlet and gevent are just placeholders for arbitrary dependencies)

from setuptools import find_namespace_packages, setup    setup(      name='foo',      version='0.0.1',      platforms='any',      packages=find_namespace_packages(),      install_requires=['greenlet'],      extras_require={          'bar': ['gevent']      },      entry_points={          'console_scripts': [              'foo-script = foo.script:main',              'bar-script = foo.bar:main [bar]'          ]      }  )  

with foo/script.py containing this

def main():      try:          import greenlet      except:          print('Dependency missing.')      else:          print('Found dependency.')  

and foo/bar.py containing this

def main():      try:          import gevent      except:          print('Dependency missing.')      else:          print('Found dependency.')  

I would assume that, when I run pip install ., it would just install foo-script and only install bar-script if I did pip install .[bar].

However, I find that bar-script is installed in any case, expectedly telling me "Dependency missing" in the first case. According to the documentation on entry points, I would have assumed that this would not be the case, so I am wondering if this is the intended behavior. If it is, I am not sure I understand the point of being able to specify dependencies for individual entry points in the first place, if not even core ecosystem tooling like pip seems to honor them.

https://stackoverflow.com/questions/67410934/pip-installs-console-scripts-entry-point-even-when-required-extra-is-not-present May 06, 2021 at 10:08AM

没有评论:

发表评论