martger.blogg.se

Setuptools setup
Setuptools setup








setuptools setup

The combination of the approaches to this point should be enough to satisfy even complex projects. So the executable script written to the bin directory effectively acts as a redirect to your source file, executing it. require ( 'hello=0.1.0' ) _file_ = '/path/to/hello/scripts/hello_world' exec ( compile ( open ( _file_ ). # EASY-INSTALL-DEV-SCRIPT: 'hello_world=0.1.0','hello_world' scripts/hello_world or python -m hello_world, they can simply run the script directly: This means that users now don't have to fiddle with running. The important thing to note in the above is Installing hello_world script to /path/to/.venv/bin. Processing dependencies for hello_world =0.1.0įinished processing dependencies for hello_world =0.1.0 Installing hello_world script to /path/to/.venv/bin )Īdding hello 0.1.0 to easy-install.pth file Reading manifest file 'hello_world.egg-info/SOURCES.txt'Ĭreating /path/to/.venv/lib/python3.7/site-packages/hello_world.egg-link ( link to. Writing manifest file 'hello_world.egg-info/SOURCES.txt'

setuptools setup

Writing top-level names to hello_world.egg-info/top_level.txt Writing dependency_links to hello_world.egg-info/dependency_links.txt If we adopt this new learning to hello_world.py, it would then look like this:

setuptools setup

A module can discover whether or not it is running in the main scope by checking its own name, which allows a common idiom for conditionally executing code in a module when it is run as a script or with python -m but not when it is imported.

setuptools setup

A module’s name is set equal to '_main_' when read from standard input, a script, or from an interactive prompt. '_main_' is the name of the scope in which top-level code executes. So then, what's the next best thing? Using the if name = ' main' pattern. So now we know that sticking all of our functionality in a Python script isn't the best approach if we want to reuse or write unit tests. Not only is it functionally not what you're going to be after, but writing unit test for it will be difficult if not impossible, especially if there is any state change through side effects. In : import hello_world hello world !Īs you can see in the above, the problem with the Python script approach is that it's overly simple and functionality is executed at import time, which is typically not what you're after.










Setuptools setup