Skip to content

Commit

Permalink
Merge pull request #186 from ctlearn-project/testalex
Browse files Browse the repository at this point in the history
CI error fix
  • Loading branch information
nietootein authored May 24, 2024
2 parents 88d3afe + e7c33c1 commit bd0092f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04]
pyv: [3.9, '3.10']
pyv: [3.9, '3.10', 3.11, 3.12]
max-parallel: 5
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.pyv }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.pyv }}
run: |
conda install -y python=${{ matrix.pyv }}
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
Expand Down
33 changes: 22 additions & 11 deletions ctlearn/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
but being much more lightwheight
"""
from subprocess import check_output, CalledProcessError
from subprocess import check_output, CalledProcessError, run, PIPE
from os import path, name, devnull, environ, listdir
from ast import literal_eval

Expand Down Expand Up @@ -78,23 +78,36 @@ def find_git_on_windows():
GIT_COMMAND = find_git_on_windows()


def get_current_version():
"""
Given a repository, list all tags for that repository
without cloning it and get the current version.
"""
result = run([
"git", "ls-remote", "--tags"
], stdout= PIPE, text=True)

output_lines = result.stdout.splitlines()

tags = [
line.split("refs/tags/")[-1] for line in output_lines
if "refs/tags/" in line and "^{}" not in line

]
last_tag = tags[-1][1:]
return last_tag


def get_git_describe_version(abbrev=7):
"""return the string output of git desribe"""
try:
with open(devnull, "w") as fnull:
arguments = [GIT_COMMAND, "describe", "--tags", "--abbrev=%d" % abbrev]
return (
check_output(arguments, cwd=CURRENT_DIRECTORY, stderr=fnull)
.decode("ascii")
.strip()
)
return get_current_version()
except (OSError, CalledProcessError):
return None


def format_git_describe(git_str, pep440=False):
"""format the result of calling 'git describe' as a python version"""

if "-" not in git_str: # currently at a tag
formatted_str = git_str
else:
Expand Down Expand Up @@ -158,11 +171,9 @@ def get_version(pep440=False):
The file VERSION will need to be changed manually.
"""

raw_git_version = get_git_describe_version()
if not raw_git_version: # not a git repository
return read_release_version()

git_version = format_git_describe(raw_git_version, pep440=pep440)

return git_version
Expand Down

0 comments on commit bd0092f

Please sign in to comment.