Skip to content

Commit cd77add

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>
1 parent 59b7999 commit cd77add

File tree

4 files changed

+28
-113
lines changed

4 files changed

+28
-113
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
@@ -14,6 +14,8 @@
1414

1515
"""Execution helpers for simplified usage of subprocess and ssh."""
1616

17+
import pkg_resources
18+
1719
from .proc_enums import ExitCodes
1820

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

54-
__version__ = "3.1.3"
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__ = {

exec_helpers/_ssh_client_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class RetryOnExceptions(tenacity.retry_if_exception): # type: ignore
5353

5454
def __init__(
5555
self,
56-
retry_on: typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException], ...]],
57-
reraise: typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException], ...]],
56+
retry_on: "typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException], ...]]",
57+
reraise: "typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException], ...]]",
5858
) -> None:
5959
"""Retry on exceptions, except several types."""
6060
super(RetryOnExceptions, self).__init__(lambda e: isinstance(e, retry_on) and not isinstance(e, reraise))

setup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ def get_simple_vars_from_src(src):
235235
"{name} <{email}>".format(name=name, email=email) for name, email in variables["__maintainers__"].items()
236236
),
237237
url=variables["__url__"],
238-
version=variables["__version__"],
239238
license=variables["__license__"],
240239
description=variables["__description__"],
241240
long_description=long_description,
@@ -248,9 +247,13 @@ def get_simple_vars_from_src(src):
248247
# situations as progressive releases of projects are done.
249248
# Blacklist setuptools 34.0.0-34.3.2 due to https://github.com/pypa/setuptools/issues/951
250249
# Blacklist setuptools 36.2.0 due to https://github.com/pypa/setuptools/issues/1086
251-
setup_requires="setuptools >= 21.0.0,!=24.0.0,"
252-
"!=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,"
253-
"!=36.2.0",
250+
setup_requires=[
251+
"setuptools >= 21.0.0,!=24.0.0,"
252+
"!=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,"
253+
"!=36.2.0",
254+
"setuptools_scm",
255+
],
256+
use_scm_version=True,
254257
install_requires=required,
255258
package_data={"exec_helpers": ["py.typed"]},
256259
)

0 commit comments

Comments
 (0)