简体   繁体   中英

Why does find_packages behavior depend on import of pip package?

I have following project structure:

prog
  __init__.py
tests
  subpak
    __init__.py
  __init__.py
run1.py
run2.py

run1.py:

#!/usr/bin/env python3
from setuptools import find_packages


for i in sorted(find_packages(exclude=['tests'])):
    print(i)

run2.py:

#!/usr/bin/env python3
import pip
from setuptools import find_packages


for i in sorted(find_packages(exclude=['tests'])):
    print(i)

The rest of the files are empty. Environment - Debian testing. python 3.5.

run1.py output:

$ python3 run1.py 
prog

run2.py output:

$ python3 run2.py 
prog
tests.subpak

That is, when find_packages is imported after pip , it no longer excludes sub-packages of excluded package. Why is this happening and what kind of mechanisms are involved in this peculiar behavior?

edit: It appears that pip or some of its dependencies are changing syspath, and setuptools modules are different. Run1:

<module 'setuptools' from '/usr/lib/python3/dist-packages/setuptools/__init__.py'>

Run2:

<module 'setuptools' from '/usr/share/python-wheels/setuptools-20.10.1-py2.py3-none-any.whl/setuptools/__init__.py'>

pip imports wheel support, and this appears to unlock a wheel you didn't know you had:

<module 'setuptools' from '/usr/share/python-wheels/setuptools-20.10.1-py2.py3-none-any.whl/setuptools/__init__.py'>

Without the wheel you are importing a system-wide setuptools version:

<module 'setuptools' from '/usr/lib/python3/dist-packages/setuptools/__init__.py'> 

This version appears to be broken, because test.subpack is supposed to be included (filter it out by adding 'tests.*' to the exclude list).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM