Skip to content

Commit

Permalink
add poetry (#5)
Browse files Browse the repository at this point in the history
* add poetry

- configure flake8
- make flake8 happy
- add constraint for python>=3.9

* adjust flake8 for tests dir

* fix pytest call

* fix script config in poetry

* test app in python matrix

* fix typo

* fix indentation in cli.py

* improve pylint result
  • Loading branch information
russoz authored Jun 5, 2023
1 parent 380b5b6 commit f4a9bb7
Show file tree
Hide file tree
Showing 10 changed files with 1,094 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 160
extend-ignore = E203
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,.tox
max-complexity = 10

20 changes: 11 additions & 9 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,28 @@ permissions:

jobs:
build:

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-mock
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install poetry
poetry install
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 -v . --count --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
poetry run flake8 -v . --count --exit-zero --statistics
- name: Test with pytest
run: |
pytest
poetry run pytest -v
24 changes: 16 additions & 8 deletions andeboxlib/actions/ignorefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,33 @@ class IgnoreLinesAction(AndeboxAction):
help = "gathers stats on ignore*.txt file(s)"
args = [
dict(names=["--ignore-file-spec", "-ifs"],
specs=dict(choices=_ignore_versions + ["-"],
specs=dict(choices=_ignore_versions + ["-"],
help=(
"Use the ignore file matching this Ansible version. "
"The special value '-' may be specified to read "
"from stdin instead. If not specified, will use all available files. "
"If no choices are presented, the collection structure was not recognized."))),
dict(names=["--depth", "-d"],
specs=dict(type=int, help="Path depth for grouping files")),
specs=dict(type=int,
help="Path depth for grouping files")),
dict(names=["--filter-files", "-ff"],
specs=dict(type=re.compile, help="Regexp matching file names to be included")),
specs=dict(type=re.compile,
help="Regexp matching file names to be included")),
dict(names=["--filter-checks", "-fc"],
specs=dict(type=re.compile, help="Regexp matching checks in ignore files to be included")),
specs=dict(type=re.compile,
help="Regexp matching checks in ignore files to be included")),
dict(names=["--suppress-files", "-sf"],
specs=dict(action="store_true", help="Supress file names from the output, consolidating the results")),
specs=dict(action="store_true",
help="Supress file names from the output, consolidating the results")),
dict(names=["--suppress-checks", "-sc"],
specs=dict(action="store_true", help="Suppress the checks from the output, consolidating the results")),
specs=dict(action="store_true",
help="Suppress the checks from the output, consolidating the results")),
dict(names=["--head", "-H"],
specs=dict(type=int, default=10, help="Number of lines to display in the output: leading lines if "
"positive, trailing lines if negative, all lines if zero.")),
specs=dict(type=int,
default=10,
help=(
"Number of lines to display in the output: leading lines if "
"positive, trailing lines if negative, all lines if zero."))),
]

# pylint: disable=consider-using-with
Expand Down
14 changes: 8 additions & 6 deletions andeboxlib/actions/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ def run(self, args):

try:
print("\n")
with Connection(user=v.user(vm_name=machine_name),
host=v.hostname(vm_name=machine_name),
port=v.port(vm_name=machine_name),
connect_kwargs={
"key_filename": v.keyfile(vm_name=machine_name),
},) as c:
with Connection(
user=v.user(vm_name=machine_name),
host=v.hostname(vm_name=machine_name),
port=v.port(vm_name=machine_name),
connect_kwargs={
"key_filename": v.keyfile(vm_name=machine_name),
},
) as c:

print(f"== BEGIN vagrant andebox: {machine_name} {'=' * 80}")
with c.cd("/vagrant"):
Expand Down
25 changes: 11 additions & 14 deletions andebox → andeboxlib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

def _make_parser():
parser = argparse.ArgumentParser(prog="andebox", description="Ansible Developer (Tool)Box v{}".format(__version__))
parser.add_argument("--version", action="version", version="%(prog)s {0}".format(__version__))
parser.add_argument("--version",
action="version",
version="%(prog)s {0}".format(__version__))
parser.add_argument("--collection", "-c",
help="fully qualified collection name (not necessary if a proper galaxy.yml file is available)")
help="fully qualified collection name (not necessary if a proper galaxy.yml file is available)")
subparser = parser.add_subparsers(dest="action", required=True)

for action in _actions:
Expand Down Expand Up @@ -53,20 +55,15 @@ def run(self):
action.run(args)


def main():
box = AndeBox()
box.run()


if __name__ == '__main__':
def run():
try:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
main()
box = AndeBox()
box.run()
return 0
except KeyboardInterrupt:
print("Interrupted by user", file=sys.stderr)
sys.exit(2)
except BrokenPipeError:
pass
except AndeboxException as e:
return 2
except (AndeboxException, BrokenPipeError) as e:
print(str(e), file=sys.stderr)
sys.exit(1)
return 1
Loading

0 comments on commit f4a9bb7

Please sign in to comment.