Skip to content

Formatting utility does not work correctly for submodules #156

Description

@olupton

This code:

@functools.lru_cache()
def source_dir():
"""
Returns:
absolute path to the root of a git repository.
The parent repository if hpc-coding-conventions is used
as a git module, this repository otherwise.
Implementation note:
alternative is to use
"git rev-parse --show-superproject-working-tree"
but this solution requires git 2.13 or higher
"""
def git_rev_parse(*args, **kwargs):
cmd = list((which("git"), "rev-parse") + args)
log_command(cmd, level=logging.DEBUG)
output = subprocess.check_output(cmd, **kwargs).decode("utf-8").strip()
return Path(output).resolve()
git_dir = Path(git_rev_parse("--git-dir", cwd=THIS_SCRIPT_DIR))
if git_dir.parent not in THIS_SCRIPT_DIR.parents:
# This project is used as a git module
module_dir = git_rev_parse("--show-toplevel", cwd=THIS_SCRIPT_DIR)
git_dir = git_rev_parse("--git-dir", cwd=os.path.dirname(module_dir))
try:
Path.cwd().relative_to(module_dir)
# cwd is inside hpc-coding-conventions module.
# assume this is for its development.
return module_dir
except ValueError:
pass
return git_dir.parent

does not return the expected result when run inside a submodule.

Given a parent project /path/to/parent with a submodule /path/to/parent/external/child the above code returns /path/to/parent/.git/modules/external when run in /path/to/parent/external/child.

olupton@ewaewa child % pwd
/path/to/parent/external/child
olupton@ewaewa child % git rev-parse --git-dir
/path/to/parent/.git/modules/external/child

This means that the formatting utility fails to find /path/to/parent/external/child/.bbp-project.yaml and formatting the child project fails.

(Example: NMODL as a submodule of NEURON)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions