Skip to content

Commit

Permalink
rename working_dir to workdir for consistency
Browse files Browse the repository at this point in the history
Currently `podman-py` uses all three versions of `work_dir`,
`working_dir` and `workdir` (not to mention `WorkingDir`).

This commit tries to unify the parameter usage by allowing `workdir` for
container `create` or `run`. For backwards compatibility `working_dir`
still works but a deprecation warning is added.

Since upstream Podman uses a variety of *workdir* versions the
`podman-py` codebase can't be simplified further.

Fix: #330

Signed-off-by: Paul Spooren <[email protected]>
  • Loading branch information
aparcar committed Sep 29, 2023
1 parent 6edcd2d commit 4405f80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions podman/domain/containers_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from contextlib import suppress
from typing import Any, Dict, List, MutableMapping, Union
import warnings

from podman import api
from podman.domain.containers import Container
Expand Down Expand Up @@ -287,7 +288,7 @@ def create(
}
volumes_from (List[str]): List of container names or IDs to get volumes from.
working_dir (str): Path to the working directory.
workdir (str): Path to the working directory.
Returns:
A Container object.
Expand Down Expand Up @@ -403,6 +404,9 @@ def to_bytes(size: Union[int, str, None]) -> Union[int, None]:
f"or int (found : {size_type})"
)

if "working_dir" in args:
warnings.warn("working_dir is deprecated, use workdir instead", PendingDeprecationWarning)

# Transform keywords into parameters
params = {
"annotations": pop("annotations"), # TODO document, podman only
Expand Down Expand Up @@ -484,7 +488,7 @@ def to_bytes(size: Union[int, str, None]) -> Union[int, None]:
"version": pop("version"),
"volumes": [],
"volumes_from": pop("volumes_from"),
"work_dir": pop("working_dir"),
"work_dir": pop("workdir") or pop("working_dir"),
}

for device in args.pop("devices", []):
Expand Down
6 changes: 6 additions & 0 deletions podman/tests/integration/test_container_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ def test_read_write_tmpfs(self):
print(inspect)
self.assertIn(expected_output, logs)

def test_container_working_dir_deprecation(self):
with self.assertWarns(DeprecationWarning):
self.client.containers.create(
self.alpine_image, working_dir="/tmp", command=["/bin/ls", "-l", "/"]
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4405f80

Please sign in to comment.