Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.egg-info
*.txt
*.ipynb
build/*
*.pyc
2 changes: 1 addition & 1 deletion dockrice/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
9 changes: 5 additions & 4 deletions dockrice/dockerpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 26 additions & 0 deletions dockrice/tests/test_dockerpath.py
Original file line number Diff line number Diff line change
@@ -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)