Skip to content

Commit 7edfb84

Browse files
committed
Add workflow to run tox jobs
1 parent f69008d commit 7edfb84

File tree

7 files changed

+151
-41
lines changed

7 files changed

+151
-41
lines changed

.coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
branch = True
3+
source = tcib
4+
omit = tcib/tests/*
5+
6+
[report]
7+
ignore_errors = True

.github/workflows/toxjobs.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run tox jobs
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
tox:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ['3.9']
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install tox
22+
- name: Run lint jobs
23+
run: tox -e linters
24+
- name: Run unit tests
25+
run: tox -e py3

.pre-commit-config.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v3.4.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: mixed-line-ending
8+
- id: check-byte-order-marker
9+
- id: check-executables-have-shebangs
10+
- id: check-merge-conflict
11+
- id: debug-statements
12+
- id: check-yaml
13+
files: .*\.(yaml|yml)$
14+
- repo: https://github.com/pycqa/flake8.git
15+
rev: 3.9.0
16+
hooks:
17+
- id: flake8
18+
- repo: https://github.com/openstack-dev/bashate.git
19+
rev: 2.0.0
20+
hooks:
21+
- id: bashate
22+
entry: bashate --error . --ignore=E006,E040,E042
23+
# Run bashate check for all bash scripts
24+
# Ignores the following rules:
25+
# E006: Line longer than 79 columns (as many scripts use jinja
26+
# templating, this is very difficult)
27+
# E040: Syntax error determined using `bash -n` (as many scripts
28+
# use jinja templating, this will often fail and the syntax
29+
# error will be discovered in execution anyway)
30+
- repo: https://github.com/PyCQA/pylint
31+
rev: pylint-2.7.2
32+
hooks:
33+
- id: pylint

.pylintrc

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[MESSAGES CONTROL]
2+
3+
disable =
4+
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
5+
arguments-differ,
6+
attribute-defined-outside-init,
7+
broad-except,
8+
consider-iterating-dictionary,
9+
consider-merging-isinstance,
10+
consider-using-dict-comprehension,
11+
consider-using-in,
12+
consider-using-set-comprehension,
13+
dangerous-default-value,
14+
duplicate-code,
15+
fixme,
16+
global-statement,
17+
import-error,
18+
inconsistent-return-statements,
19+
invalid-name,
20+
missing-class-docstring,
21+
missing-function-docstring,
22+
missing-module-docstring,
23+
no-self-use,
24+
no-value-for-parameter,
25+
protected-access,
26+
raise-missing-from,
27+
redefined-argument-from-local,
28+
redefined-builtin,
29+
redefined-outer-name,
30+
super-init-not-called,
31+
super-with-arguments,
32+
superfluous-parens,
33+
too-few-public-methods,
34+
too-many-ancestors,
35+
too-many-arguments,
36+
too-many-branches,
37+
too-many-instance-attributes,
38+
too-many-lines,
39+
too-many-locals,
40+
too-many-nested-blocks,
41+
too-many-public-methods,
42+
too-many-statements,
43+
unidiomatic-typecheck,
44+
unnecessary-comprehension,
45+
unnecessary-pass,
46+
unsubscriptable-object,
47+
unused-argument,
48+
unused-variable,
49+
useless-else-on-loop,
50+
useless-object-inheritance,
51+
useless-super-delegation,
52+
wrong-import-order,
53+
wrong-import-position
54+
55+
[REPORTS]
56+
output-format = colorized

tcib/client/container_image.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
if sys.prefix != "/usr" and not os.path.isdir(CONTAINER_IMAGES_BASE_PATH):
4848
CONTAINER_IMAGES_BASE_PATH = os.path.join(
4949
"/usr", "share", "tcib", "container-images")
50-
CONTAINER_IMAGES_BASE_PATH = os.environ.get("TCIB_CONFIG_PATH", CONTAINER_IMAGES_BASE_PATH)
50+
CONTAINER_IMAGES_BASE_PATH = os.environ.get(
51+
"TCIB_CONFIG_PATH", CONTAINER_IMAGES_BASE_PATH)
5152

5253

5354
class Build(command.Command):
@@ -688,9 +689,8 @@ def take_action(self, parsed_args):
688689
"The file provided by <options-apply> does not "
689690
"exist, check you settings and try again."
690691
)
691-
else:
692-
with open(parsed_args.extra_config) as f:
693-
generation_playbook["vars"] = yaml.safe_load(f)
692+
with open(parsed_args.extra_config) as f:
693+
generation_playbook["vars"] = yaml.safe_load(f)
694694

695695
playdata.append(generation_playbook)
696696

tcib/client/utils.py

+26-36
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def __exit__(self, *args):
110110
if self.cleanup:
111111
self.clean()
112112
else:
113-
LOG.warning("Not cleaning temporary directory [ %s ]" % self.dir)
113+
LOG.warning("Not cleaning temporary directory [ %s ]", self.dir)
114114

115115
def clean(self):
116116
shutil.rmtree(self.dir, ignore_errors=True)
117-
LOG.info("Temporary directory [ %s ] cleaned up" % self.dir)
117+
LOG.info("Temporary directory [ %s ] cleaned up", self.dir)
118118

119119

120120
def _encode_envvars(env):
@@ -124,8 +124,7 @@ def _encode_envvars(env):
124124
"""
125125
for key, value in env.items():
126126
env[key] = str(value)
127-
else:
128-
return env
127+
return env
129128

130129

131130
def makedirs(dir_path):
@@ -139,15 +138,13 @@ def makedirs(dir_path):
139138
os.makedirs(dir_path)
140139
except FileExistsError:
141140
LOG.debug(
142-
'Directory "{}" was not created because it'
143-
' already exists.'.format(
144-
dir_path
145-
)
141+
'Directory "%s" was not created because it already exists.',
142+
dir_path
146143
)
147144
return False
148-
else:
149-
LOG.debug('Directory "{}" was created.'.format(dir_path))
150-
return True
145+
146+
LOG.debug('Directory "%s" was created.', dir_path)
147+
return True
151148

152149

153150
def playbook_verbosity(self):
@@ -244,7 +241,7 @@ def _playbook_check(play):
244241
play = os.path.join(playbook_dir, play)
245242
if not os.path.exists(play):
246243
raise RuntimeError('No such playbook: {}'.format(play))
247-
LOG.debug('Ansible playbook {} found'.format(play))
244+
LOG.debug('Ansible playbook %s found', play)
248245
return play
249246

250247
def _inventory(inventory):
@@ -267,9 +264,9 @@ def _inventory(inventory):
267264

268265
def _running_ansible_msg(playbook, timeout=None):
269266
if timeout and timeout > 0:
270-
return ('Running Ansible playbook with timeout %sm: %s,' %
267+
return ('Running Ansible playbook with timeout %sm: %s' %
271268
(timeout, playbook))
272-
return ('Running Ansible playbook: %s,' % playbook)
269+
return ('Running Ansible playbook: %s' % playbook)
273270

274271
if not playbook_dir:
275272
playbook_dir = workdir
@@ -308,31 +305,27 @@ def _running_ansible_msg(playbook, timeout=None):
308305
)
309306

310307
LOG.info(
311-
_running_ansible_msg(playbook, timeout) +
312-
' multi-playbook execution: {}'
313-
' Working directory: {},'
314-
' Playbook directory: {}'.format(
315-
verified_playbooks,
316-
workdir,
317-
playbook_dir
318-
)
308+
'%s,'
309+
' multi-playbook execution: %s,'
310+
' Working directory: %s,'
311+
' Playbook directory: %s',
312+
_running_ansible_msg(playbook, timeout),
313+
verified_playbooks,
314+
workdir,
315+
playbook_dir
319316
)
320317
else:
321318
playbook = _playbook_check(play=playbook)
322319
LOG.info(
323-
_running_ansible_msg(playbook, timeout) +
324-
' Working directory: {},'
325-
' Playbook directory: {}'.format(
326-
workdir,
327-
playbook_dir
328-
)
320+
'%s, Working directory: %s, Playbook directory: %s',
321+
_running_ansible_msg(playbook, timeout),
322+
workdir,
323+
playbook_dir
329324
)
330325

331326
if limit_hosts:
332327
LOG.info(
333-
'Running ansible with the following limit: {}'.format(
334-
limit_hosts
335-
)
328+
'Running ansible with the following limit: %s', limit_hosts
336329
)
337330
ansible_fact_path = os.path.join(
338331
os.path.expanduser('~'),
@@ -441,8 +434,7 @@ def _running_ansible_msg(playbook, timeout=None):
441434
msg = "extra_env_variables must be a dict"
442435
LOG.error(msg)
443436
raise SystemError(msg)
444-
else:
445-
env.update(extra_env_variables)
437+
env.update(extra_env_variables)
446438

447439
if 'ANSIBLE_CONFIG' not in env and not ansible_cfg:
448440
ansible_cfg = os.path.join(workdir, 'ansible.cfg')
@@ -554,6 +546,4 @@ def _running_ansible_msg(playbook, timeout=None):
554546

555547
raise RuntimeError(err_msg)
556548

557-
LOG.info(
558-
'Ansible execution success. playbook: {}'.format(
559-
playbook))
549+
LOG.info('Ansible execution success. playbook: %s', playbook)

tox.ini

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ allowlist_externals =
3737
commands = {posargs}
3838

3939
[testenv:linters]
40-
basepython=python39
4140
deps =
4241
virtualenv>=20.0.20
4342
pre-commit>=2.4.0

0 commit comments

Comments
 (0)