From 49ba0c433e3c90833d7f1b692d3d38b184d525f5 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Sun, 9 Aug 2020 20:21:34 +0200 Subject: [PATCH] Fix the "clean-pwd" command in nox - some glob patterns in .gitignore were not correctly expanded - adapt the exclude logic to focus on the start of the excluded paths --- .gitignore | 3 ++- noxfile.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 84d0bf6..2fc8820 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .cache/ -*.egg-info/ +**/*.egg-info/ .env +**/.ipynb_checkpoints/ .python-version .venv/ diff --git a/noxfile.py b/noxfile.py index bf97ca1..ec5d6f9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -357,25 +357,29 @@ def init_project(session): @nox.session(name='clean-pwd', python=PYTHON, venv_backend='none') -def clean_pwd(session): +def clean_pwd(session): # noqa:WPS210,WPS231 """Remove (almost) all glob patterns listed in .gitignore. The difference compared to `git clean -X` is that this task does not remove pyenv's .python-version file and poetry's virtual environment. """ - exclude = frozenset(('.python-version', '.venv', 'venv')) + exclude = frozenset(('.env', '.python-version', '.venv/', 'venv/')) with open('.gitignore') as file_handle: paths = file_handle.readlines() for path in paths: path = path.strip() - if path.startswith('#') or path in exclude: + if path.startswith('#'): continue for expanded in glob.glob(path): - session.run(f'rm -rf {expanded}') + for excluded in exclude: + if expanded.startswith(excluded): + break + else: + session.run('rm', '-rf', expanded) def _begin(session):