Skip to content

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherhesse committed Jan 15, 2022
1 parent 34ca8b6 commit 11bc8fe
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@
README = open(os.path.join(SCRIPT_DIR, "README.md"), "rb").read().decode("utf8")

# dynamically determine version number based on git commit
version = open(os.path.join(PACKAGE_ROOT, "version.txt"), "r").read().strip()
sha = "unknown"

try:
sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SCRIPT_DIR)
.decode("ascii")
.strip()
)
except Exception:
pass

if "GITHUB_REF" in os.environ:
ref = os.environ["GITHUB_REF"]
tag = ref.split("/")[-1]
print(f"ref={ref} tag={tag}")
assert tag == version, "mismatch in tag vs version, expected: %s actual: %s" % (
tag,
version,
)
elif sha != "unknown":
version += "+" + sha[:7]

def determine_version():
version = open(os.path.join(PACKAGE_ROOT, "version.txt"), "r").read().strip()
sha = "unknown"

try:
sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SCRIPT_DIR)
.decode("ascii")
.strip()
)
except Exception:
pass

if "GITHUB_REF" in os.environ:
ref = os.environ["GITHUB_REF"]
print(f"ref={ref}")
parts = ref.split("/")
assert parts[0] == "refs"
if parts[1] == "tags":
tag = parts[2]
assert tag == version, "mismatch in tag vs version, expected: %s actual: %s" % (
tag,
version,
)
return version
elif sha == "unknown":
return version
else:
return version + "+" + sha[:7]

version = determine_version()

# build shared library
class DummyExtension(Extension):
Expand Down

0 comments on commit 11bc8fe

Please sign in to comment.