Skip to content

Commit 3c9628b

Browse files
Falmarrimuayyad-alsadi
authored andcommitted
Fix a couple issues and update docs
Signed-off-by: Falmarri <[email protected]>
1 parent 38b13a3 commit 3c9628b

10 files changed

+48
-25
lines changed

.coveragerc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
parallel=True

.github/workflows/pytest.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ jobs:
2121
python-version: "3.10"
2222
- name: Install dependencies
2323
run: |
24+
apt update && apt install podman
2425
python -m pip install --upgrade pip
25-
pip install flake8 pytest
2626
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
2728
- name: Lint with flake8
2829
run: |
2930
# stop the build if there are Python syntax errors or undefined names
@@ -32,5 +33,7 @@ jobs:
3233
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3334
- name: Test with pytest
3435
run: |
35-
python -m pytest ./pytests
36-
36+
coverage run --source podman_compose -m pytest ./pytests
37+
python -m pytest ./tests
38+
coverage combine
39+
coverage report

CONTRIBUTING.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ $ pre-commit install
3939
```shell
4040
$ pre-commit run --all-files
4141
```
42-
6. Commit your code to your fork's branch.
42+
6. Run code coverage
43+
```shell
44+
coverage run --source podman_compose -m pytest ./pytests
45+
python -m pytest ./tests
46+
coverage combine
47+
coverage report
48+
coverage html
49+
```
50+
7. Commit your code to your fork's branch.
4351
- Make sure you include a `Signed-off-by` message in your commits. Read [this guide](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) to learn how to sign your commits
4452
- In the commit message reference the Issue ID that your code fixes and a brief description of the changes. Example: `Fixes #516: allow empty network`
4553
7. Open a PR to `containers/podman-compose:devel` and wait for a maintainer to review your work.
@@ -48,18 +56,18 @@ $ pre-commit run --all-files
4856

4957
To add a command you need to add a function that is decorated
5058
with `@cmd_run` passing the compose instance, command name and
51-
description. the wrapped function should accept two arguments
52-
the compose instance and the command-specific arguments (resulted
53-
from python's `argparse` package) inside that command you can
54-
run PodMan like this `compose.podman.run(['inspect', 'something'])`
55-
and inside that function you can access `compose.pods`
56-
and `compose.containers` ...etc.
57-
Here is an example
59+
description. This function must be declared `async` the wrapped
60+
function should accept two arguments the compose instance and
61+
the command-specific arguments (resulted from python's `argparse`
62+
package) inside that command you can run PodMan like this
63+
`await compose.podman.run(['inspect', 'something'])`and inside
64+
that function you can access `compose.pods` and `compose.containers`
65+
...etc. Here is an example
5866

5967
```
6068
@cmd_run(podman_compose, 'build', 'build images defined in the stack')
61-
def compose_build(compose, args):
62-
compose.podman.run(['build', 'something'])
69+
async def compose_build(compose, args):
70+
await compose.podman.run(['build', 'something'])
6371
```
6472

6573
## Command arguments parsing
@@ -90,10 +98,10 @@ do something like:
9098

9199
```
92100
@cmd_run(podman_compose, 'up', 'up desc')
93-
def compose_up(compose, args):
94-
compose.commands['down'](compose, args)
101+
async def compose_up(compose, args):
102+
await compose.commands['down'](compose, args)
95103
# or
96-
compose.commands['down'](argparse.Namespace(foo=123))
104+
await compose.commands['down'](argparse.Namespace(foo=123))
97105
```
98106

99107

podman_compose.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,8 @@ async def compose_up(compose: PodmanCompose, args):
22482248
if not args.no_build:
22492249
# `podman build` does not cache, so don't always build
22502250
build_args = argparse.Namespace(if_not_exists=(not args.build), **args.__dict__)
2251-
ret = await compose.commands["build"](compose, build_args)
2251+
if await compose.commands["build"](compose, build_args) != 0:
2252+
log("Build command failed")
22522253

22532254
hashes = (
22542255
(await compose.podman.output(
@@ -2317,7 +2318,12 @@ async def compose_up(compose: PodmanCompose, args):
23172318
log("** skipping: ", cnt["name"])
23182319
continue
23192320

2320-
tasks.add(asyncio.create_task(compose.podman.run([], "start", ["-a", cnt["name"]], wait=True, sleep=None, log_formatter=log_formatter), name=cnt["_service"]))
2321+
tasks.add(
2322+
asyncio.create_task(
2323+
compose.podman.run([], "start", ["-a", cnt["name"]], sleep=None, log_formatter=log_formatter),
2324+
name=cnt["_service"]
2325+
)
2326+
)
23212327

23222328
exit_code = 0
23232329
for task in asyncio.as_completed(tasks):

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"black",
4646
"pylint",
4747
"pre-commit",
48+
"coverage"
4849
]
4950
}
5051
# test_suite='tests',

test-requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# process, which may cause wedges in the gate later.
44

55
coverage
6-
pytest-cov
76
pytest
87
tox
98
black

tests/test_podman_compose.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def test_podman_compose_extends_w_file_subdir():
2121
main_path = Path(__file__).parent.parent
2222

2323
command_up = [
24-
"python3",
24+
"coverage",
25+
"run",
2526
str(main_path.joinpath("podman_compose.py")),
2627
"-f",
2728
str(main_path.joinpath("tests", "extends_w_file_subdir", "docker-compose.yml")),

tests/test_podman_compose_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_config_no_profiles(podman_compose_path, profile_compose_file):
2222
:param podman_compose_path: The fixture used to specify the path to the podman compose file.
2323
:param profile_compose_file: The fixtued used to specify the path to the "profile" compose used in the test.
2424
"""
25-
config_cmd = ["python3", podman_compose_path, "-f", profile_compose_file, "config"]
25+
config_cmd = ["coverage", "run", podman_compose_path, "-f", profile_compose_file, "config"]
2626

2727
out, _, return_code = capture(config_cmd)
2828
assert return_code == 0
@@ -61,7 +61,7 @@ def test_config_profiles(
6161
:param expected_services: Dictionary used to model the expected "enabled" services in the profile.
6262
Key = service name, Value = True if the service is enabled, otherwise False.
6363
"""
64-
config_cmd = ["python3", podman_compose_path, "-f", profile_compose_file]
64+
config_cmd = ["coverage", "run", podman_compose_path, "-f", profile_compose_file]
6565
config_cmd.extend(profiles)
6666

6767
out, _, return_code = capture(config_cmd)

tests/test_podman_compose_include.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_podman_compose_include():
2020
main_path = Path(__file__).parent.parent
2121

2222
command_up = [
23-
"python3",
23+
"coverage",
24+
"run",
2425
str(main_path.joinpath("podman_compose.py")),
2526
"-f",
2627
str(main_path.joinpath("tests", "include", "docker-compose.yaml")),

tests/test_podman_compose_up_down.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def teardown(podman_compose_path, profile_compose_file):
2727
yield
2828

2929
down_cmd = [
30-
"python3",
30+
"coverage",
31+
"run",
3132
podman_compose_path,
3233
"--profile",
3334
"profile-1",
@@ -59,7 +60,8 @@ def teardown(podman_compose_path, profile_compose_file):
5960
)
6061
def test_up(podman_compose_path, profile_compose_file, profiles, expected_services):
6162
up_cmd = [
62-
"python3",
63+
"coverage",
64+
"run",
6365
podman_compose_path,
6466
"-f",
6567
profile_compose_file,

0 commit comments

Comments
 (0)