diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..205cd6a --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,41 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.gitignore b/.gitignore index a88f3ce..df0e868 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.egg-info *.txt *.ipynb +build/* +*.pyc \ No newline at end of file diff --git a/dockrice/argparse.py b/dockrice/argparse.py index e2a9abc..773842c 100644 --- a/dockrice/argparse.py +++ b/dockrice/argparse.py @@ -93,7 +93,7 @@ def __init__( def __call__(factory_self, action=None): - if action == None: + if action is None: action = "store" if isinstance(action, str): action = getattr(argparse, factory_self.select[action]) diff --git a/dockrice/dockerpath.py b/dockrice/dockerpath.py index 64fa12e..af5464a 100644 --- a/dockrice/dockerpath.py +++ b/dockrice/dockerpath.py @@ -5,13 +5,13 @@ from docker.types import Mount from typing import Union, Tuple from enum import Enum -from collections.abc import Hashable, MutableSet +import sys PathLike = Union[pathlib.PurePath, str] def remove_prefix(string, prefix): - return string[(len(prefix) if string.startswith(prefix) else 0) :] + return string[(len(prefix) if string.startswith(prefix) else 0):] class MountOption(Enum): @@ -59,7 +59,8 @@ def __init__( self._mount_path = mount_path self._mount_parent = mount_parent self._read_only = read_only - super().__init__(*path) + if sys.version_info >= (3, 12): + super().__init__(*path) @property def read_only(self) -> bool: @@ -95,7 +96,7 @@ def mount_path(self) -> pathlib.PurePosixPath: mount_path = pathlib.PurePosixPath(*mount_path) else: mount_path = pathlib.PurePosixPath(mount_path) - if mount_parent is True: + if self.mount_parent is True: mount_path = pathlib.PurePosixPath(mount_path, self.name) assert ( mount_path.is_absolute() diff --git a/dockrice/tests/test_dockerpath.py b/dockrice/tests/test_dockerpath.py new file mode 100644 index 0000000..8d2ae23 --- /dev/null +++ b/dockrice/tests/test_dockerpath.py @@ -0,0 +1,26 @@ +import pytest + +from dockrice import DockerPath +from pathlib import PurePath, Path + + +@pytest.mark.parametrize( + "arg1, arg2", + [ + ("test/path", None), + ("test/path", "another/path"), + (Path("existing/path"), None), + (Path("existing/path"), "string/path"), + ("string/path", Path("existing/path")), + ], +) +def test_path_initialization(arg1, arg2): + if arg2 is None: + path = DockerPath(arg1) + else: + path = DockerPath(arg1, arg2) + + path.resolve() + path.exists() + assert isinstance(path, PurePath) + assert isinstance(path.mount_path, PurePath)