mirror of
https://github.com/containers/podman-compose.git
synced 2025-02-09 14:59:26 +01:00
Merge pull request #887 from baszoetekouw/fix-oldpython
Fix support for older python versions
This commit is contained in:
commit
f18c8092cc
@ -1,4 +1,4 @@
|
|||||||
[codespell]
|
[codespell]
|
||||||
skip = .git,*.pdf,*.svg
|
skip = .git,*.pdf,*.svg,requirements.txt,test-requirements.txt
|
||||||
# poped - loved variable name
|
# poped - loved variable name
|
||||||
ignore-words-list = poped
|
ignore-words-list = poped
|
||||||
|
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = tab
|
||||||
|
tab_width = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 100
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.py]
|
||||||
|
indent_style = space
|
||||||
|
|
3
.github/workflows/static-checks.yml
vendored
3
.github/workflows/static-checks.yml
vendored
@ -20,3 +20,6 @@ jobs:
|
|||||||
pip install -r test-requirements.txt
|
pip install -r test-requirements.txt
|
||||||
ruff format --check
|
ruff format --check
|
||||||
ruff check
|
ruff check
|
||||||
|
- name: Analysing the code with pylint
|
||||||
|
run: |
|
||||||
|
pylint podman_compose.py
|
||||||
|
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
@ -6,9 +6,14 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: docker.io/library/python:3.11-bookworm
|
image: "docker.io/library/python:${{ matrix.python-version }}-bookworm"
|
||||||
# cgroupns needed to address the following error:
|
# cgroupns needed to address the following error:
|
||||||
# write /sys/fs/cgroup/cgroup.subtree_control: operation not supported
|
# write /sys/fs/cgroup/cgroup.subtree_control: operation not supported
|
||||||
options: --privileged --cgroupns=host
|
options: --privileged --cgroupns=host
|
||||||
@ -21,11 +26,15 @@ jobs:
|
|||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
|
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
|
||||||
- name: Test with unittest
|
- name: Run tests in tests/
|
||||||
run: |
|
run: |
|
||||||
coverage run --source podman_compose -m unittest pytests/*.py
|
|
||||||
python -m unittest tests/*.py
|
python -m unittest tests/*.py
|
||||||
coverage combine
|
|
||||||
coverage report
|
|
||||||
env:
|
env:
|
||||||
TESTS_DEBUG: 1
|
TESTS_DEBUG: 1
|
||||||
|
- name: Run tests in pytests/
|
||||||
|
run: |
|
||||||
|
coverage run --source podman_compose -m unittest pytests/*.py
|
||||||
|
- name: Report coverage
|
||||||
|
run: |
|
||||||
|
coverage combine
|
||||||
|
coverage report
|
||||||
|
@ -1173,14 +1173,14 @@ class Podman:
|
|||||||
xargs = self.compose.get_podman_args(cmd) if cmd else []
|
xargs = self.compose.get_podman_args(cmd) if cmd else []
|
||||||
cmd_ls = [self.podman_path, *podman_args, cmd] + xargs + cmd_args
|
cmd_ls = [self.podman_path, *podman_args, cmd] + xargs + cmd_args
|
||||||
log.info(str(cmd_ls))
|
log.info(str(cmd_ls))
|
||||||
p = await asyncio.subprocess.create_subprocess_exec(
|
p = await asyncio.create_subprocess_exec(
|
||||||
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||||
)
|
)
|
||||||
|
|
||||||
stdout_data, stderr_data = await p.communicate()
|
stdout_data, stderr_data = await p.communicate()
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return stdout_data
|
return stdout_data
|
||||||
else:
|
|
||||||
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
|
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
|
||||||
|
|
||||||
def exec(
|
def exec(
|
||||||
@ -1195,7 +1195,7 @@ class Podman:
|
|||||||
log.info(" ".join([str(i) for i in cmd_ls]))
|
log.info(" ".join([str(i) for i in cmd_ls]))
|
||||||
os.execlp(self.podman_path, *cmd_ls)
|
os.execlp(self.podman_path, *cmd_ls)
|
||||||
|
|
||||||
async def run(
|
async def run( # pylint: disable=dangerous-default-value
|
||||||
self,
|
self,
|
||||||
podman_args,
|
podman_args,
|
||||||
cmd="",
|
cmd="",
|
||||||
@ -1223,7 +1223,7 @@ class Podman:
|
|||||||
if stdout.at_eof():
|
if stdout.at_eof():
|
||||||
break
|
break
|
||||||
|
|
||||||
p = await asyncio.subprocess.create_subprocess_exec(
|
p = await asyncio.create_subprocess_exec(
|
||||||
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||||
) # pylint: disable=consider-using-with
|
) # pylint: disable=consider-using-with
|
||||||
|
|
||||||
@ -1238,7 +1238,7 @@ class Podman:
|
|||||||
err_t.add_done_callback(task_reference.discard)
|
err_t.add_done_callback(task_reference.discard)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
p = await asyncio.subprocess.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
|
p = await asyncio.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exit_code = await p.wait()
|
exit_code = await p.wait()
|
||||||
@ -1916,9 +1916,12 @@ class PodmanCompose:
|
|||||||
|
|
||||||
podman_compose = PodmanCompose()
|
podman_compose = PodmanCompose()
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# decorators to add commands and parse options
|
# decorators to add commands and parse options
|
||||||
###################
|
###################
|
||||||
|
class PodmanComposeError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
|
class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
|
||||||
@ -1932,7 +1935,7 @@ class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
|
|||||||
return func(*args, **kw)
|
return func(*args, **kw)
|
||||||
|
|
||||||
if not asyncio.iscoroutinefunction(func):
|
if not asyncio.iscoroutinefunction(func):
|
||||||
raise Exception("Command must be async")
|
raise PodmanComposeError("Command must be async")
|
||||||
wrapped._compose = self.compose
|
wrapped._compose = self.compose
|
||||||
# Trim extra indentation at start of multiline docstrings.
|
# Trim extra indentation at start of multiline docstrings.
|
||||||
wrapped.desc = self.cmd_desc or re.sub(r"^\s+", "", func.__doc__)
|
wrapped.desc = self.cmd_desc or re.sub(r"^\s+", "", func.__doc__)
|
||||||
@ -2014,8 +2017,8 @@ async def compose_systemd(compose, args):
|
|||||||
f.write(f"{k}={v}\n")
|
f.write(f"{k}={v}\n")
|
||||||
log.debug("writing [%s]: done.", fn)
|
log.debug("writing [%s]: done.", fn)
|
||||||
log.info("\n\ncreating the pod without starting it: ...\n\n")
|
log.info("\n\ncreating the pod without starting it: ...\n\n")
|
||||||
process = await asyncio.subprocess.create_subprocess_exec(script, ["up", "--no-start"])
|
process = await asyncio.create_subprocess_exec(script, ["up", "--no-start"])
|
||||||
log.info("\nfinal exit code is ", process)
|
log.info("\nfinal exit code is %d", process)
|
||||||
username = getpass.getuser()
|
username = getpass.getuser()
|
||||||
print(
|
print(
|
||||||
f"""
|
f"""
|
||||||
@ -2299,6 +2302,14 @@ async def compose_up(compose: PodmanCompose, args):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _task_cancelled(task: Task) -> bool:
|
||||||
|
if task.cancelled():
|
||||||
|
return True
|
||||||
|
# Task.cancelling() is new in python 3.11
|
||||||
|
if sys.version_info >= (3, 11) and task.cancelling():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
exiting = False
|
exiting = False
|
||||||
while tasks:
|
while tasks:
|
||||||
@ -2309,7 +2320,9 @@ async def compose_up(compose: PodmanCompose, args):
|
|||||||
# cause the status to overwrite. Sleeping for 1 seems to fix this and make it match
|
# cause the status to overwrite. Sleeping for 1 seems to fix this and make it match
|
||||||
# docker-compose
|
# docker-compose
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
[_.cancel() for _ in tasks if not _.cancelling() and not _.cancelled()]
|
for t in tasks:
|
||||||
|
if not _task_cancelled(t):
|
||||||
|
t.cancel()
|
||||||
t: Task
|
t: Task
|
||||||
exiting = True
|
exiting = True
|
||||||
for t in done:
|
for t in done:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
@ -4,6 +4,7 @@ parameterized==0.9.0
|
|||||||
pytest==8.0.2
|
pytest==8.0.2
|
||||||
tox==4.13.0
|
tox==4.13.0
|
||||||
ruff==0.3.1
|
ruff==0.3.1
|
||||||
|
pylint==3.1.0
|
||||||
|
|
||||||
# The packages below are transitive dependencies of the packages above and are included here
|
# The packages below are transitive dependencies of the packages above and are included here
|
||||||
# to make testing reproducible.
|
# to make testing reproducible.
|
||||||
@ -12,16 +13,21 @@ ruff==0.3.1
|
|||||||
# pip freeze > test-requirements.txt
|
# pip freeze > test-requirements.txt
|
||||||
# and edit test-requirements.txt to add this comment
|
# and edit test-requirements.txt to add this comment
|
||||||
|
|
||||||
|
astroid==3.1.0
|
||||||
cachetools==5.3.3
|
cachetools==5.3.3
|
||||||
chardet==5.2.0
|
chardet==5.2.0
|
||||||
colorama==0.4.6
|
colorama==0.4.6
|
||||||
|
dill==0.3.8
|
||||||
distlib==0.3.8
|
distlib==0.3.8
|
||||||
filelock==3.13.1
|
filelock==3.13.1
|
||||||
iniconfig==2.0.0
|
iniconfig==2.0.0
|
||||||
|
isort==5.13.2
|
||||||
|
mccabe==0.7.0
|
||||||
packaging==23.2
|
packaging==23.2
|
||||||
platformdirs==4.2.0
|
platformdirs==4.2.0
|
||||||
pluggy==1.4.0
|
pluggy==1.4.0
|
||||||
pyproject-api==1.6.1
|
pyproject-api==1.6.1
|
||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
|
tomlkit==0.12.4
|
||||||
virtualenv==20.25.1
|
virtualenv==20.25.1
|
||||||
|
Loading…
Reference in New Issue
Block a user