From 8ce85d2582eaf9b3a169f9018241e9f5feed1ad0 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 19 Apr 2022 13:58:34 +0200 Subject: [PATCH 1/4] fix: package version this is a hybrid approach. previously we used bumpversion to bump the version and then appended the commithash to the `--version` output. as of 0.3.1, we used setuptools-scm to append the commit hash. however, setuptools-scm did not have a way to create multiple versions -- one for our `--version` output, and one for PKG-INFO. this commit uses setuptools-scm to automate the global (ex. v0.3.2) version string calculation, while using an auxiliary file to keep track of the commit hash for `--version`. --- .gitignore | 1 + setup.py | 24 ++++++++++++++++-------- vyper/__init__.py | 11 +++++++++++ vyper/cli/vyper_compile.py | 2 +- vyper/cli/vyper_ir.py | 2 +- vyper/cli/vyper_json.py | 2 +- vyper/cli/vyper_serve.py | 2 +- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 09a95debe2..14c4a5d0e8 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ docs/vyper.*.rst # vyper vyper/version.py +vyper/vyper_git_version.txt *.spec diff --git a/setup.py b/setup.py index 0830a9caf7..2ef681a46f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import re +import re, os, subprocess from setuptools import find_packages, setup @@ -40,14 +40,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): @@ -59,6 +54,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 + + setup( name="vyper", use_scm_version={ @@ -105,4 +112,5 @@ def _global_version(version): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", ], + data_files=[("", [hash_file_rel_path])], ) diff --git a/vyper/__init__.py b/vyper/__init__.py index f564a391e3..4b28eb72b0 100644 --- a/vyper/__init__.py +++ b/vyper/__init__.py @@ -1,5 +1,8 @@ from vyper.compiler import compile_code, compile_codes # noqa: F401 +from pathlib import Path as _Path + + try: from importlib.metadata import PackageNotFoundError # type: ignore from importlib.metadata import version as _version # type: ignore @@ -7,6 +10,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: diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 98e234f603..956cc0169f 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -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", diff --git a/vyper/cli/vyper_ir.py b/vyper/cli/vyper_ir.py index b524de2efa..76a8d25c97 100755 --- a/vyper/cli/vyper_ir.py +++ b/vyper/cli/vyper_ir.py @@ -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", diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 96258ab56d..556816fb4c 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -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", diff --git a/vyper/cli/vyper_serve.py b/vyper/cli/vyper_serve.py index 21ef6edf76..0fe0eead2c 100755 --- a/vyper/cli/vyper_serve.py +++ b/vyper/cli/vyper_serve.py @@ -18,7 +18,7 @@ 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", From 2a42fb18e314115a6d2c9bc0b05c2ff8b7eab980 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 19 Apr 2022 14:08:24 +0200 Subject: [PATCH 2/4] fix lint --- setup.py | 4 +++- vyper/__init__.py | 3 +-- vyper/cli/vyper_serve.py | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 2ef681a46f..de3baf064d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -import re, os, subprocess +import os +import re +import subprocess from setuptools import find_packages, setup diff --git a/vyper/__init__.py b/vyper/__init__.py index 4b28eb72b0..6650a8e08d 100644 --- a/vyper/__init__.py +++ b/vyper/__init__.py @@ -1,7 +1,6 @@ -from vyper.compiler import compile_code, compile_codes # noqa: F401 - from pathlib import Path as _Path +from vyper.compiler import compile_code, compile_codes # noqa: F401 try: from importlib.metadata import PackageNotFoundError # type: ignore diff --git a/vyper/cli/vyper_serve.py b/vyper/cli/vyper_serve.py index 0fe0eead2c..564e0d0110 100755 --- a/vyper/cli/vyper_serve.py +++ b/vyper/cli/vyper_serve.py @@ -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__}+commit{vyper.__commit__}") + 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", From 2f31a49730eed5ffca34ea4021e39d9ec9afab36 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 19 Apr 2022 17:50:35 +0200 Subject: [PATCH 3/4] add explanation for adding commit hash to package --- .gitignore | 1 + setup.py | 6 +++++- vyper/__init__.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 14c4a5d0e8..d138ad54d0 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ docs/vyper.*.rst # vyper vyper/version.py vyper/vyper_git_version.txt +vyper/vyper_git_commithash.txt *.spec diff --git a/setup.py b/setup.py index de3baf064d..fbbd0b1cc8 100644 --- a/setup.py +++ b/setup.py @@ -56,9 +56,13 @@ def _global_version(version): return re.sub(r"\.dev\d+", "", version_str) -hash_file_rel_path = os.path.join("vyper", "vyper_git_version.txt") +hash_file_rel_path = os.path.join("vyper", "vyper_git_commithash.txt") hashfile = os.path.relpath(hash_file_rel_path) +# there is no way in setuptools-scm to get metadata besides the package +# version into version.py. (and we need that version to be PEP440 compliant +# in order to get it into pypi). so, add the commit hash to the package +# separately, in order so that we can add it to `vyper --version`. try: commithash = subprocess.check_output("git rev-parse --short HEAD".split()) commithash_str = commithash.decode("utf-8").strip() diff --git a/vyper/__init__.py b/vyper/__init__.py index 6650a8e08d..35237bd044 100644 --- a/vyper/__init__.py +++ b/vyper/__init__.py @@ -9,7 +9,7 @@ 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") +_commit_hash_file = _Path(__file__).parent.joinpath("vyper_git_commithash.txt") if _commit_hash_file.exists(): with _commit_hash_file.open() as fp: From f4f7107923ae77b9db93a392414c5736599d8044 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 19 Apr 2022 17:50:35 +0200 Subject: [PATCH 4/4] add things to make clean even though we don't generate them anymore, they sometimes get generated when building old releases locally --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d62bc02993..daa1c2bfc9 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ clean-build: @rm -fr _build/ # docs build dir @rm -fr dist/ @rm -fr *.egg-info - @rm -f vyper/version.py + @rm -f vyper/version.py vyper/vyper_git_version.txt vyper/vyper_git_commithash.txt @rm -f *.spec clean-docs: