|
1 | | -from setuptools import setup |
2 | | -import bip32 |
3 | 1 | import io |
| 2 | +import os |
| 3 | + |
| 4 | +from setuptools import setup |
| 5 | + |
| 6 | + |
| 7 | +# Taken from https://github.com/pypa/pip/blob/003c7ac56b4da80235d4a147fbcef84b6fbc8248/setup.py#L7-L21 |
| 8 | +def read(rel_path: str) -> str: |
| 9 | + here = os.path.abspath(os.path.dirname(__file__)) |
| 10 | + # intentionally *not* adding an encoding option to open, See: |
| 11 | + # https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 |
| 12 | + with open(os.path.join(here, rel_path)) as fp: |
| 13 | + return fp.read() |
| 14 | + |
| 15 | + |
| 16 | +# Taken from https://github.com/pypa/pip/blob/003c7ac56b4da80235d4a147fbcef84b6fbc8248/setup.py#L7-L21 |
| 17 | +def get_version(rel_path: str) -> str: |
| 18 | + for line in read(rel_path).splitlines(): |
| 19 | + if line.startswith("__version__"): |
| 20 | + # __version__ = "0.9" |
| 21 | + delim = '"' if '"' in line else "'" |
| 22 | + return line.split(delim)[1] |
| 23 | + raise RuntimeError("Unable to find version string.") |
4 | 24 |
|
5 | 25 |
|
6 | 26 | with io.open("README.md", encoding="utf-8") as f: |
|
10 | 30 | requirements = [r for r in f.read().split('\n') if len(r)] |
11 | 31 |
|
12 | 32 | setup(name="bip32", |
13 | | - version=bip32.__version__, |
| 33 | + # We use the first approach from https://packaging.python.org/en/latest/guides/single-sourcing-package-version |
| 34 | + version=get_version("bip32/__init__.py"), |
14 | 35 | description="Minimalistic implementation of the BIP32 key derivation scheme", |
15 | 36 | long_description=long_description, |
16 | 37 | long_description_content_type="text/markdown", |
|
0 commit comments