Strange 150 ms fine using python setuptools

I had a weird 150 second start-out using python setuptools, I built a minimal test case, and the problem still exists:

My project layout for this minimum case:

- setup.py
- setuptest
- - __init__.py
- - __main__.py

The setup.py file contains:

from setuptools import setup

setup(
    name         = 'setuptest',
    version      = '0.1',
    packages     = ['setuptest'],

    entry_points = {
        'console_scripts' : ['setuptest = setuptest.__main__:main']
        } ,
    )

The __main__.py file contains simply:

#!/usr/bin/env python2

def main ():
    print "hai"

if __name__ == '__main__':
    main()

Doing this at the root of the project:

 —— — time python2 setuptest
hai

real    0m0.021s
user    0m0.017s
sys     0m0.004s

Gives me only 21 ms script execution, however after starting sudo python2 setup.py installand executing:

 —— — time setuptest 
hai

real    0m0.158s
user    0m0.144s
sys     0m0.012s
 —— — 

Gives me 158 ms. This start delay time of 150 seconds is consistent and occurs throughout the board when I use setuptools, but does not happen with things that I installed through the package manager or manually installing some other project, so it seems to me that I am obviously doing that something very wrong.

+4
3

, , , , . , setuptools , , - , , , distutils .

, , distutils

:

from distutils.core import setup

setup(
    name         = 'disttest',
    version      = '0.1',
    packages     = ['disttest'],

    scripts      = ['bin/disttest']
    )

bin/disttest - , , . distutils.core setuptools - , . , distuitls .

-1

, setuptools, script bin, :

import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('<PACKAGE_NAME>', 'console_scripts', '<ENTRY_POINT>')()
    )

load_entry_point() , sys.path, , , , .

setuptools load_entry_point():

setuptools.py:load_entry_point():

def load_entry_point(dist, group, name):
    """Return `name` entry point of `group` for `dist` or raise ImportError"""
    return get_distribution(dist).load_entry_point(group, name)

'setuptools.py:get_distribution()':

def get_distribution(dist):
    """Return a current distribution object for a Requirement or string"""
    if isinstance(dist,basestring): dist = Requirement.parse(dist)
    if isinstance(dist,Requirement): dist = get_provider(dist)
    if not isinstance(dist,Distribution):
        raise TypeError("Expected string, Requirement, or Distribution", dist)
    return dist

setuptools.py:Distribution.load_entry_point():

def load_entry_point(self, group, name):
    """Return the `name` entry point of `group` or raise ImportError"""
    ep = self.get_entry_info(group,name)
    if ep is None:
        raise ImportError("Entry point %r not found" % ((group,name),))
    return ep.load()

setuptools.py:Distribution.get_entry_info():

def get_entry_info(self, group, name):
    """Return the EntryPoint object for `group`+`name`, or ``None``"""
    return self.get_entry_map(group).get(name)

, , . , Distribution, (, _dep_map) .

+2

, , " python setup.py install" "pip install". ( .egg), script pkg_resources, .

, (.whl), , script pkg_resources . , cookiecutter .

https://github.com/audreyr/cookiecutter

" python setup.py", script pkg_resources ( ):

#!/usr/local/opt/python3/bin/python3.5
# EASY-INSTALL-ENTRY-SCRIPT: 'cookiecutter==1.5.1','console_scripts','cookiecutter'
__requires__ = 'cookiecutter==1.5.1'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('cookiecutter==1.5.1', 'console_scripts', 'cookiecutter')()
    )

, :

python setup.py bdist_wheel
pip install dist/cookiecutter-1.5.1-py2.py3-none-any.whl

The script executable does not contain imports from pkg_resources (and faster):

#!/usr/local/opt/python3/bin/python3.5

# -*- coding: utf-8 -*-
import re
import sys

from cookiecutter.__main__ import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
0
source

All Articles