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
This commit is contained in:
parent
a16c260543
commit
49ba0c433e
2 changed files with 10 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
.cache/
|
.cache/
|
||||||
*.egg-info/
|
**/*.egg-info/
|
||||||
.env
|
.env
|
||||||
|
**/.ipynb_checkpoints/
|
||||||
.python-version
|
.python-version
|
||||||
.venv/
|
.venv/
|
||||||
|
|
12
noxfile.py
12
noxfile.py
|
@ -357,25 +357,29 @@ def init_project(session):
|
||||||
|
|
||||||
|
|
||||||
@nox.session(name='clean-pwd', python=PYTHON, venv_backend='none')
|
@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.
|
"""Remove (almost) all glob patterns listed in .gitignore.
|
||||||
|
|
||||||
The difference compared to `git clean -X` is that this task
|
The difference compared to `git clean -X` is that this task
|
||||||
does not remove pyenv's .python-version file and poetry's
|
does not remove pyenv's .python-version file and poetry's
|
||||||
virtual environment.
|
virtual environment.
|
||||||
"""
|
"""
|
||||||
exclude = frozenset(('.python-version', '.venv', 'venv'))
|
exclude = frozenset(('.env', '.python-version', '.venv/', 'venv/'))
|
||||||
|
|
||||||
with open('.gitignore') as file_handle:
|
with open('.gitignore') as file_handle:
|
||||||
paths = file_handle.readlines()
|
paths = file_handle.readlines()
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
path = path.strip()
|
path = path.strip()
|
||||||
if path.startswith('#') or path in exclude:
|
if path.startswith('#'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for expanded in glob.glob(path):
|
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):
|
def _begin(session):
|
||||||
|
|
Loading…
Reference in a new issue