-
Notifications
You must be signed in to change notification settings - Fork 45
Improved version tracking and deprecated SVN #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
646953c
Add files via upload
VeronicaSergeeva 27cb95e
Add files via upload
VeronicaSergeeva 5fb5975
Add files via upload
VeronicaSergeeva 62f5577
Add files via upload
VeronicaSergeeva 8f15e96
Add files via upload
VeronicaSergeeva 98200f7
Add files via upload
VeronicaSergeeva a04fae5
Update and rename rec_check.py to tools/rec_check.py
VeronicaSergeeva e436fb1
Merge branch 'master' into master
VeronicaSergeeva 238968e
Add files via upload
VeronicaSergeeva dffbf7a
Add files via upload
VeronicaSergeeva ef9dee8
Add files via upload
VeronicaSergeeva a114af1
Add files via upload
VeronicaSergeeva 7cb1417
Add files via upload
VeronicaSergeeva 080df8e
Add files via upload
VeronicaSergeeva 0d3dd53
removing extraneous copy of SurveySim
dsavransky 53a78da
Add files via upload
VeronicaSergeeva 29ba8c2
Add files via upload
VeronicaSergeeva b54697a
Update version_util.py
VeronicaSergeeva 794230d
Add files via upload
VeronicaSergeeva 830ef70
Add files via upload
VeronicaSergeeva 16a6e9b
Add files via upload
VeronicaSergeeva a1a466e
updating version utils and putting all version info into single keywo…
dsavransky c92a7b6
updating docstrings
dsavransky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from importlib import metadata | ||
import platform | ||
import subprocess | ||
import os | ||
import json | ||
import EXOSIMS | ||
|
||
|
||
def get_git_info(): | ||
""" | ||
Get Git information including commit hash and any uncommited changes | ||
|
||
Args: | ||
None | ||
|
||
Returns: | ||
tuple: | ||
gitrev (str): | ||
Hash of HEAD commit. None if git repo cannot be identified | ||
uncommitted_changes (str): | ||
Full text of any uncommitted changes. None if git repo cannot be | ||
identified. '' if no uncommitted changes present. | ||
|
||
""" | ||
|
||
# see if the editable install is pulling from a git repo | ||
path = os.path.split(os.path.split(EXOSIMS.__file__)[0])[0] | ||
gitdir = os.path.join(path, ".git") | ||
if not os.path.exists(gitdir): | ||
return None, None | ||
|
||
# grab current revision | ||
# comm = "git rev-parse HEAD" | ||
comm = ["git", f"--git-dir={gitdir}", f"--work-tree={path}", "rev-parse", "HEAD"] | ||
res = subprocess.run( | ||
comm, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
check=False, | ||
) | ||
|
||
if res.returncode != 0: | ||
return None, None | ||
|
||
gitrev = res.stdout.decode().strip() | ||
|
||
# Check for uncommitted changes | ||
# comm = "git diff HEAD" | ||
comm = ["git", f"--git-dir={gitdir}", f"--work-tree={path}", "diff", "HEAD"] | ||
res = subprocess.run( | ||
comm, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
check=False, | ||
) | ||
uncommitted_changes = res.stdout.decode() | ||
|
||
return gitrev, uncommitted_changes | ||
|
||
|
||
def is_editable_installation(): | ||
"""Check if EXOSIMS is installed in editable mode | ||
Args: | ||
None | ||
|
||
Returns: | ||
bool: | ||
True if EXOSIMS package installed in editable mode. Otherwise False. | ||
|
||
""" | ||
direct_url = metadata.Distribution.from_name("EXOSIMS").read_text("direct_url.json") | ||
if direct_url is None: | ||
return False | ||
else: | ||
direct_url = json.loads(direct_url) | ||
|
||
if "editable" in direct_url["dir_info"]: | ||
return direct_url["dir_info"]["editable"] | ||
else: | ||
return False | ||
|
||
|
||
def get_version(): | ||
VeronicaSergeeva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Retrieve the Python version and EXOSIMS version. | ||
Args: | ||
None | ||
|
||
Returns: | ||
dict: | ||
Dictonary containing keys 'Python Version', 'EXOSIMS Version', | ||
'Package Versions', and 'Editable Installation'. If EXOSIMS is installed | ||
in editable mode from a git repo, will also include the commit hash in | ||
keyword 'Git Commit'. If the repo contains any uncommitted changes, will | ||
contain full text of these in key 'Uncommitted Changes'. | ||
|
||
""" | ||
|
||
# Get basic versions | ||
python_version = platform.python_version() | ||
exosims_version = metadata.version("EXOSIMS") | ||
|
||
# Check required package versions | ||
reqs = metadata.distribution("EXOSIMS").requires | ||
required_packages = [str(req) for req in reqs] | ||
|
||
# Get installed versions of required packages | ||
installed_packages = { | ||
dist.metadata["Name"]: dist.version for dist in metadata.distributions() | ||
} | ||
|
||
# Filter installed packages to those listed in requirements | ||
relevant_packages = { | ||
pkg: installed_packages.get(pkg.split(">=")[0], "Not installed") | ||
for pkg in required_packages | ||
} | ||
|
||
# Check for editable installation | ||
editable = is_editable_installation() | ||
|
||
out = { | ||
"Python Version": python_version, | ||
"EXOSIMS Version": exosims_version, | ||
"Package Versions": relevant_packages, | ||
"Editable Installation": editable, | ||
} | ||
|
||
if editable: | ||
commit_hash, uncommitted_changes = get_git_info() | ||
if commit_hash is not None: | ||
out["Git Commit"] = commit_hash | ||
if uncommitted_changes != "": | ||
out["Uncommitted Changes"] = uncommitted_changes | ||
|
||
return out | ||
|
||
|
||
def print_version(): | ||
""" | ||
Print out full version information. | ||
""" | ||
version_info = get_version() | ||
for key, value in version_info.items(): | ||
if isinstance(value, dict): | ||
print(f"{key}:") | ||
for sub_key, sub_value in value.items(): | ||
print(f" {sub_key}:".ljust(25) + f"{sub_value}") | ||
else: | ||
print(f"{key}:".ljust(25) + f"{value}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
from importlib import metadata | ||
reqs = metadata.distribution('EXOSIMS').requires | ||
required_packages = [str(req).split('>=')[0] for req in reqs] | ||
|
||
with open('requirements.txt', 'r') as f: | ||
lines = f.readlines() | ||
|
||
for package in required_packages: | ||
flag = False | ||
for line in lines: | ||
if package in line: | ||
flag = True | ||
assert flag, f'{package} not found in requirements.txt' | ||
print(f'{package} found in requirements.txt') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.