Skip to content
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

test build: turn on #28

Merged
merged 5 commits into from
Feb 15, 2021
Merged

test build: turn on #28

merged 5 commits into from
Feb 15, 2021

Conversation

pared
Copy link
Contributor

@pared pared commented Jan 15, 2021

No description provided.

@pared pared changed the title test build: turn on [WIP] test build: turn on Jan 15, 2021
@pared pared force-pushed the builds branch 2 times, most recently from 26dd93b to f05b7cf Compare February 5, 2021 11:38
Comment on lines +1 to +69
import os
import subprocess

_BASE_VERSION = "0.0.1"


def _generate_version(base_version):
"""Generate a version with information about the Git repository."""
pkg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

if not _is_git_repo(pkg_dir) or not _have_git():
return base_version

if _is_release(pkg_dir, base_version) and not _is_dirty(pkg_dir):
return base_version

return "{base_version}+{short_sha}{dirty}".format(
base_version=base_version,
short_sha=_git_revision(pkg_dir).decode("utf-8")[0:6],
dirty=".mod" if _is_dirty(pkg_dir) else "",
)


def _is_git_repo(dir_path):
"""Is the given directory version-controlled with Git?"""
return os.path.exists(os.path.join(dir_path, ".git"))


def _have_git():
"""Can we run the git executable?"""
try:
subprocess.check_output(["git", "--help"])
return True
except subprocess.CalledProcessError:
return False
except OSError:
return False


def _is_release(dir_path, base_version):
try:
output = subprocess.check_output(
["git", "describe", "--tags", "--exact-match"],
cwd=dir_path,
stderr=subprocess.STDOUT,
).decode("utf-8")
tag = output.strip()
return tag == base_version
except subprocess.CalledProcessError:
return False


def _git_revision(dir_path):
"""Get SHA of the HEAD of a Git repository."""
return subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=dir_path
).strip()


def _is_dirty(dir_path):
"""Check whether a git repository has uncommitted changes."""
try:
subprocess.check_call(["git", "diff", "--quiet"], cwd=dir_path)
return False
except subprocess.CalledProcessError:
return True


__version__ = _generate_version(_BASE_VERSION)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shamelessly stolen borrowed from https://github.com/iterative/dvc in order to maintain consistent versioning.

@efiop
Copy link
Contributor

efiop commented Feb 5, 2021

Btw, looks like you are missing https://github.com/iterative/dvc/blob/550cbb5e1154dff930b1cff33ee159bb16b03693/setup.py#L35 . That part generates the version file when you install the package, so you have a frozen version.

@pared pared merged commit bd1c776 into master Feb 15, 2021
@pared pared changed the title [WIP] test build: turn on test build: turn on Feb 15, 2021
@pared pared deleted the builds branch February 17, 2021 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants