From b77fef17bb91e4d443b5996589c36652047f7c98 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Tue, 16 Apr 2024 08:19:19 +0300 Subject: [PATCH 1/7] version file added --- python/hyperon/__init__.py | 16 +--------------- python/hyperon/__version__.py | 10 ++++++++++ python/pyproject.toml | 3 +++ 3 files changed, 14 insertions(+), 15 deletions(-) create mode 100644 python/hyperon/__version__.py diff --git a/python/hyperon/__init__.py b/python/hyperon/__init__.py index 9a7331003..58bf59a13 100644 --- a/python/hyperon/__init__.py +++ b/python/hyperon/__init__.py @@ -1,18 +1,4 @@ from .atoms import * from .base import * from .runner import * - -def _version(dist_name): - try: - import sys - if sys.version_info[:2] >= (3, 8): - # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` - from importlib.metadata import PackageNotFoundError, version # pragma: no cover - else: - from importlib_metadata import PackageNotFoundError, version # pragma: no cover - return version(dist_name) - except: - return "0.1.8+localbuild" - -__version__ = _version(__name__) - +from .__version__ import __version__ \ No newline at end of file diff --git a/python/hyperon/__version__.py b/python/hyperon/__version__.py new file mode 100644 index 000000000..3ebb30c9f --- /dev/null +++ b/python/hyperon/__version__.py @@ -0,0 +1,10 @@ +import subprocess + +def get_git_revision_short_hash() -> str: + return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + +def current_version(): + sha = get_git_revision_short_hash() + return '0.1.8'+'+'+sha + +__version__ = current_version() \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml index d63c9862a..45f880fd7 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -21,6 +21,9 @@ dependencies = [ ] dynamic = ["version"] +[tool.setuptools.dynamic] +version = {attr = "hyperon.__version__"} + [project.scripts] metta = "hyperon.metta:main" From 5c282858ee8191508d2b07e21cd66dea2ecee6a9 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Mon, 22 Apr 2024 11:43:08 +0300 Subject: [PATCH 2/7] current version --- python/hyperon/__version__.py | 11 +-------- python/pyproject.toml | 10 ++++---- python/setup.py | 45 ++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/python/hyperon/__version__.py b/python/hyperon/__version__.py index 3ebb30c9f..6a1481438 100644 --- a/python/hyperon/__version__.py +++ b/python/hyperon/__version__.py @@ -1,10 +1 @@ -import subprocess - -def get_git_revision_short_hash() -> str: - return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() - -def current_version(): - sha = get_git_revision_short_hash() - return '0.1.8'+'+'+sha - -__version__ = current_version() \ No newline at end of file +__version__ = '0.1.8' \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml index 45f880fd7..50b353847 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -19,10 +19,9 @@ classifiers = [ dependencies = [ 'importlib-metadata==6.6.0; python_version<"3.8"', ] -dynamic = ["version"] - -[tool.setuptools.dynamic] -version = {attr = "hyperon.__version__"} +dynamic = [ + "version", +] [project.scripts] metta = "hyperon.metta:main" @@ -46,5 +45,4 @@ test-command = "pytest {project}/python/tests" [tool.setuptools_scm] -root = '..' - +root = '..' \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index 4c8bd5cdc..37033265d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,4 +1,5 @@ import os +import codecs import sys import shutil import subprocess @@ -6,6 +7,35 @@ from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +import setuptools_scm as scm +import setuptools_scm.git as scmgit + +def get_git_revision_short_hash() -> str: + try: + sha = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + return f"+{sha}" + except Exception: + return '' + +def read(rel_path): + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, rel_path), 'r') as fp: + return fp.read() + +def get_version(rel_path): + new_ver = None + with open(rel_path) as f: lines = f.read().splitlines() + with open(rel_path, 'w') as f: + for line in lines: + if line.startswith('__version__'): + delim = '"' if '"' in line else "'" + new_ver = line.split(delim)[1].split("+")[0] + get_git_revision_short_hash() + f.write(line.replace(line.split(delim)[1], new_ver)) + else: + f.write(line) + if new_ver is None: + raise RuntimeError("Unable to find version string.") + return new_ver def resolve_path(path: str) -> str: return os.path.abspath(path) @@ -36,7 +66,6 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None: # Must be in this form due to bug in .resolve() only fixed in Python 3.10+ ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) extdir = ext_fullpath.parent.resolve() - debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug cfg = "Debug" if debug else "Release" @@ -71,7 +100,17 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None: ["cmake", "--build", ".", *build_args], cwd=build_temp, check=True ) + +def parse(root, config): + ver = scmgit.parse(root, config) + if (ver == '0.0') or (ver is None): + version = get_version("hyperon/__version__.py") + return scm.version.meta(tag=version, config=config, preformatted=True, dirty=True) + else: + return ver + setup( ext_modules=[CMakeExtension("hyperonpy")], - cmdclass={"build_ext": CMakeBuild} - ) + cmdclass={"build_ext": CMakeBuild}, + version=scm.get_version(parse=parse) + ) \ No newline at end of file From 695b99c367f585b546ccebd3973f620a8564044c Mon Sep 17 00:00:00 2001 From: Innokenty Date: Tue, 23 Apr 2024 11:49:59 +0300 Subject: [PATCH 3/7] parse -> version_scheme --- python/hyperon/__init__.py | 2 +- .../hyperon/{__version__.py => _version.py} | 0 python/pyproject.toml | 12 ++---- python/setup.py | 37 +++++-------------- 4 files changed, 13 insertions(+), 38 deletions(-) rename python/hyperon/{__version__.py => _version.py} (100%) diff --git a/python/hyperon/__init__.py b/python/hyperon/__init__.py index 58bf59a13..5ef3fdfdb 100644 --- a/python/hyperon/__init__.py +++ b/python/hyperon/__init__.py @@ -1,4 +1,4 @@ from .atoms import * from .base import * from .runner import * -from .__version__ import __version__ \ No newline at end of file +from ._version import __version__ \ No newline at end of file diff --git a/python/hyperon/__version__.py b/python/hyperon/_version.py similarity index 100% rename from python/hyperon/__version__.py rename to python/hyperon/_version.py diff --git a/python/pyproject.toml b/python/pyproject.toml index 50b353847..b1b8641ac 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools==65.6.3", "conan==1.62", "cmake==3.26.4", "setuptools_scm[toml]>=6.2"] +requires = ["setuptools==65.6.3", "conan==1.62", "cmake==3.26.4", "setuptools_scm[toml]>=8.0.0"] build-backend = "setuptools.build_meta" [project] @@ -16,9 +16,7 @@ classifiers = [ "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", ] -dependencies = [ - 'importlib-metadata==6.6.0; python_version<"3.8"', -] + dynamic = [ "version", ] @@ -41,8 +39,4 @@ before-all = "sh -c ./python/install-hyperonc.sh" # no Rust toolchain is available for musllinux-i686 environment skip = "*-musllinux_i686" test-requires = ["pytest==7.3.2"] -test-command = "pytest {project}/python/tests" - - -[tool.setuptools_scm] -root = '..' \ No newline at end of file +test-command = "pytest {project}/python/tests" \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index 37033265d..d030f5ab9 100644 --- a/python/setup.py +++ b/python/setup.py @@ -10,29 +10,13 @@ import setuptools_scm as scm import setuptools_scm.git as scmgit -def get_git_revision_short_hash() -> str: - try: - sha = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() - return f"+{sha}" - except Exception: - return '' - -def read(rel_path): - here = os.path.abspath(os.path.dirname(__file__)) - with codecs.open(os.path.join(here, rel_path), 'r') as fp: - return fp.read() - def get_version(rel_path): new_ver = None with open(rel_path) as f: lines = f.read().splitlines() - with open(rel_path, 'w') as f: - for line in lines: - if line.startswith('__version__'): - delim = '"' if '"' in line else "'" - new_ver = line.split(delim)[1].split("+")[0] + get_git_revision_short_hash() - f.write(line.replace(line.split(delim)[1], new_ver)) - else: - f.write(line) + for line in lines: + if line.startswith('__version__') and (not "str" in line): + delim = '"' if '"' in line else "'" + new_ver = line.split(delim)[1].split("+")[0] if new_ver is None: raise RuntimeError("Unable to find version string.") return new_ver @@ -101,16 +85,13 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None: ) -def parse(root, config): - ver = scmgit.parse(root, config) - if (ver == '0.0') or (ver is None): - version = get_version("hyperon/__version__.py") - return scm.version.meta(tag=version, config=config, preformatted=True, dirty=True) - else: - return ver +def version_scheme(version): + return get_version("hyperon/_version.py") setup( ext_modules=[CMakeExtension("hyperonpy")], cmdclass={"build_ext": CMakeBuild}, - version=scm.get_version(parse=parse) + use_scm_version={'root': '..', + 'version_scheme': version_scheme, + 'version_file': 'hyperon/_version.py'}, ) \ No newline at end of file From d495dce977b57edd15a84f7dddf4d5d3d5baa149 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Wed, 24 Apr 2024 09:10:47 +0300 Subject: [PATCH 4/7] version refactoring. Pre-test state --- VERSION | 1 + python/hyperon/__init__.py | 10 +++++++++- python/hyperon/_version.py | 2 +- python/setup.py | 26 ++++++++++---------------- 4 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..4ad8ec271 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +'0.1.8' \ No newline at end of file diff --git a/python/hyperon/__init__.py b/python/hyperon/__init__.py index 5ef3fdfdb..e88dca2de 100644 --- a/python/hyperon/__init__.py +++ b/python/hyperon/__init__.py @@ -1,4 +1,12 @@ from .atoms import * from .base import * from .runner import * -from ._version import __version__ \ No newline at end of file +from ._version import __version__ as _ver + +if _ver is None: + from pathlib import Path + path = Path(__file__).parent / "../../VERSION" + with path.open() as f: ver = f.read().splitlines()[0].split("'")[1] + __version__ = ver + "+localbuild" +else: + __version__ = _ver \ No newline at end of file diff --git a/python/hyperon/_version.py b/python/hyperon/_version.py index 6a1481438..c8ffb60db 100644 --- a/python/hyperon/_version.py +++ b/python/hyperon/_version.py @@ -1 +1 @@ -__version__ = '0.1.8' \ No newline at end of file +__version__ = None \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index d030f5ab9..e1e3917b7 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,5 +1,4 @@ import os -import codecs import sys import shutil import subprocess @@ -7,19 +6,6 @@ from setuptools import Extension, setup from setuptools.command.build_ext import build_ext -import setuptools_scm as scm -import setuptools_scm.git as scmgit - -def get_version(rel_path): - new_ver = None - with open(rel_path) as f: lines = f.read().splitlines() - for line in lines: - if line.startswith('__version__') and (not "str" in line): - delim = '"' if '"' in line else "'" - new_ver = line.split(delim)[1].split("+")[0] - if new_ver is None: - raise RuntimeError("Unable to find version string.") - return new_ver def resolve_path(path: str) -> str: return os.path.abspath(path) @@ -85,8 +71,16 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None: ) -def version_scheme(version): - return get_version("hyperon/_version.py") +def get_version(rel_path): + try: + with open(rel_path) as f: ver = f.read().splitlines()[0].split("'")[1] + return ver + except Exception: + print(f"Error reading file {rel_path}", file=sys.stderr) + + +def version_scheme(*args): + return get_version("../VERSION") setup( ext_modules=[CMakeExtension("hyperonpy")], From 07398547bc492a94fb25fd1cfdf890960b22d292 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Wed, 24 Apr 2024 09:12:40 +0300 Subject: [PATCH 5/7] _version.py to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2c61c02c1..343c55729 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Cargo.lock .DS_Store .vscode .aider* +./python/hyperon/_version.py From dea0e5d4e5abbdb856e30d9c6b5b8e2ae7c0b008 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Wed, 24 Apr 2024 10:07:06 +0300 Subject: [PATCH 6/7] post-test changes --- python/pyproject.toml | 2 +- python/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index b1b8641ac..240eb9b9e 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools==65.6.3", "conan==1.62", "cmake==3.26.4", "setuptools_scm[toml]>=8.0.0"] +requires = ["setuptools==65.6.3", "conan==1.62", "cmake==3.26.4", "setuptools_scm[toml]==7.1.0"] build-backend = "setuptools.build_meta" [project] diff --git a/python/setup.py b/python/setup.py index e1e3917b7..2111666a3 100644 --- a/python/setup.py +++ b/python/setup.py @@ -87,5 +87,5 @@ def version_scheme(*args): cmdclass={"build_ext": CMakeBuild}, use_scm_version={'root': '..', 'version_scheme': version_scheme, - 'version_file': 'hyperon/_version.py'}, + 'write_to': 'python/hyperon/_version.py'}, ) \ No newline at end of file From 4fdc486f1e9a8578f01293b2a3ebe9ae44f36ef3 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Wed, 24 Apr 2024 11:33:14 +0300 Subject: [PATCH 7/7] change VERSION folder and gitignore content --- .gitignore | 1 - python/.gitignore | 1 + VERSION => python/VERSION | 0 python/hyperon/__init__.py | 2 +- python/setup.py | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename VERSION => python/VERSION (100%) diff --git a/.gitignore b/.gitignore index 343c55729..2c61c02c1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ Cargo.lock .DS_Store .vscode .aider* -./python/hyperon/_version.py diff --git a/python/.gitignore b/python/.gitignore index 8e06918fd..537f6af29 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -5,3 +5,4 @@ __pycache__ /*.so /*.dylib /wheelhouse +/hyperon/_version.py diff --git a/VERSION b/python/VERSION similarity index 100% rename from VERSION rename to python/VERSION diff --git a/python/hyperon/__init__.py b/python/hyperon/__init__.py index e88dca2de..f6f9b7973 100644 --- a/python/hyperon/__init__.py +++ b/python/hyperon/__init__.py @@ -5,7 +5,7 @@ if _ver is None: from pathlib import Path - path = Path(__file__).parent / "../../VERSION" + path = Path(__file__).parent / "../VERSION" with path.open() as f: ver = f.read().splitlines()[0].split("'")[1] __version__ = ver + "+localbuild" else: diff --git a/python/setup.py b/python/setup.py index 2111666a3..cb320db4c 100644 --- a/python/setup.py +++ b/python/setup.py @@ -80,7 +80,7 @@ def get_version(rel_path): def version_scheme(*args): - return get_version("../VERSION") + return get_version("./VERSION") setup( ext_modules=[CMakeExtension("hyperonpy")],