Refactor the untracked files check

Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com>
This commit is contained in:
Sviatoslav Sydorenko 2020-01-28 17:21:02 +01:00
parent 75f8c6d6ff
commit 6a0b1f2675
No known key found for this signature in database
GPG Key ID: 9345E8FEA89CA455
1 changed files with 21 additions and 12 deletions

View File

@ -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",