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

fix: package version #2816

Merged
merged 4 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ docs/vyper.*.rst

# vyper
vyper/version.py
vyper/vyper_git_version.txt
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
*.spec
24 changes: 17 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

import os
import re
import subprocess

from setuptools import find_packages, setup

Expand Down Expand Up @@ -40,14 +42,9 @@
long_description = f.read()


# force commit hash to be appended to version even when tag is exact
# (breaks PEP 440, but this is the debug info, not the version tag for pypi)
# strip local version
def _local_version(version):
commithash = version.node[1:] # git describe adds 'g' prefix
ret = f"+commit.{commithash}"
if version.dirty:
ret += "-dirty"
return ret
return ""


def _global_version(version):
Expand All @@ -59,6 +56,18 @@ def _global_version(version):
return re.sub(r"\.dev\d+", "", version_str)


hash_file_rel_path = os.path.join("vyper", "vyper_git_version.txt")
hashfile = os.path.relpath(hash_file_rel_path)

try:
commithash = subprocess.check_output("git rev-parse --short HEAD".split())
commithash_str = commithash.decode("utf-8").strip()
with open(hashfile, "w") as fh:
fh.write(commithash_str)
except subprocess.CalledProcessError:
pass
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved


setup(
name="vyper",
use_scm_version={
Expand Down Expand Up @@ -105,4 +114,5 @@ def _global_version(version):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
data_files=[("", [hash_file_rel_path])],
)
10 changes: 10 additions & 0 deletions vyper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path as _Path

from vyper.compiler import compile_code, compile_codes # noqa: F401

try:
Expand All @@ -7,6 +9,14 @@
from importlib_metadata import PackageNotFoundError # type: ignore
from importlib_metadata import version as _version # type: ignore

_commit_hash_file = _Path(__file__).parent.joinpath("vyper_git_version.txt")

if _commit_hash_file.exists():
with _commit_hash_file.open() as fp:
__commit__ = fp.read()
else:
__commit__ = "unknown"

try:
__version__ = _version(__name__)
except PackageNotFoundError:
Expand Down
2 changes: 1 addition & 1 deletion vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _parse_args(argv):
parser.add_argument(
"--version",
action="version",
version=vyper.__version__,
version=f"{vyper.__version__}+commit.{vyper.__commit__}",
)
parser.add_argument(
"--show-gas-estimates",
Expand Down
2 changes: 1 addition & 1 deletion vyper/cli/vyper_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _parse_args(argv):
parser.add_argument(
"--version",
action="version",
version=f"{vyper.__version__}",
version=f"{vyper.__version__}+commit{vyper.__commit__}",
)
parser.add_argument(
"-f",
Expand Down
2 changes: 1 addition & 1 deletion vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _parse_args(argv):
parser.add_argument(
"--version",
action="version",
version=vyper.__version__,
version=f"{vyper.__version__}+commit.{vyper.__commit__}",
)
parser.add_argument(
"-o",
Expand Down
4 changes: 3 additions & 1 deletion vyper/cli/vyper_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def _parse_cli_args():

def _parse_args(argv):
parser = argparse.ArgumentParser(description="Serve Vyper compiler as an HTTP Service")
parser.add_argument("--version", action="version", version=f"{vyper.__version__}")
parser.add_argument(
"--version", action="version", version=f"{vyper.__version__}+commit{vyper.__commit__}"
)
parser.add_argument(
"-b",
help="Address to bind JSON server on, default: localhost:8000",
Expand Down