Skip to content

Commit 5abb5b2

Browse files
committed
Single source package version
I admit the approach is complex... But it is the only reliable way to do it with a single file.
1 parent a3c4b58 commit 5abb5b2

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

setup.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
import memory_profiler
1+
import os
2+
import io
3+
import re
24
from distutils.core import setup
35
import setuptools
46

7+
8+
# https://packaging.python.org/guides/single-sourcing-package-version/
9+
def read(*names, **kwargs):
10+
with io.open(
11+
os.path.join(os.path.dirname(__file__), *names),
12+
encoding=kwargs.get("encoding", "utf8")
13+
) as fp:
14+
return fp.read()
15+
16+
17+
def find_version(*file_paths):
18+
version_file = read(*file_paths)
19+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
20+
version_file, re.M)
21+
if version_match:
22+
return version_match.group(1)
23+
24+
525
CLASSIFIERS = """\
626
Development Status :: 5 - Production/Stable
727
Intended Audience :: Science/Research
@@ -24,7 +44,7 @@
2444
name='memory_profiler',
2545
description='A module for monitoring memory usage of a python program',
2646
long_description=open('README.rst').read(),
27-
version=memory_profiler.__version__,
47+
version=find_version("memory_profiler.py"),
2848
author='Fabian Pedregosa',
2949
author_email='f@bianp.net',
3050
url='http://pypi.python.org/pypi/memory_profiler',

0 commit comments

Comments
 (0)