1616
1717"""Execution helpers for simplified usage of subprocess and ssh."""
1818
19- from __future__ import absolute_import
20- from __future__ import division
21- from __future__ import print_function
22- from __future__ import unicode_literals
23-
2419# Standard Library
2520import ast
26- import collections
2721import distutils .errors
2822import os .path
2923import shutil
3327# External Dependencies
3428import setuptools
3529
30+ try :
31+ import typing
32+ except ImportError :
33+ typing = None
34+
35+
3636try :
3737 # noinspection PyPackageRequirements
3838 from Cython .Build import cythonize
3939except ImportError :
4040 cythonize = None
4141
42- with open (os .path .join (os .path .dirname (__file__ ), "exec_helpers" , "__init__.py" )) as f :
42+
43+ PACKAGE_NAME = "exec_helpers"
44+
45+ with open (os .path .join (os .path .dirname (__file__ ), PACKAGE_NAME , "__init__.py" )) as f :
4346 SOURCE = f .read ()
4447
4548with open ("requirements.txt" ) as f :
@@ -111,14 +114,13 @@ def run(self):
111114 root_dir = os .path .abspath (os .path .join (__file__ , ".." ))
112115 target_dir = build_dir if not self .inplace else root_dir
113116
114- src_files = ( os .path .join ("exec_helpers" , "__init__.py" ), )
117+ src_file = os .path .join (PACKAGE_NAME , "__init__.py" )
115118
116- for src_file in src_files :
117- src = os .path .join (root_dir , src_file )
118- dst = os .path .join (target_dir , src_file )
119+ src = os .path .join (root_dir , src_file )
120+ dst = os .path .join (target_dir , src_file )
119121
120- if src != dst :
121- shutil .copyfile (src , dst )
122+ if src != dst :
123+ shutil .copyfile (src , dst )
122124 except (
123125 distutils .errors .DistutilsPlatformError ,
124126 getattr (globals ()["__builtins__" ], "FileNotFoundError" , OSError ),
@@ -142,7 +144,9 @@ def build_extension(self, ext):
142144
143145
144146# noinspection PyUnresolvedReferences
145- def get_simple_vars_from_src (src ):
147+ def get_simple_vars_from_src (
148+ src : str
149+ ) -> "typing.Dict[str, typing.Union[str, bytes, int, float, complex, list, set, dict, tuple, None, bool, Ellipsis]]" :
146150 """Get simple (string/number/boolean and None) assigned values from source.
147151
148152 :param src: Source code
@@ -167,26 +171,24 @@ def get_simple_vars_from_src(src):
167171
168172 >>> string_sample = "a = '1'"
169173 >>> get_simple_vars_from_src(string_sample)
170- OrderedDict([( 'a', '1')])
174+ { 'a': '1'}
171175
172176 >>> int_sample = "b = 1"
173177 >>> get_simple_vars_from_src(int_sample)
174- OrderedDict([( 'b', 1)])
178+ { 'b': 1}
175179
176180 >>> list_sample = "c = [u'1', b'1', 1, 1.0, 1j, None]"
177181 >>> result = get_simple_vars_from_src(list_sample)
178- >>> result == collections.OrderedDict(
179- ... [('c', [u'1', b'1', 1, 1.0, 1j, None])]
180- ... )
182+ >>> result == {'c': [u'1', b'1', 1, 1.0, 1j, None]}
181183 True
182184
183185 >>> iterable_sample = "d = ([1], {1: 1}, {1})"
184186 >>> get_simple_vars_from_src(iterable_sample)
185- OrderedDict([( 'd', ([1], {1: 1}, {1}))])
187+ { 'd': ([1], {1: 1}, {1})}
186188
187189 >>> multiple_assign = "e = f = g = 1"
188190 >>> get_simple_vars_from_src(multiple_assign)
189- OrderedDict([( 'e', 1), ( 'f', 1), ( 'g', 1)])
191+ { 'e': 1, 'f': 1, 'g': 1}
190192 """
191193 if sys .version_info [:2 ] < (3 , 8 ):
192194 ast_data = (ast .Str , ast .Num , ast .List , ast .Set , ast .Dict , ast .Tuple , ast .Bytes , ast .NameConstant , ast .Ellipsis )
@@ -195,7 +197,7 @@ def get_simple_vars_from_src(src):
195197
196198 tree = ast .parse (src )
197199
198- result = collections . OrderedDict ()
200+ result = {}
199201
200202 for node in ast .iter_child_nodes (tree ):
201203 if not isinstance (node , ast .Assign ): # We parse assigns only
@@ -247,7 +249,7 @@ def get_simple_vars_from_src(src):
247249 long_description = LONG_DESCRIPTION ,
248250 classifiers = CLASSIFIERS ,
249251 keywords = KEYWORDS ,
250- python_requires = ">=3.6" ,
252+ python_requires = ">=3.6.0 " ,
251253 # While setuptools cannot deal with pre-installed incompatible versions,
252254 # setting a lower bound is not harmful - it makes error messages cleaner. DO
253255 # NOT set an upper bound on setuptools, as that will lead to uninstallable
@@ -269,7 +271,7 @@ def get_simple_vars_from_src(src):
269271 "all_formats" : XML_DEPS + LXML_DEPS + YAML_DEPS ,
270272 "all-formats" : XML_DEPS + LXML_DEPS + YAML_DEPS ,
271273 },
272- package_data = {"exec_helpers" : ["py.typed" ]},
274+ package_data = {PACKAGE_NAME : ["py.typed" ]},
273275)
274276if cythonize is not None :
275277 SETUP_ARGS ["ext_modules" ] = EXT_MODULES
0 commit comments