Skip to content

Commit f18c809

Browse files
authored
Merge pull request #887 from baszoetekouw/fix-oldpython
Fix support for older python versions
2 parents 43059dc + da63048 commit f18c809

File tree

9 files changed

+69
-16
lines changed

9 files changed

+69
-16
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[codespell]
2-
skip = .git,*.pdf,*.svg
2+
skip = .git,*.pdf,*.svg,requirements.txt,test-requirements.txt
33
# poped - loved variable name
44
ignore-words-list = poped

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = tab
6+
tab_width = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
max_line_length = 100
12+
13+
[*.{yml,yaml}]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.py]
18+
indent_style = space
19+

.github/workflows/static-checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ jobs:
2020
pip install -r test-requirements.txt
2121
ruff format --check
2222
ruff check
23+
- name: Analysing the code with pylint
24+
run: |
25+
pylint podman_compose.py

.github/workflows/test.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ on:
66

77
jobs:
88
test:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
13+
914
runs-on: ubuntu-latest
1015
container:
11-
image: docker.io/library/python:3.11-bookworm
16+
image: "docker.io/library/python:${{ matrix.python-version }}-bookworm"
1217
# cgroupns needed to address the following error:
1318
# write /sys/fs/cgroup/cgroup.subtree_control: operation not supported
1419
options: --privileged --cgroupns=host
@@ -21,11 +26,15 @@ jobs:
2126
python -m pip install --upgrade pip
2227
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2328
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
24-
- name: Test with unittest
29+
- name: Run tests in tests/
2530
run: |
26-
coverage run --source podman_compose -m unittest pytests/*.py
2731
python -m unittest tests/*.py
28-
coverage combine
29-
coverage report
3032
env:
3133
TESTS_DEBUG: 1
34+
- name: Run tests in pytests/
35+
run: |
36+
coverage run --source podman_compose -m unittest pytests/*.py
37+
- name: Report coverage
38+
run: |
39+
coverage combine
40+
coverage report

podman_compose.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,15 +1173,15 @@ async def output(self, podman_args, cmd="", cmd_args=None):
11731173
xargs = self.compose.get_podman_args(cmd) if cmd else []
11741174
cmd_ls = [self.podman_path, *podman_args, cmd] + xargs + cmd_args
11751175
log.info(str(cmd_ls))
1176-
p = await asyncio.subprocess.create_subprocess_exec(
1176+
p = await asyncio.create_subprocess_exec(
11771177
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
11781178
)
11791179

11801180
stdout_data, stderr_data = await p.communicate()
11811181
if p.returncode == 0:
11821182
return stdout_data
1183-
else:
1184-
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
1183+
1184+
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
11851185

11861186
def exec(
11871187
self,
@@ -1195,7 +1195,7 @@ def exec(
11951195
log.info(" ".join([str(i) for i in cmd_ls]))
11961196
os.execlp(self.podman_path, *cmd_ls)
11971197

1198-
async def run(
1198+
async def run( # pylint: disable=dangerous-default-value
11991199
self,
12001200
podman_args,
12011201
cmd="",
@@ -1223,7 +1223,7 @@ async def format_out(stdout):
12231223
if stdout.at_eof():
12241224
break
12251225

1226-
p = await asyncio.subprocess.create_subprocess_exec(
1226+
p = await asyncio.create_subprocess_exec(
12271227
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
12281228
) # pylint: disable=consider-using-with
12291229

@@ -1238,7 +1238,7 @@ async def format_out(stdout):
12381238
err_t.add_done_callback(task_reference.discard)
12391239

12401240
else:
1241-
p = await asyncio.subprocess.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
1241+
p = await asyncio.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
12421242

12431243
try:
12441244
exit_code = await p.wait()
@@ -1916,9 +1916,12 @@ def _init_global_parser(parser):
19161916

19171917
podman_compose = PodmanCompose()
19181918

1919+
19191920
###################
19201921
# decorators to add commands and parse options
19211922
###################
1923+
class PodmanComposeError(Exception):
1924+
pass
19221925

19231926

19241927
class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
@@ -1932,7 +1935,7 @@ def wrapped(*args, **kw):
19321935
return func(*args, **kw)
19331936

19341937
if not asyncio.iscoroutinefunction(func):
1935-
raise Exception("Command must be async")
1938+
raise PodmanComposeError("Command must be async")
19361939
wrapped._compose = self.compose
19371940
# Trim extra indentation at start of multiline docstrings.
19381941
wrapped.desc = self.cmd_desc or re.sub(r"^\s+", "", func.__doc__)
@@ -2014,8 +2017,8 @@ async def compose_systemd(compose, args):
20142017
f.write(f"{k}={v}\n")
20152018
log.debug("writing [%s]: done.", fn)
20162019
log.info("\n\ncreating the pod without starting it: ...\n\n")
2017-
process = await asyncio.subprocess.create_subprocess_exec(script, ["up", "--no-start"])
2018-
log.info("\nfinal exit code is ", process)
2020+
process = await asyncio.create_subprocess_exec(script, ["up", "--no-start"])
2021+
log.info("\nfinal exit code is %d", process)
20192022
username = getpass.getuser()
20202023
print(
20212024
f"""
@@ -2299,6 +2302,14 @@ async def compose_up(compose: PodmanCompose, args):
22992302
)
23002303
)
23012304

2305+
def _task_cancelled(task: Task) -> bool:
2306+
if task.cancelled():
2307+
return True
2308+
# Task.cancelling() is new in python 3.11
2309+
if sys.version_info >= (3, 11) and task.cancelling():
2310+
return True
2311+
return False
2312+
23022313
exit_code = 0
23032314
exiting = False
23042315
while tasks:
@@ -2309,7 +2320,9 @@ async def compose_up(compose: PodmanCompose, args):
23092320
# cause the status to overwrite. Sleeping for 1 seems to fix this and make it match
23102321
# docker-compose
23112322
await asyncio.sleep(1)
2312-
[_.cancel() for _ in tasks if not _.cancelling() and not _.cancelled()]
2323+
for t in tasks:
2324+
if not _task_cancelled(t):
2325+
t.cancel()
23132326
t: Task
23142327
exiting = True
23152328
for t in done:

pytests/test_can_merge_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
from __future__ import annotations
23

34
import argparse
45
import os

pytests/test_can_merge_cmd_ent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
from __future__ import annotations
23

34
import argparse
45
import copy

pytests/test_normalize_final_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# pylint: disable=protected-access
3+
from __future__ import annotations
34

45
import argparse
56
import os

test-requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameterized==0.9.0
44
pytest==8.0.2
55
tox==4.13.0
66
ruff==0.3.1
7+
pylint==3.1.0
78

89
# The packages below are transitive dependencies of the packages above and are included here
910
# to make testing reproducible.
@@ -12,16 +13,21 @@ ruff==0.3.1
1213
# pip freeze > test-requirements.txt
1314
# and edit test-requirements.txt to add this comment
1415

16+
astroid==3.1.0
1517
cachetools==5.3.3
1618
chardet==5.2.0
1719
colorama==0.4.6
20+
dill==0.3.8
1821
distlib==0.3.8
1922
filelock==3.13.1
2023
iniconfig==2.0.0
24+
isort==5.13.2
25+
mccabe==0.7.0
2126
packaging==23.2
2227
platformdirs==4.2.0
2328
pluggy==1.4.0
2429
pyproject-api==1.6.1
2530
python-dotenv==1.0.1
2631
PyYAML==6.0.1
32+
tomlkit==0.12.4
2733
virtualenv==20.25.1

0 commit comments

Comments
 (0)