Replace tpo git repository URL by gitlab
[stem.git] / setup.py
blobdfe855da7bbf4f568455b9f34345c6406c435588
1 #!/usr/bin/env python
2 # Copyright 2012-2020, Damian Johnson and The Tor Project
3 # See LICENSE for licensing information
5 # Release Checklist
6 # =================
8 # * Recache latest information (cache_manual.py and cache_fallback_directories.py)
10 # * Test with python3 and pypy.
11 # |- If using tox run...
12 # |
13 # | % tox -- --all --target RUN_ALL,ONLINE
14 # |
15 # | Otherwise, for each interpreter run...
16 # |
17 # | % [python_interpreter] run_tests.py --all --target RUN_ALL,ONLINE
18 # |
19 # |- Pypy test instructions for ubuntu are...
20 # |
21 # | % sudo apt-get install pypy
22 # | % wget https://bootstrap.pypa.io/get-pip.py
23 # | % pypy get-pip.py --user
24 # | % ~/.local/bin/pip install mock pycodestyle pyflakes --user
25 # | % pypy ./run_tests.py --all
26 # |
27 # +- Some version of python 3.x should be available in your platform's
28 # repositories. To test against a specific version on ubuntu try the
29 # following. In this example, Python 3.7...
31 # % sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
32 # % sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev
33 # % sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
34 # % sudo apt-get install libssl-dev openssl libffi-dev
36 # % wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
37 # % tar -xzf Python-3.7.0.tgz
38 # % mv Python-3.7.0 ~
40 # % cd ~/Python-3.7.0
41 # % ./configure
42 # % make
44 # % cd /path/to/stem
45 # % ~/Python-3.7.0/python ./run_tests.py --all
47 # * Tag the release
48 # |- Bump stem's version (in stem/__init__.py and docs/index.rst).
49 # |- git commit -a -m "Stem release 1.0.0"
50 # |- git tag -u 9ABBEEC6 -m "stem release 1.0.0" 1.0.0 d0bb81a
51 # +- git push --tags
53 # * Dry-run release on https://pypi.org/project/stem/
54 # |- python setup.py sdist --dryrun
55 # |- gpg --detach-sig --armor dist/stem-dry-run-1.0.0.tar.gz
56 # |- twine upload dist/*
57 # +- Check that https://pypi.org/project/stem-dry-run/ looks correct, comparing it to https://pypi.org/project/stem/
58 # +- Don't worry about the 'Bug Tracker' being missing. That's an attribute of the project itself.
60 # * Final release
61 # |- rm dist/*
62 # |- python setup.py sdist
63 # |- gpg --detach-sig --armor dist/stem-1.0.0.tar.gz
64 # +- twine upload dist/*
66 # * Contact package maintainers
67 # * Announce the release (example: https://blog.torproject.org/blog/stem-release-11)
69 import setuptools
70 import os
71 import re
72 import sys
74 if '--dryrun' in sys.argv:
75 DRY_RUN = True
76 sys.argv.remove('--dryrun')
77 else:
78 DRY_RUN = False
80 SUMMARY = 'Stem is a Python controller library that allows applications to interact with Tor (https://www.torproject.org/).'
81 DRY_RUN_SUMMARY = 'Ignore this package. This is dry-run release creation to work around PyPI limitations (https://github.com/pypa/packaging-problems/issues/74#issuecomment-260716129).'
83 DESCRIPTION = """
84 For tutorials and API documentation see `Stem's homepage <https://stem.torproject.org/>`_.
86 Quick Start
87 -----------
89 To install you can either use...
93 pip install stem
95 ... or install from the source tarball. Stem supports Python 3.6 and above.
97 After that, give some `tutorials <https://stem.torproject.org/tutorials.html>`_ a try! For questions or to discuss project ideas we're available on `irc <https://www.torproject.org/about/contact.html.en#irc>`_ and the `tor-dev@ email list <https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev>`_.
98 """.strip()
100 MANIFEST = """
101 include cache_fallback_directories.py
102 include cache_manual.py
103 include LICENSE
104 include README.md
105 include MANIFEST.in
106 include requirements.txt
107 include run_tests.py
108 include tox.ini
109 graft docs
110 graft test
111 global-exclude __pycache__
112 global-exclude *.orig
113 global-exclude *.pyc
114 global-exclude *.swp
115 global-exclude *.swo
116 global-exclude .tox
117 global-exclude *~
118 recursive-exclude test/data *
119 recursive-exclude docs/_build *
120 """.strip()
122 # installation requires us to be in our setup.py's directory
124 os.chdir(os.path.dirname(os.path.abspath(__file__)))
126 with open('MANIFEST.in', 'w') as manifest_file:
127 manifest_file.write(MANIFEST)
130 def get_module_info():
131 # reads the basic __stat__ strings from our module's init
133 STAT_REGEX = re.compile(r"^__(.+)__ = '(.+)'$")
134 result = {}
135 cwd = os.path.sep.join(__file__.split(os.path.sep)[:-1])
137 with open(os.path.join(cwd, 'stem', '__init__.py')) as init_file:
138 for line in init_file.readlines():
139 line_match = STAT_REGEX.match(line)
141 if line_match:
142 keyword, value = line_match.groups()
143 result[keyword] = value
145 return result
148 module_info = get_module_info()
150 try:
151 setuptools.setup(
152 name = 'stem-dry-run' if DRY_RUN else 'stem',
153 version = module_info['version'],
154 description = DRY_RUN_SUMMARY if DRY_RUN else SUMMARY,
155 long_description = DESCRIPTION,
156 license = module_info['license'],
157 author = module_info['author'],
158 author_email = module_info['contact'],
159 url = module_info['url'],
160 packages = setuptools.find_packages(exclude=['test*']),
161 keywords = 'tor onion controller',
162 scripts = ['tor-prompt'],
163 package_data = {
164 'stem': ['cached_fallbacks.cfg', 'cached_manual.sqlite', 'settings.cfg'],
165 'stem.interpreter': ['settings.cfg'],
166 'stem.util': ['ports.cfg'],
167 }, classifiers = [
168 'Development Status :: 5 - Production/Stable',
169 'Intended Audience :: Developers',
170 'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
171 'Topic :: Security',
172 'Topic :: Software Development :: Libraries :: Python Modules',
175 finally:
176 for filename in ['MANIFEST.in', 'MANIFEST']:
177 if os.path.exists(filename):
178 os.remove(filename)