From b8572e21a1203582acf8b00bac7622cdf2e11748 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 3 Nov 2024 09:54:29 +0000 Subject: [PATCH 1/3] Allow cleaning temporary directories --- release-notes.rst | 11 +++++-- setup.cfg | 2 +- src/chevah_compat/testing/filesystem.py | 38 +++++++++++++++++-------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/release-notes.rst b/release-notes.rst index 3734fc1..25f18d0 100644 --- a/release-notes.rst +++ b/release-notes.rst @@ -2,15 +2,22 @@ Release notes for chevah.compat =============================== +1.2.1 - 2024-11-03 +------------------ + +* Allow cleaning testing filesystem inside the Python default temporary + directory, `tempfile.tempdir`. + + 1.2.0 - 2024-10-26 --------------------- +------------------ * Include nose_randomly extension. The extension is no longer maintained upstream. It also removes the dependency on node. 1.1.2 - 2024-10-04 --------------------- +------------------ * Update for python 3.12. * Fix tearDown error handling. diff --git a/setup.cfg b/setup.cfg index 393b75d..7664910 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chevah-compat -version = 1.2.0 +version = 1.2.1 maintainer = Adi Roiban maintainer_email = adi.roiban@proatria.com license = BSD diff --git a/src/chevah_compat/testing/filesystem.py b/src/chevah_compat/testing/filesystem.py index eb9fcb4..9ee17db 100644 --- a/src/chevah_compat/testing/filesystem.py +++ b/src/chevah_compat/testing/filesystem.py @@ -6,6 +6,7 @@ import os import re +import tempfile import uuid import six @@ -265,22 +266,35 @@ def have_safe_path(path): if path == '/': return False + # Allow cleaning temporary directories. + if tempfile.tempdir and path.startswith(path.tempdir): + return True + if os.name == 'posix': # On Unix it is allowed to clean folder only in these # folders. - if not path.startswith(('/srv', '/home', '/tmp')): - return False - if os.name == 'nt': - if path == 'c:\\': - return False - # Allow the windows temp. - if path.lower().startswith('c:\\windows\\temp'): + + if path.startswith(('/srv', '/home', '/tmp')): return True - # On Windows deny Windows or Program Files. - if 'Windows' in path: - return False - if 'Program Files' in path: - return False + + return False + + # We are on Windows. + if path == 'c:\\': + # Deny direct Windows root folder. + return False + + # Allow the windows temp. + if path.lower().startswith('c:\\windows\\temp'): + return True + + # On Windows deny Windows or Program Files. + if 'Windows' in path: + return False + + if 'Program Files' in path: + return False + return True if not have_safe_path(path): From cbeb11010ed299461d788dfa8b9b4aef9858b074 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 3 Nov 2024 09:54:43 +0000 Subject: [PATCH 2/3] Try to run all windows tests in one go. --- .github/workflows/ci.yaml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 40ae1ef..25f3bc2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -211,20 +211,9 @@ jobs: with: limit-access-to-actor: true - # FIXME:691: - # We should have just a single test step here to run all the tests in one - # go. - # Not sure why on Windows the normal tests are not discovered by default. - - name: Test normal - run: | - ./pythia.sh test -vs normal - env: - CODECOV_TOKEN: enabled - USER: runneradmin - - - name: Test elevated + - name: Test run: | - ./pythia.sh test_ci2 elevated + ./pythia.sh test_ci2 env: CODECOV_TOKEN: enabled USER: runneradmin From 2099e24d3f1f14cf5cd7b53d7e254877f649273c Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 3 Nov 2024 10:06:24 +0000 Subject: [PATCH 3/3] Fix tests. --- .github/workflows/ci.yaml | 15 +++++++++++++-- src/chevah_compat/testing/filesystem.py | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 25f3bc2..40ae1ef 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -211,9 +211,20 @@ jobs: with: limit-access-to-actor: true - - name: Test + # FIXME:691: + # We should have just a single test step here to run all the tests in one + # go. + # Not sure why on Windows the normal tests are not discovered by default. + - name: Test normal run: | - ./pythia.sh test_ci2 + ./pythia.sh test -vs normal + env: + CODECOV_TOKEN: enabled + USER: runneradmin + + - name: Test elevated + run: | + ./pythia.sh test_ci2 elevated env: CODECOV_TOKEN: enabled USER: runneradmin diff --git a/src/chevah_compat/testing/filesystem.py b/src/chevah_compat/testing/filesystem.py index 9ee17db..e2b1f79 100644 --- a/src/chevah_compat/testing/filesystem.py +++ b/src/chevah_compat/testing/filesystem.py @@ -267,7 +267,7 @@ def have_safe_path(path): return False # Allow cleaning temporary directories. - if tempfile.tempdir and path.startswith(path.tempdir): + if tempfile.tempdir and path.startswith(tempfile.tempdir): return True if os.name == 'posix':