Skip to content

Commit

Permalink
Merge pull request #667 from DaddyWesker/main
Browse files Browse the repository at this point in the history
Issue 662 solution, hyperon version refactor
  • Loading branch information
vsbogd authored Apr 24, 2024
2 parents bf95172 + 4ac8585 commit fbc5b5f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
/*.so
/*.dylib
/wheelhouse
/hyperon/_version.py
1 change: 1 addition & 0 deletions python/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'0.1.8'
22 changes: 8 additions & 14 deletions python/hyperon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from .atoms import *
from .base import *
from .runner import *
from ._version import __version__ as _ver

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__)

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
1 change: 1 addition & 0 deletions python/hyperon/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = None
15 changes: 5 additions & 10 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]==7.1.0"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -16,10 +16,10 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
]
dependencies = [
'importlib-metadata==6.6.0; python_version<"3.8"',

dynamic = [
"version",
]
dynamic = ["version"]

[project.scripts]
metta = "hyperon.metta:main"
Expand All @@ -39,9 +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 = '..'

test-command = "pytest {project}/python/tests"
20 changes: 17 additions & 3 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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"

Expand Down Expand Up @@ -71,7 +70,22 @@ def _build_with_cmake(self, ext: CMakeExtension) -> None:
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
)


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")],
cmdclass={"build_ext": CMakeBuild}
)
cmdclass={"build_ext": CMakeBuild},
use_scm_version={'root': '..',
'version_scheme': version_scheme,
'write_to': 'python/hyperon/_version.py'},
)

0 comments on commit fbc5b5f

Please sign in to comment.