Skip to content

Commit 6b3df85

Browse files
committed
On old pythons typing.Type can cause unexpected errors -> deactivate
MyPy will still check types, while in normal runtime type will be string Signed-off-by: Alexey Stepanov <penguinolog@gmail.com> (cherry picked from commit cd77add) Signed-off-by: Alexey Stepanov <penguinolog@gmail.com>
1 parent f738128 commit 6b3df85

File tree

3 files changed

+29
-114
lines changed

3 files changed

+29
-114
lines changed

doc/source/conf.py

Lines changed: 6 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -13,110 +13,11 @@
1313
# All configuration values have a default; values that are commented out
1414
# serve to show the default.
1515

16-
import ast
17-
import collections
18-
import os.path
19-
import sys
20-
21-
PY3 = sys.version_info[:2] > (2, 7)
22-
PY34 = sys.version_info[:2] > (3, 3)
23-
24-
with open(
25-
os.path.join(
26-
os.path.dirname(__file__), '..', '..',
27-
'exec_helpers', '__init__.py'
28-
)
29-
) as f:
30-
source = f.read()
31-
32-
33-
# noinspection PyUnresolvedReferences
34-
def get_simple_vars_from_src(src):
35-
"""Get simple (string/number/boolean and None) assigned values from source.
36-
37-
:param src: Source code
38-
:type src: str
39-
:returns: OrderedDict with keys, values = variable names, values
40-
:rtype: typing.Dict[
41-
str,
42-
typing.Union[
43-
str, bytes,
44-
int, float, complex,
45-
list, set, dict, tuple,
46-
None,
47-
]
48-
]
49-
50-
Limitations: Only defined from scratch variables.
51-
Not supported by design:
52-
* Imports
53-
* Executable code, including string formatting and comprehensions.
54-
55-
Examples:
56-
57-
>>> string_sample = "a = '1'"
58-
>>> get_simple_vars_from_src(string_sample)
59-
OrderedDict([('a', '1')])
60-
61-
>>> int_sample = "b = 1"
62-
>>> get_simple_vars_from_src(int_sample)
63-
OrderedDict([('b', 1)])
64-
65-
>>> list_sample = "c = [u'1', b'1', 1, 1.0, 1j, None]"
66-
>>> result = get_simple_vars_from_src(list_sample)
67-
>>> result == collections.OrderedDict(
68-
... [('c', [u'1', b'1', 1, 1.0, 1j, None])]
69-
... )
70-
True
71-
72-
>>> iterable_sample = "d = ([1], {1: 1}, {1})"
73-
>>> get_simple_vars_from_src(iterable_sample)
74-
OrderedDict([('d', ([1], {1: 1}, {1}))])
75-
76-
>>> multiple_assign = "e = f = g = 1"
77-
>>> get_simple_vars_from_src(multiple_assign)
78-
OrderedDict([('e', 1), ('f', 1), ('g', 1)])
79-
"""
80-
ast_data = (
81-
ast.Str, ast.Num,
82-
ast.List, ast.Set, ast.Dict, ast.Tuple
83-
)
84-
if PY3:
85-
ast_data += (ast.Bytes,)
86-
if PY34:
87-
ast_data += (ast.NameConstant,)
88-
89-
tree = ast.parse(src)
90-
91-
result = collections.OrderedDict()
92-
93-
for node in ast.iter_child_nodes(tree):
94-
if not isinstance(node, ast.Assign): # We parse assigns only
95-
continue
96-
try:
97-
if isinstance(node.value, ast_data):
98-
value = ast.literal_eval(node.value)
99-
elif isinstance( # NameConstant in python < 3.4
100-
node.value, ast.Name
101-
) and isinstance(
102-
node.value.ctx, ast.Load # Read constant
103-
):
104-
value = ast.literal_eval(node.value)
105-
else:
106-
continue
107-
except ValueError:
108-
continue
109-
for tgt in node.targets:
110-
if isinstance(
111-
tgt, ast.Name
112-
) and isinstance(
113-
tgt.ctx, ast.Store
114-
):
115-
result[tgt.id] = value
116-
return result
117-
118-
119-
variables = get_simple_vars_from_src(source)
16+
import pkg_resources
17+
18+
release = pkg_resources.get_distribution("exec-helpers").version
19+
version = '.'.join(release.split('.')[:2])
20+
12021

12122
# If extensions (or modules to document with autodoc) are in another directory,
12223
# add these directories to sys.path here. If the directory is relative to the
@@ -168,9 +69,8 @@ def get_simple_vars_from_src(src):
16869
# built documents.
16970
#
17071
# The short X.Y version.
171-
version = variables['__version__']
72+
17273
# The full version, including alpha/beta/rc tags.
173-
release = variables['__version__']
17474

17575
# The language for content autogenerated by Sphinx. Refer to documentation
17676
# for a list of supported languages.

exec_helpers/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from __future__ import absolute_import
1818

19+
import pkg_resources
20+
1921
from .proc_enums import ExitCodes
2022

2123
from .exceptions import (
@@ -51,7 +53,17 @@
5153
"ExecResult",
5254
)
5355

54-
__version__ = "1.9.5"
56+
try:
57+
__version__ = pkg_resources.get_distribution(__name__).version
58+
except pkg_resources.DistributionNotFound:
59+
# package is not installed, try to get from SCM
60+
try:
61+
import setuptools_scm # type: ignore
62+
63+
__version__ = setuptools_scm.get_version()
64+
except ImportError:
65+
pass
66+
5567
__author__ = "Alexey Stepanov"
5668
__author_email__ = "penguinolog@gmail.com"
5769
__maintainers__ = {

setup.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ def get_simple_vars_from_src(src):
158158
'{name} <{email}>'.format(name=name, email=email)
159159
for name, email in variables['__maintainers__'].items()
160160
),
161-
url=variables['__url__'],
162-
version=variables['__version__'],
163-
license=variables['__license__'],
164-
description=variables['__description__'],
161+
url=variables["__url__"],
162+
license=variables["__license__"],
163+
description=variables["__description__"],
165164
long_description=long_description,
166165
classifiers=classifiers,
167166
keywords=keywords,
@@ -172,9 +171,13 @@ def get_simple_vars_from_src(src):
172171
# situations as progressive releases of projects are done.
173172
# Blacklist setuptools 34.0.0-34.3.2 due to https://github.com/pypa/setuptools/issues/951
174173
# Blacklist setuptools 36.2.0 due to https://github.com/pypa/setuptools/issues/1086
175-
setup_requires="setuptools >= 21.0.0,!=24.0.0,"
176-
"!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,"
177-
"!=36.2.0",
174+
setup_requires=[
175+
"setuptools >= 21.0.0,!=24.0.0,"
176+
"!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,"
177+
"!=36.2.0",
178+
"setuptools_scm",
179+
],
180+
use_scm_version=True,
178181
install_requires=required,
179182
package_data={
180183
str('exec_helpers'): ['py.typed'],

0 commit comments

Comments
 (0)