diff --git a/README.md b/README.md index 3f810327..53771e5b 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ You can confirm installation via `conda list` (curation) $ conda list ldcoolp ``` -You should see that the version is `0.16.1`. +You should see that the version is `0.16.2`. ### Configuration Settings @@ -221,7 +221,8 @@ following a `git tag` version. A list of released features and their issue number(s). List is sorted from moderate to minor revisions for reach release. -v0.16.0 - v0.16.1: +v0.16.0 - v0.16.2: + * Improved handling of .git set-up in `git_info` #124, #125 * `update` method for `ReadmeClass` to enable updating README.txt file #73, #122 * `update_readme` script to enable easy revision #73 * Scripts are executable #110 diff --git a/ldcoolp/__init__.py b/ldcoolp/__init__.py index 01d3d31f..dd021bca 100644 --- a/ldcoolp/__init__.py +++ b/ldcoolp/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = "0.16.1" +__version__ = "0.16.2" co_path = path.dirname(__file__) diff --git a/ldcoolp/git_info.py b/ldcoolp/git_info.py index 8feb11cf..afc992d4 100644 --- a/ldcoolp/git_info.py +++ b/ldcoolp/git_info.py @@ -1,27 +1,39 @@ from pathlib import Path - - -def get_active_branch_name(input_path="."): - - head_dir = Path(input_path) / ".git" / "HEAD" - with head_dir.open("r") as f: - content = f.read().splitlines() - - for line in content: - if line[0:4] == "ref:": - return line.partition("refs/heads/")[2] - - -def get_latest_commit(input_path="."): - - head_dir = Path(input_path) / ".git" / "HEAD" - with head_dir.open("r") as f: - content = f.read().splitlines() - - for line in content: - if line[0:4] == "ref:": - head_path = Path(f".git/{line.partition(' ')[2]}") - with head_path.open('r') as g: - commit = g.read().splitlines() - - return commit[0], commit[0][:7] # full and short hash +from os.path import dirname, basename, exists, join + +# Get git root +git_root = dirname(__file__.replace(f'/{basename(__file__)}', '')) + + +def get_active_branch_name(input_path=git_root): + if exists(join(input_path, ".git", "HEAD")): + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() + + for line in content: + if line[0:4] == "ref:": + return line.partition("refs/heads/")[2] + else: + return f"HEAD detached : {content[0]}" + else: + return '.git structure does not exist' + + +def get_latest_commit(input_path=git_root): + + if exists(join(input_path, ".git", "HEAD")): + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() + + for line in content: + if line[0:4] == "ref:": + head_path = Path(join(input_path, f".git/{line.partition(' ')[2]}")) + with head_path.open('r') as g: + commit = g.read().splitlines() + else: + commit = content + return commit[0], commit[0][:7] # full and short hash + else: + return '.git structure does not exist', '' diff --git a/setup.py b/setup.py index 01451c7d..f69e23c3 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='ldcoolp', - version='v0.16.1', + version='v0.16.2', packages=['ldcoolp'], url='https://github.com/ualibraries/LD_Cool_P', license='MIT License',