Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docbook.py: It's not about the performance, it's about the style. #570

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
38 changes: 20 additions & 18 deletions src/bin/docbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

class JavaClassRunnerException(Exception):
"""Subclass of Exception for errors raised by the runner."""
pass


class JavaClassRunner:
Expand All @@ -29,7 +28,7 @@ class JavaClassRunner:
# Yes, I have a lot of instance attributes. I'm also using camelCase names,
# which aren't the Pythonic way, but they are the POM way. And I know some
# methods could be functions.
# pylint: disable=R0902,C0103,R0201
# pylint: disable=R0902,C0103,W1514

def __init__(self, args):
self.version = "@@VERSION@@"
Expand All @@ -42,7 +41,7 @@ def __init__(self, args):
# docbook-xslTNG package from the distribution environment and
# we seed with its dependencies. These must all be in the
# DocBook distribution (in libs/lib).
self.seeds = set(["@@PACKAGE_LIST@@"])
self.seeds = {"@@PACKAGE_LIST@@"}

self.config = {
"maven-local": str(Path.home()) + "/.m2/repository",
Expand Down Expand Up @@ -158,16 +157,17 @@ def _parse_args(self, args):

if resources is not None:
if resources == "" and not self.output:
self._message(f"Cannot determine output directory; ignoring --resources")
self._message("Cannot determine output directory; ignoring --resources")
else:
if resources == "":
resources = os.path.abspath(self.output)
resources = os.path.abspath(f"{self.output}")
resources = os.path.dirname(resources)
else:
resources = os.path.abspath(resources)
self._configure_resources(resources)

def _help(self):
@staticmethod
def _help():
print(f"""DocBook xslTNG version @@VERSION@@

Usage: {sys.argv[0]} [options]
Expand Down Expand Up @@ -238,7 +238,7 @@ def _configure_resources(self, path):
try:
if not os.path.isdir(fdir):
os.makedirs(fdir)
except:
except OSError:
self._message(f"Failed to create output directory: {path}")
return

Expand All @@ -264,7 +264,8 @@ def _pom(self, groupId, artifactId, version):
except IOError:
return None

def _get_value(self, node, tag):
@staticmethod
def _get_value(node, tag):
for child in node.childNodes:
if child.nodeType == Node.ELEMENT_NODE \
and child.tagName == tag \
Expand All @@ -281,7 +282,8 @@ def _jar(self, groupId, artifactId, version):
return jarfile
return None

def _skip(self, groupId, artifactId, version):
@staticmethod
def _skip(groupId, artifactId, version):
return (groupId is None or "${" in groupId
or artifactId is None or "${" in artifactId
or version is None or "${" in version)
Expand Down Expand Up @@ -311,9 +313,7 @@ def _update_dependencies(self, groupId, artifactId, version):
self._message(f"No jar: {groupId}:{artifactId}:{version}")
return

pkgconfig = {}
pkgconfig["jar"] = jar
pkgconfig["dependencies"] = []
pkgconfig = {"jar": jar, "dependencies": []}
self.depends[groupId][artifactId][version] = pkgconfig

if self._skip(groupId, artifactId, version):
Expand Down Expand Up @@ -367,7 +367,8 @@ def _artifact_dependencies(self, groupId, artifactId, version):

return deps

def _expandProperties(self, value, properties):
@staticmethod
def _expandProperties(value, properties):
for prop in properties:
repl = "${" + prop + "}"
if repl in value:
Expand All @@ -392,7 +393,7 @@ def compute_dependencies(self):
or artifact not in self.depends[group] \
or version not in self.depends[group][artifact] \
or self.depends[group][artifact][version] is None:
found = self._libfallback(package);
found = self._libfallback(package)

if not found:
sys.exit(1)
Expand All @@ -408,7 +409,8 @@ def _libfallback(self, package):
print(f"Required package not found: {group}:{artifact}:{version}; download with Maven")
return False

def _higher_version(self, curver, newver):
@staticmethod
def _higher_version(curver, newver):
if curver == newver:
return False

Expand Down Expand Up @@ -480,8 +482,8 @@ def _add_to_classpath(self, package):
if self._higher_version(curver, version):
usever = version
# Actually remove the current version, we're replacing it.
del self._cp[group][artifact][curver];
del self.depends[group][artifact][curver];
del self._cp[group][artifact][curver]
del self.depends[group][artifact][curver]
else:
usever = curver

Expand Down Expand Up @@ -527,6 +529,7 @@ def classpath(self):
for path in os.environ["CLASSPATH"].split(os.pathsep):
cplist.append(path)

# pylint: disable=C0206
for group in self._cp:
for archive in self._cp[group]:
for version in self._cp[group][archive]:
Expand Down Expand Up @@ -600,7 +603,6 @@ def run(self):

if __name__ == "__main__":
# I'm perfectly happy with the name 'docbook'
# pylint: disable=C0103

try:
docbook = JavaClassRunner(sys.argv[1:])
Expand Down
Loading