Skip to content

Commit 043a715

Browse files
committed
Extract metadata directly from source
This affects all the __version__, __author__ etc.
1 parent 6c2f4f0 commit 043a715

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

semver.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Python helper for Semantic Versioning (http://semver.org/)"""
1+
"""Python helper for Semantic Versioning (http://semver.org)"""
22
from __future__ import print_function
33

44
import argparse
@@ -15,6 +15,7 @@
1515
__author_email__ = "[email protected]"
1616
__maintainer__ = ["Sebastien Celles", "Tom Schraitle"]
1717
__maintainer_email__ = "[email protected]"
18+
__description__ = "Python helper for Semantic Versioning (http://semver.org)"
1819

1920
#: Our public interface
2021
__all__ = (
@@ -222,11 +223,7 @@ class VersionInfo(object):
222223

223224
def __init__(self, major, minor=0, patch=0, prerelease=None, build=None):
224225
# Build a dictionary of the arguments except prerelease and build
225-
version_parts = {
226-
"major": major,
227-
"minor": minor,
228-
"patch": patch,
229-
}
226+
version_parts = {"major": major, "minor": minor, "patch": patch}
230227

231228
for name, value in version_parts.items():
232229
value = int(value)

setup.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
11
#!/usr/bin/env python3
2-
import semver as package
2+
# import semver as package
33
from os.path import dirname, join
44
from setuptools import setup
5+
import re
6+
7+
8+
VERSION_MATCH = re.compile(r"__version__ = ['\"]([^'\"]*)['\"]", re.M)
59

610

711
def read_file(filename):
812
with open(join(dirname(__file__), filename)) as f:
913
return f.read()
1014

1115

16+
def find_meta(meta):
17+
"""
18+
Extract __*meta*__ from META_FILE.
19+
"""
20+
meta_match = re.search(
21+
r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M
22+
)
23+
if meta_match:
24+
return meta_match.group(1)
25+
raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))
26+
27+
28+
NAME = "semver"
29+
META_FILE = read_file("semver.py")
30+
31+
32+
# -----------------------------------------------------------------------------
1233
setup(
13-
name=package.__name__,
14-
version=package.__version__,
15-
description=package.__doc__.strip(),
34+
name=NAME,
35+
version=find_meta("version"),
36+
description=find_meta("description").strip(),
1637
long_description=read_file("README.rst"),
1738
long_description_content_type="text/x-rst",
18-
author=package.__author__,
19-
author_email=package.__author_email__,
39+
author=find_meta("author"),
40+
author_email=find_meta("author_email"),
2041
url="https://github.com/python-semver/python-semver",
2142
download_url="https://github.com/python-semver/python-semver/downloads",
2243
project_urls={
2344
"Documentation": "https://python-semver.rtfd.io",
2445
"Releases": "https://github.com/python-semver/python-semver/releases",
2546
"Bug Tracker": "https://github.com/python-semver/python-semver/issues",
2647
},
27-
py_modules=[package.__name__],
48+
py_modules=[NAME],
2849
include_package_data=True,
2950
license="BSD",
3051
classifiers=[

0 commit comments

Comments
 (0)