Skip to content

Commit aaccda0

Browse files
authored
Wip (#3)
* Fix README * Add missing TODO item * Add lint target * Edit actions * Fix wrong ref * Fix wrong ref * Fix runs-on label * Add dev image * Fix image name * Fix * Fix * Add label * Use dev image in pipeline * Fix * Fix * Fix * Fix * Fix * Fix * Ordered option resolve * Edit docstring * Options improvements * Linting and docs gen * Fix linter issues * Add generated docs * Rename step * Add tests * Tests in CI * Fix ci * Rebuild dev-image * Restrict test/lint * Fix ci
1 parent c9209f4 commit aaccda0

File tree

13 files changed

+133
-23
lines changed

13 files changed

+133
-23
lines changed

.github/workflows/.lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ jobs:
1818
uses: actions/checkout@v3
1919
-
2020
name: Running flake8
21-
run: flake8 pycli/
21+
22+
run: make lint

.github/workflows/.test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: lint
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
dev_image_name:
7+
required: true
8+
type: string
9+
secrets: {}
10+
11+
jobs:
12+
pytest:
13+
runs-on: ubuntu-latest
14+
container:
15+
image: ${{ inputs.dev_image_name }}:latest
16+
steps:
17+
-
18+
uses: actions/checkout@v3
19+
-
20+
name: Running pytest
21+
run: make unit-test

.github/workflows/dev-image.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
on:
2-
pull_request:
3-
types:
4-
- opened
5-
- reopened
2+
push:
63
branches:
74
- master
85
paths:
96
- Dockerfile
7+
- pyproject.toml
8+
- poetry.lock
109

1110
jobs:
1211
build-dev-image:

.github/workflows/wip.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ on:
22
push:
33
branches:
44
- wip
5+
paths:
6+
- pycli/
7+
- tests/
58
pull_request:
69
types:
710
- opened
@@ -12,7 +15,11 @@ on:
1215
- pycli/
1316

1417
jobs:
15-
pylint:
18+
lint:
1619
uses: ./.github/workflows/.lint.yml
1720
with:
18-
dev_image_name: ${{ vars.DEV_IMAGE_NAME }}
21+
dev_image_name: ${{ vars.DEV_IMAGE_NAME }}
22+
test:
23+
uses: ./.github/workflows/.test.yml
24+
with:
25+
dev_image_name: ${{ vars.DEV_IMAGE_NAME }}

docs/api/api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ Registers Command within application's root command
3939
#### run
4040

4141
```python
42-
def run() -> int
43-
```
42+
43+
def run(argv: list[str] = None) -> int
44+
4445

4546
Runs Application lifecycle
4647

poetry.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pycli/app.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def __init__(self, name, descr=None, *opts: Option):
3131
for opt in opts:
3232
self.opts.append(opt)
3333

34-
def exec(self, opts):
35-
return
34+
def exec(self, vals):
35+
return 0
3636

3737
__messager: Messager
3838
root_cmd: Command
@@ -62,15 +62,17 @@ def with_commands(self, *cmds: Command) -> Self:
6262
self.root_cmd.children.append(cmd)
6363
return self
6464

65-
def run(self) -> int:
65+
def run(self, argv: list[str] = None) -> int:
6666
"""Runs Application lifecycle
6767
6868
Returns:
6969
Numeric result code
7070
"""
71-
inputl = sys.argv[1:]
72-
cmd, opts, cmdpath = self.root_cmd.process(inputl, set())
73-
args = [x for x in inputl if x not in cmdpath]
71+
if argv is None:
72+
argv = sys.argv[1:]
73+
cmd, opts, cmdpath = self.root_cmd.process(argv, set())
74+
args = [x for x in argv if x not in cmdpath]
75+
7476
values, args = Values.from_opts_args(list(opts), args)
7577
cpath = [self.root_cmd.name, *cmdpath]
7678
if len(args) != 0:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jinja2 = "^3.1.2"
1111
rich = "^13.3.2"
1212

1313
[tool.poetry.group.dev.dependencies]
14-
black = "^23.1.0"
1514
flake8 = "^6.0.0"
1615
pydoc-markdown = {extras = ["novella"], version = "^4.6.4"}
1716
novella = "^0.2.5"

tests/templates/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .app import create_test_app
2+
from . import cmds
3+
from . import opts

tests/templates/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pycli import Application
2+
3+
4+
def create_test_app(name = "test app", descr = None, global_opts = None):
5+
return Application(name, descr, global_opts)

0 commit comments

Comments
 (0)