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/
|
||||
*.egg-info/
|
||||
**/*.egg-info/
|
||||
.env
|
||||
**/.ipynb_checkpoints/
|
||||
.python-version
|
||||
.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')
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue