[SEBA-412] Automated reformat of Python code
Passes of modernize, autopep8, black, then check with flake8
flake8 + manual fixes:
lib/xos-config
lib/xos-kafka
lib/xos-util
xos/coreapi
xos/api
xos/xos_client
Change-Id: Ib23cf84cb13beb3c6381fa0d79594dc9131dc815
diff --git a/lib/xos-util/xosutil/__init__.py b/lib/xos-util/xosutil/__init__.py
index 42722a8..b0fb0b2 100644
--- a/lib/xos-util/xosutil/__init__.py
+++ b/lib/xos-util/xosutil/__init__.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/xos-util/xosutil/autodiscover_version.py b/lib/xos-util/xosutil/autodiscover_version.py
index 2e606e1..8f4ea47 100644
--- a/lib/xos-util/xosutil/autodiscover_version.py
+++ b/lib/xos-util/xosutil/autodiscover_version.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +23,7 @@
import inspect
import os
+
def autodiscover_version(caller_filename=None, save_to=None, max_parent_depth=None):
""" walk back along the path to the current module, searching for a VERSION file """
if not caller_filename:
@@ -42,8 +42,8 @@
return version
# limit_parent_depth can be used to limit how far back we search the tree for a VERSION file.
- if (max_parent_depth is not None):
- if (max_parent_depth <= 0):
+ if max_parent_depth is not None:
+ if max_parent_depth <= 0:
return None
max_parent_depth -= 1
@@ -51,13 +51,16 @@
if not remainder:
return None
+
def autodiscover_version_of_caller(*args, **kwargs):
frame = inspect.stack()[1]
module = inspect.getmodule(frame[0])
return autodiscover_version(module.__file__, *args, **kwargs)
+
def autodiscover_version_of_main(*args, **kwargs):
import __main__
+
if hasattr(__main__, "__file__"):
return autodiscover_version(__main__.__file__, *args, **kwargs)
else:
diff --git a/lib/xos-util/xosutil/autoversion_setup.py b/lib/xos-util/xosutil/autoversion_setup.py
index 5a7ea44..e027d5c 100644
--- a/lib/xos-util/xosutil/autoversion_setup.py
+++ b/lib/xos-util/xosutil/autoversion_setup.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,42 +32,47 @@
import inspect
from autodiscover_version import autodiscover_version
+
class SdistCommand(sdist):
def copy_file(self, infile, outfile, *args, **kwargs):
if kwargs.get("dry_run"):
return (outfile, 1)
- if (os.path.split(outfile)[1] == "version.py"):
- open(outfile, "w").write("# do not edit. Autogenerated file.\n" \
- "__version__ = '%s'\n" % self.distribution.metadata.version)
+ if os.path.split(outfile)[1] == "version.py":
+ open(outfile, "w").write(
+ "# do not edit. Autogenerated file.\n"
+ "__version__ = '%s'\n" % self.distribution.metadata.version
+ )
return (outfile, 1)
else:
return sdist.copy_file(self, infile, outfile, *args, **kwargs)
+
class BuildPyCommand(build_py):
def copy_file(self, infile, outfile, *args, **kwargs):
if kwargs.get("dry_run"):
return (outfile, 1)
- if (os.path.split(outfile)[1] == "version.py"):
- open(outfile, "w").write("# do not edit. Autogenerated file.\n" \
- "__version__ = '%s'\n" % self.distribution.metadata.version)
+ if os.path.split(outfile)[1] == "version.py":
+ open(outfile, "w").write(
+ "# do not edit. Autogenerated file.\n"
+ "__version__ = '%s'\n" % self.distribution.metadata.version
+ )
return (outfile, 1)
else:
return build_py.copy_file(self, infile, outfile, *args, **kwargs)
+
def setup_with_auto_version(*args, **kwargs):
# Learn the module that called this function, so we can search for any VERSION files in it.
frame = inspect.stack()[1]
caller_module = inspect.getmodule(frame[0])
# Search for a VERSION file and extract the version number from it.
- version = autodiscover_version(caller_filename = caller_module.__file__)
+ version = autodiscover_version(caller_filename=caller_module.__file__)
if version:
kwargs["version"] = version
cmdclass = kwargs.get("cmdclass", {}).copy()
- cmdclass.update( {"sdist": SdistCommand,
- "build_py": BuildPyCommand} )
+ cmdclass.update({"sdist": SdistCommand, "build_py": BuildPyCommand})
kwargs["cmdclass"] = cmdclass
return setup(*args, **kwargs)
-
diff --git a/lib/xos-util/xosutil/version.py b/lib/xos-util/xosutil/version.py
index 57833b8..8456fc5 100644
--- a/lib/xos-util/xosutil/version.py
+++ b/lib/xos-util/xosutil/version.py
@@ -13,4 +13,4 @@
# limitations under the License.
# This file is autogenerated. Do not edit.
-__version__ = 'unknown'
+__version__ = "unknown"