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)
This code:
hpc-coding-conventions/cpp/lib.py
Lines 59 to 91 in c539260
does not return the expected result when run inside a submodule.
Given a parent project
/path/to/parentwith a submodule/path/to/parent/external/childthe above code returns/path/to/parent/.git/modules/externalwhen run in/path/to/parent/external/child.This means that the formatting utility fails to find
/path/to/parent/external/child/.bbp-project.yamland formatting the child project fails.(Example: NMODL as a submodule of NEURON)