Skip to content

Commit

Permalink
Merge pull request #12 from kwozyman/pep8
Browse files Browse the repository at this point in the history
PEP8-ifying
  • Loading branch information
iranzo authored Nov 8, 2024
2 parents 265a0df + e7f8a12 commit 103e7ae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@





node_modules/*
*/__pycache__/*
3 changes: 3 additions & 0 deletions fab/.pep8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pycodestyle]
max_line_length = 120
ignore = E501
12 changes: 7 additions & 5 deletions fab/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
from fab.fab import Fab


class FabCli():
"""
Fab command line
"""

def __init__(self, **kwargs):
self.loglevel = 'info'
self.log_format = '%(asctime)19s - %(levelname)8s - %(message)s'
Expand Down Expand Up @@ -56,7 +58,7 @@ def _cmdargs(self):
import argparse
parser = argparse.ArgumentParser(
description=description
)
)

parser.add_argument('--log-level', '--loglevel',
choices=self.logmap.keys(),
Expand All @@ -73,11 +75,11 @@ def _cmdargs(self):
default=self.log_datefmt,
help='Python Logger() compatible date format str')
parser.add_argument('--container-tool',
help='What container tool to use',
default='/usr/bin/podman')
help='What container tool to use',
default='/usr/bin/podman')
parser.add_argument('--container-tool-extra-args',
help='container tool extra arguments',
default=[])
help='container tool extra arguments',
default=[])

subparsers = parser.add_subparsers(dest='command')
subparsers.required = False
Expand Down
10 changes: 6 additions & 4 deletions fab/fab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import subprocess
from fab.module import FabModule


class Fab:
"""
Fabfile definition
"""

def __init__(self, source, container_tool='/usr/bin/podman', tool_args=[]):
self.source = source
self.name = source
Expand Down Expand Up @@ -37,7 +39,7 @@ def _validate(self):
logging.warning("No name set in fabfile {} metadata. Autosetting to {}".format(self.name, self.name))
self.definition['metadata']['name'] = self.name
else:
self.name = self.definition['metadata']['name']
self.name = self.definition['metadata']['name']
if not 'description' in self.definition['metadata']:
logging.warning("No description set in fabfile {} metadata. Autosetting".format(self.name))
self.definition['metadata']['description'] = 'Autogenerated'
Expand All @@ -57,7 +59,7 @@ def _validate(self):
else:
self.definition['buildargs'] = []

return(is_valid)
return (is_valid)

def _load_includes(self):
for include in self.definition['include']:
Expand Down Expand Up @@ -93,8 +95,8 @@ def build(self):
print(len(self.includes))
for module in self.includes:
tag = '{}-stage-{}'.format(
self.name,
module.name)
self.name,
module.name)
podman_args = []
podman_args.append(self.tool_args)
podman_args.append('build')
Expand Down
10 changes: 6 additions & 4 deletions fab/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import urllib.parse
import pathlib


class FabModule():
"""
Definition of a generic Fab module
"""

def __init__(self, source, **kwargs):
self.source = source
self.name = self.source
Expand All @@ -21,8 +23,8 @@ def __init__(self, source, **kwargs):
raise Exception("YAML is not valid")

def __str__(self):
return(pprint.pformat(self.definition, indent=4))
return (pprint.pformat(self.definition, indent=4))

def _read(self):
parsed_source = urllib.parse.urlparse(self.source)
logging.debug('Decoded source: {}'.format(parsed_source))
Expand Down Expand Up @@ -56,7 +58,7 @@ def _validate(self):
if not 'description' in self.definition['metadata']:
logging.warning("No description set in module {}'s metadata. Autosetting".format(self.name))
self.definition['metadata']['description'] = 'Autogenerated'

if not 'containerfile' in self.definition:
logging.debug("'containerfile' missing from definition yaml for module {}, using default".format(self.name))
self.definition['containerfile'] = 'Containerfile'
Expand All @@ -72,4 +74,4 @@ def _validate(self):
else:
self.definition['buildargs'] = []

return(is_valid)
return (is_valid)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyyaml
configargparse
pyyaml

0 comments on commit 103e7ae

Please sign in to comment.