mirror of https://github.com/pypa/pip
Refactor the untracked files check
Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com>
This commit is contained in:
parent
75f8c6d6ff
commit
6a0b1f2675
33
noxfile.py
33
noxfile.py
|
@ -262,19 +262,28 @@ def build_dists(session):
|
||||||
session.log(
|
session.log(
|
||||||
"# Check if there's any Git-untracked files before building the wheel",
|
"# Check if there's any Git-untracked files before building the wheel",
|
||||||
)
|
)
|
||||||
has_git_untracked_files = any(
|
|
||||||
bool(l) for l in
|
def get_git_untracked_files():
|
||||||
# session.run doesn't seem to return any output
|
"""List all local file paths that aren't tracked by Git."""
|
||||||
subprocess.check_output(
|
git_ls_files_cmd = (
|
||||||
(
|
"git", "ls-files", "--ignored", "--exclude-standard",
|
||||||
"git", "ls-files", "--ignored", "--exclude-standard",
|
"--others", "--", ".",
|
||||||
"--others", "--", ".",
|
)
|
||||||
),
|
# session.run doesn't seem to return any output:
|
||||||
text=True,
|
ls_files_out = subprocess.check_output(git_ls_files_cmd, text=True)
|
||||||
).split('\n')
|
ls_files_out_lines = ls_files_out.splitlines()
|
||||||
if not l.startswith('.nox/build-release/') # exclude nox env file
|
for file_name in ls_files_out_lines:
|
||||||
|
if file_name.strip(): # it's useless if empty
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield file_name
|
||||||
|
|
||||||
|
has_forbidden_git_untracked_files = any(
|
||||||
|
# Don't report the environment this session is running in
|
||||||
|
not untracked_file.startswith('.nox/build-release/')
|
||||||
|
for untracked_file in get_git_untracked_files()
|
||||||
)
|
)
|
||||||
if has_git_untracked_files:
|
if has_forbidden_git_untracked_files:
|
||||||
session.error(
|
session.error(
|
||||||
"There are untracked files in the working directory. "
|
"There are untracked files in the working directory. "
|
||||||
"Remove them and try again",
|
"Remove them and try again",
|
||||||
|
|
Loading…
Reference in New Issue