Skip to content

Commit

Permalink
Bump to 2.1.0 (#85)
Browse files Browse the repository at this point in the history
* API changes: async calls
* Code style changed
* Docs and types explanations fixed
* Require `threaded>=2.0` as properly typed
  • Loading branch information
penguinolog committed Sep 21, 2018
1 parent 0d3d16c commit d478c4f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 107 deletions.
2 changes: 1 addition & 1 deletion exec_helpers/__init__.py
Expand Up @@ -49,7 +49,7 @@
"ExecResult",
)

__version__ = "2.0.2"
__version__ = "2.1.0"
__author__ = "Alexey Stepanov"
__author_email__ = "penguinolog@gmail.com"
__maintainers__ = {
Expand Down
14 changes: 7 additions & 7 deletions exec_helpers/_ssh_client_base.py
Expand Up @@ -359,8 +359,8 @@ def __repr__(self) -> str:

def __str__(self) -> str: # pragma: no cover
"""Representation for debug purposes."""
return "{cls}(host={self.hostname}, port={self.port}) for user {self.auth.username}".format(
cls=self.__class__.__name__, self=self
return "{cls}(host={self.hostname}, port={self.port}) for user {username}".format(
cls=self.__class__.__name__, self=self, username=self.auth.username
)

@property
Expand Down Expand Up @@ -827,13 +827,13 @@ def get_result(remote: "SSHClientBase") -> exec_result.ExecResult:
cmd_for_log = remote._mask_command(cmd=command, log_mask_re=kwargs.get("log_mask_re", None))
# pylint: enable=protected-access

result = exec_result.ExecResult(cmd=cmd_for_log)
result.read_stdout(src=async_result.stdout)
result.read_stderr(src=async_result.stderr)
result.exit_code = exit_code
res = exec_result.ExecResult(cmd=cmd_for_log)
res.read_stdout(src=async_result.stdout)
res.read_stderr(src=async_result.stderr)
res.exit_code = exit_code

async_result.interface.close()
return result
return res

expected = expected or [proc_enums.ExitCodes.EX_OK]
expected = proc_enums.exit_codes_to_enums(expected)
Expand Down
1 change: 1 addition & 0 deletions exec_helpers/api.py
Expand Up @@ -122,6 +122,7 @@ def mask(text: str, rules: str) -> str:
end = indexes[idx + 1]
masked += text[start:end] + "<*masked*>"

# noinspection PyPep8
masked += text[indexes[-2] : indexes[-1]] # final part
return masked

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,7 +1,7 @@
paramiko>=2.4 # LGPLv2.1+
tenacity>=4.4.0 # Apache-2.0
six>=1.10.0 # MIT
threaded>=1.0 # Apache-2.0
threaded>=2.0 # Apache-2.0
PyYAML>=3.12 # MIT
advanced-descriptors>=1.0 # Apache-2.0
typing >= 3.6 ; python_version < "3.8"
162 changes: 65 additions & 97 deletions setup.py
Expand Up @@ -30,65 +30,61 @@
import sys

try:
# noinspection PyPackageRequirements
from Cython.Build import cythonize
except ImportError:
cythonize = None

import setuptools

with open(
os.path.join(
os.path.dirname(__file__),
'exec_helpers', '__init__.py'
)
) as f:
with open(os.path.join(os.path.dirname(__file__), "exec_helpers", "__init__.py")) as f:
source = f.read()

with open('requirements.txt') as f:
with open("requirements.txt") as f:
required = f.read().splitlines()

with open('README.rst',) as f:
with open("README.rst") as f:
long_description = f.read()


def _extension(modpath):
"""Make setuptools.Extension."""
source_path = modpath.replace('.', '/') + '.py'
source_path = modpath.replace(".", "/") + ".py"
return setuptools.Extension(modpath, [source_path])


requires_optimization = [
_extension('exec_helpers.api'),
_extension('exec_helpers.constants'),
_extension('exec_helpers._log_templates'),
_extension('exec_helpers.exceptions'),
_extension('exec_helpers.exec_result'),
_extension('exec_helpers.proc_enums'),
_extension('exec_helpers._ssh_client_base'),
_extension('exec_helpers.ssh_auth'),
_extension('exec_helpers.ssh_client'),
_extension('exec_helpers.subprocess_runner'),
_extension("exec_helpers.api"),
_extension("exec_helpers.constants"),
_extension("exec_helpers._log_templates"),
_extension("exec_helpers.exceptions"),
_extension("exec_helpers.exec_result"),
_extension("exec_helpers.proc_enums"),
_extension("exec_helpers._ssh_client_base"),
_extension("exec_helpers.ssh_auth"),
_extension("exec_helpers.ssh_client"),
_extension("exec_helpers.subprocess_runner"),
]

if 'win32' != sys.platform:
requires_optimization.append(
_extension('exec_helpers.__init__')
)
if "win32" != sys.platform:
requires_optimization.append(_extension("exec_helpers.__init__"))

ext_modules = cythonize(
requires_optimization,
compiler_directives=dict(
always_allow_keywords=True,
binding=True,
embedsignature=True,
overflowcheck=True,
language_level=3,
# noinspection PyCallingNonCallable
ext_modules = (
cythonize(
requires_optimization,
compiler_directives=dict(
always_allow_keywords=True, binding=True, embedsignature=True, overflowcheck=True, language_level=3
),
)
) if cythonize is not None else []
if cythonize is not None
else []
)


class BuildFailed(Exception):
"""For install clear scripts."""

pass


Expand All @@ -102,12 +98,10 @@ def run(self):

# Copy __init__.py back to repair package.
build_dir = os.path.abspath(self.build_lib)
root_dir = os.path.abspath(os.path.join(__file__, '..'))
root_dir = os.path.abspath(os.path.join(__file__, ".."))
target_dir = build_dir if not self.inplace else root_dir

src_files = (
os.path.join('exec_helpers', '__init__.py'),
)
src_files = (os.path.join("exec_helpers", "__init__.py"),)

for src_file in src_files:
src = os.path.join(root_dir, src_file)
Expand All @@ -117,7 +111,7 @@ def run(self):
shutil.copyfile(src, dst)
except (
distutils.errors.DistutilsPlatformError,
getattr(globals()['__builtins__'], 'FileNotFoundError', OSError)
getattr(globals()["__builtins__"], "FileNotFoundError", OSError),
):
raise BuildFailed()

Expand All @@ -129,7 +123,7 @@ def build_extension(self, ext):
distutils.errors.CCompilerError,
distutils.errors.DistutilsExecError,
distutils.errors.DistutilsPlatformError,
ValueError
ValueError,
):
raise BuildFailed()

Expand Down Expand Up @@ -181,11 +175,7 @@ def get_simple_vars_from_src(src):
>>> get_simple_vars_from_src(multiple_assign)
OrderedDict([('e', 1), ('f', 1), ('g', 1)])
"""
ast_data = (
ast.Str, ast.Num,
ast.List, ast.Set, ast.Dict, ast.Tuple,
ast.Bytes, ast.NameConstant,
)
ast_data = (ast.Str, ast.Num, ast.List, ast.Set, ast.Dict, ast.Tuple, ast.Bytes, ast.NameConstant)

tree = ast.parse(src)

Expand All @@ -197,9 +187,7 @@ def get_simple_vars_from_src(src):
try:
if isinstance(node.value, ast_data):
value = ast.literal_eval(node.value)
elif isinstance( # NameConstant in python < 3.4
node.value, ast.Name
) and isinstance(
elif isinstance(node.value, ast.Name) and isinstance( # NameConstant in python < 3.4
node.value.ctx, ast.Load # Read constant
):
value = ast.literal_eval(node.value)
Expand All @@ -208,84 +196,64 @@ def get_simple_vars_from_src(src):
except ValueError:
continue
for tgt in node.targets:
if isinstance(
tgt, ast.Name
) and isinstance(
tgt.ctx, ast.Store
):
if isinstance(tgt, ast.Name) and isinstance(tgt.ctx, ast.Store):
result[tgt.id] = value
return result


variables = get_simple_vars_from_src(source)

classifiers = [
'Development Status :: 5 - Production/Stable',

'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',

'License :: OSI Approved :: Apache Software License',

'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',

'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

keywords = [
'logging',
'debugging',
'development',
]
keywords = ["logging", "debugging", "development"]

setup_args = dict(
name='exec-helpers',
author=variables['__author__'],
author_email=variables['__author_email__'],
maintainer=', '.join(
'{name} <{email}>'.format(name=name, email=email)
for name, email in variables['__maintainers__'].items()
name="exec-helpers",
author=variables["__author__"],
author_email=variables["__author_email__"],
maintainer=", ".join(
"{name} <{email}>".format(name=name, email=email) for name, email in variables["__maintainers__"].items()
),
url=variables['__url__'],
version=variables['__version__'],
license=variables['__license__'],
description=variables['__description__'],
url=variables["__url__"],
version=variables["__version__"],
license=variables["__license__"],
description=variables["__description__"],
long_description=long_description,
classifiers=classifiers,
keywords=keywords,
python_requires='>=3.4',
python_requires=">=3.4",
# While setuptools cannot deal with pre-installed incompatible versions,
# setting a lower bound is not harmful - it makes error messages cleaner. DO
# NOT set an upper bound on setuptools, as that will lead to uninstallable
# situations as progressive releases of projects are done.
# Blacklist setuptools 34.0.0-34.3.2 due to https://github.com/pypa/setuptools/issues/951
# Blacklist setuptools 36.2.0 due to https://github.com/pypa/setuptools/issues/1086
setup_requires="setuptools >= 21.0.0,!=24.0.0,"
"!=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,"
"!=36.2.0",
"!=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,"
"!=36.2.0",
install_requires=required,
package_data={
'exec_helpers': ['py.typed'],
},
package_data={"exec_helpers": ["py.typed"]},
)
if cythonize is not None:
setup_args['ext_modules'] = ext_modules
setup_args['cmdclass'] = dict(build_ext=AllowFailRepair)
setup_args["ext_modules"] = ext_modules
setup_args["cmdclass"] = dict(build_ext=AllowFailRepair)

try:
setuptools.setup(**setup_args)
except BuildFailed:
print(
'*' * 80 + '\n'
'* Build Failed!\n'
'* Use clear scripts version.\n'
'*' * 80 + '\n'
)
del setup_args['ext_modules']
del setup_args['cmdclass']
print("*" * 80 + "\n" "* Build Failed!\n" "* Use clear scripts version.\n" "*" * 80 + "\n")
del setup_args["ext_modules"]
del setup_args["cmdclass"]
setuptools.setup(**setup_args)
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -5,7 +5,7 @@

[tox]
minversion = 2.0
envlist = pep8, pylint, mypy, bandit, pep257, py{34,35,36,37,py3}, docs, py{34,35,36,37}-nocov
envlist = black, pep8, pylint, mypy, bandit, pep257, py{34,35,36,37,py3}, docs, py{34,35,36,37}-nocov
skipsdist = True
skip_missing_interpreters = True

Expand Down

0 comments on commit d478c4f

Please sign in to comment.