From a98c5dd85c25e7e30c53b8b455bfbcffde3300b9 Mon Sep 17 00:00:00 2001 From: Konstantinos Smanis Date: Mon, 17 May 2021 22:08:54 +0300 Subject: [PATCH] Fix compilation inside Git submodules --- pipautocompile/main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pipautocompile/main.py b/pipautocompile/main.py index f67a011..705b072 100644 --- a/pipautocompile/main.py +++ b/pipautocompile/main.py @@ -19,15 +19,13 @@ ) -def _is_inside_git_submodule(path: Union[bytes, str, os.PathLike]) -> bool: +def _working_tree(path: Union[bytes, str, os.PathLike] = Path()) -> bytes: try: - output = subprocess.check_output( # nosec - ("git", "rev-parse", "--show-superproject-working-tree"), cwd=path + return subprocess.check_output( # nosec + ("git", "rev-parse", "--show-toplevel"), cwd=path ) except (FileNotFoundError, subprocess.CalledProcessError): - return False - else: - return bool(output) + return b"" def _find_spec_files( @@ -92,8 +90,9 @@ def cli(build_stage: str, recurse_submodules: bool, pip_compile_args: Tuple[str, if not pip_compile_args: pip_compile_args = DEFAULT_PIP_COMPILE_ARGS + initial_working_tree = _working_tree() for spec_dir, specs in groupby(_find_spec_files(), key=lambda spec: spec.parent): - if not recurse_submodules and _is_inside_git_submodule(spec_dir): + if not recurse_submodules and initial_working_tree != _working_tree(spec_dir): continue _log(f"Processing {spec_dir} directory...")