From 5ba0ce1c671b3bacf4fc4136909ff8c2342b7c99 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 20 May 2023 13:01:23 -0700 Subject: [PATCH 1/5] Add Windows in the tests --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index b859c1b..d09b08f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: From a4e6624e497c1de1e9d9fa0c2f83abacb33fa540 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 20 May 2023 13:03:27 -0700 Subject: [PATCH 2/5] no fail fast --- .github/workflows/pytest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index d09b08f..0f9f3d8 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -6,6 +6,7 @@ jobs: test: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] From 5db143c923529c4d887a390b120cd883789b1c67 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 20 May 2023 13:07:19 -0700 Subject: [PATCH 3/5] Run on WSL --- .github/workflows/pytest.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0f9f3d8..9eff34d 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -13,16 +13,37 @@ jobs: steps: - uses: actions/checkout@v2 + + - name: Set up WSL + if: matrix.os == 'windows-latest' + run: | + wsl --install + wsl --set-default-version 2 + shell: powershell + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -e ".[test,docs]" + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then + wsl python -m pip install --upgrade pip + wsl pip install -e ".[test,docs]" + else + python -m pip install --upgrade pip + pip install -e ".[test,docs]" + fi + - name: Run pytest - run: pytest + run: | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then + wsl pytest + else + pytest + fi + - name: Upload coverage reports to Codecov if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' uses: codecov/codecov-action@v3 From 42387c2f9b351b15dc48bbea8aca44cf733acd2a Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 20 May 2023 13:10:08 -0700 Subject: [PATCH 4/5] Use Path and revert WSL --- .github/workflows/pytest.yml | 27 +++------------------------ rsync_time_machine.py | 11 ++++++----- tests/test_app.py | 3 ++- 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 9eff34d..0f9f3d8 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -13,37 +13,16 @@ jobs: steps: - uses: actions/checkout@v2 - - - name: Set up WSL - if: matrix.os == 'windows-latest' - run: | - wsl --install - wsl --set-default-version 2 - shell: powershell - - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies run: | - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - wsl python -m pip install --upgrade pip - wsl pip install -e ".[test,docs]" - else - python -m pip install --upgrade pip - pip install -e ".[test,docs]" - fi - + python -m pip install --upgrade pip + pip install -e ".[test,docs]" - name: Run pytest - run: | - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - wsl pytest - else - pytest - fi - + run: pytest - name: Upload coverage reports to Codecov if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' uses: codecov/codecov-action@v3 diff --git a/rsync_time_machine.py b/rsync_time_machine.py index 5bc46a0..08f8e0a 100755 --- a/rsync_time_machine.py +++ b/rsync_time_machine.py @@ -8,8 +8,9 @@ import sys import time from datetime import datetime +from pathlib import Path from types import FrameType -from typing import Dict, List, NamedTuple, Optional, Tuple +from typing import Dict, List, NamedTuple, Optional, Tuple, Union APPNAME = "rsync-time-machine.py" VERBOSE = False @@ -322,12 +323,12 @@ def expire_backups( break -def backup_marker_path(folder: str) -> str: +def backup_marker_path(folder: Union[str, Path]) -> Path: """Return the path to the backup marker file.""" - return os.path.join(folder, "backup.marker") + return Path(folder) / "backup.marker" -def find_backup_marker(folder: str, ssh: Optional[SSH]) -> Optional[str]: +def find_backup_marker(folder: str, ssh: Optional[SSH]) -> Optional[Union[str, Path]]: """Find the backup marker file in the given folder.""" marker_path = backup_marker_path(folder) output = find(marker_path, ssh) @@ -375,7 +376,7 @@ def run_cmd( return CmdResult(result.stdout.strip(), result.stderr.strip(), result.returncode) -def find(path: str, ssh: Optional[SSH]) -> str: +def find(path: Union[str, Path], ssh: Optional[SSH]) -> str: """Find files in the given path, using the `find` command.""" return run_cmd(f"find '{path}'", ssh).stdout diff --git a/tests/test_app.py b/tests/test_app.py index 0ed82f9..713a8a1 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -178,7 +178,8 @@ def test_find_backups(tmp_path: Path) -> None: def test_backup_marker_path() -> None: """Test the backup_marker_path function.""" - assert backup_marker_path("/path/to/folder") == "/path/to/folder/backup.marker" + folder = Path("path") / "to" / "folder" + assert backup_marker_path(folder) == folder / "backup.marker" def test_find_backup_marker(tmp_path: Path) -> None: From 99b1cf03a6e063afca43852289c8fbd14e6b2c39 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 20 May 2023 13:19:48 -0700 Subject: [PATCH 5/5] Test vampire --- .github/workflows/pytest.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0f9f3d8..4bcb997 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -6,23 +6,36 @@ jobs: test: runs-on: ${{ matrix.os }} strategy: - fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v2 + + - name: Set up WSL + if: matrix.os == 'windows-latest' + uses: Vampire/setup-wsl@v2 + with: + distribution: 'Ubuntu-20.04' + use-cache: 'true' + update: 'true' + additional-packages: 'python3-pip' + wsl-shell-user: 'root' + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip pip install -e ".[test,docs]" + - name: Run pytest run: pytest + - name: Upload coverage reports to Codecov if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' uses: codecov/codecov-action@v3