|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # SPDX-License-Identifier: LGPL-3.0-only |
3 | | - |
4 | | -# Notes for the not-an-everyday-python-dev for package distribution on pypi |
5 | | -# |
6 | | -# Build the package using `setuptools`: |
7 | | -# |
8 | | -# python setup.py sdist bdist_wheel |
9 | | -# |
10 | | -# Make sure you have ~/.pypirc correctly populated, as of today should look something like: |
11 | | -# |
12 | | -# [distutils] |
13 | | -# index-servers = |
14 | | -# pypi |
15 | | -# testpypi |
16 | | -# |
17 | | -# [pypi] |
18 | | -# username: username-here |
19 | | -# password: password-here |
20 | | -# |
21 | | -# [testpypi] |
22 | | -# repository: https://test.pypi.org/legacy/ |
23 | | -# username: username-here (not necessarily same as real pypi) |
24 | | -# password: password-here (not necessarily same as real pypi) |
25 | | -# |
26 | | -# Then upload using twine to testpypi first: |
27 | | -# |
28 | | -# twine upload -r testpypi dist/* |
29 | | -# |
30 | | -# If all looks good go ahead and tag the repo, push to GH, and then push to real |
31 | | -# pypi: |
32 | | -# |
33 | | -# twine upload dist/* |
34 | | -# |
35 | | -# Congratulations to me, I've just condensed so many webpages into 30 lines, |
36 | | -# :raised_hands:! |
| 3 | +import codecs |
| 4 | +import os.path |
37 | 5 |
|
38 | 6 | try: |
39 | 7 | from setuptools import setup |
40 | 8 | except ImportError: |
41 | 9 | from ez_setup import use_setuptools |
42 | | - |
43 | 10 | use_setuptools() |
44 | 11 | from setuptools import setup |
45 | 12 |
|
| 13 | + |
46 | 14 | with open("README.md") as readme, open("CHANGELOG.md") as changelog: |
47 | 15 | long_description = readme.read() + "\n" + changelog.read() |
48 | 16 |
|
| 17 | +def read(rel_path): |
| 18 | + here = os.path.abspath(os.path.dirname(__file__)) |
| 19 | + with codecs.open(os.path.join(here, rel_path), 'r') as fp: |
| 20 | + return fp.read() |
| 21 | + |
| 22 | +def get_version(rel_path): |
| 23 | + for line in read(rel_path).splitlines(): |
| 24 | + if line.startswith('__version__'): |
| 25 | + delim = '"' if '"' in line else "'" |
| 26 | + return line.split(delim)[1] |
| 27 | + else: |
| 28 | + raise RuntimeError("Unable to find version string.") |
| 29 | + |
49 | 30 | setup( |
50 | 31 | name="packet-python", |
51 | | - version="1.42.0", |
| 32 | + version=get_version("packet/__init__.py"), |
52 | 33 | description="Packet API client", |
53 | 34 | long_description=long_description, |
54 | 35 | long_description_content_type="text/markdown", |
|
0 commit comments