├── example1 ├── mymodule │ ├── mymodule │ │ ├── __init__.py │ │ └── script.py │ └── setup.py └── README.md ├── README.md ├── .gitignore └── LICENSE /example1/mymodule/mymodule/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | setuptools 2 | ========== 3 | 4 | examples using setuptools 5 | -------------------------------------------------------------------------------- /example1/mymodule/mymodule/script.py: -------------------------------------------------------------------------------- 1 | 2 | from __future__ import print_function 3 | 4 | def main(): 5 | try: 6 | import requests 7 | print('requests is present. kudos!') 8 | except ImportError: 9 | raise RuntimeError('how the heck did you install this?') 10 | 11 | -------------------------------------------------------------------------------- /example1/mymodule/setup.py: -------------------------------------------------------------------------------- 1 | 2 | from setuptools import setup 3 | setup( 4 | name='mymodule', 5 | packages=['mymodule'], 6 | entry_points={ 7 | 'console_scripts' : [ 8 | 'mycommand = mymodule.script:main', 9 | ] 10 | }, 11 | install_requires=[ 12 | 'requests', 13 | ] 14 | ) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 python-examples 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /example1/README.md: -------------------------------------------------------------------------------- 1 | This example shows how to use some basic features of `setuptools`. 2 | 3 | The first one is `install_requires` which allows you to automatically install 4 | dependencies that you need. 5 | 6 | Another one is `entry_points`, where you can declare `console_scripts` which 7 | will then be new commands available in your environment. 8 | 9 | This particular example will install the `requests` package as a dependency, 10 | then install a new command `mycommand` in your environment. You can test it 11 | with the help of `virtualenv`: 12 | 13 | $ virtualenv test 14 | $ source test/bin/activate 15 | (test)$ pip install ./mymodule/ 16 | (test)$ mycommand 17 | 18 | You can also check what would happen if you were missing the dependencies 19 | and distributed the code without a `setup.py`. In this case, `requests` is 20 | not part of the standard library, so unless you install it, it would not be 21 | present. Please note that this time we cannot run `mycommand` since we are not 22 | installing `mymodule`. 23 | 24 | $ virtualenv --clear test 25 | $ source test/bin/activate 26 | (test)$ cd mymodule 27 | (test)$ python -c 'import mymodule.script; mymodule.script.main()' 28 | 29 | --------------------------------------------------------------------------------