Skip to content

Commit

Permalink
Various changes about versioning:
Browse files Browse the repository at this point in the history
  - use setuptools_scm to automatically set the correct setuptools version
    based on git tags

  - automatically generate hpy/universal/src/version.h at build time

  - introduce hpy.universal.get_version(). The idea is to introduce it also in
    the PyPy version: it will be useful to know which hpy revision we are
    targeting as soon as the pypy hpy branch gets merged and we start to do
    nightly builds
  • Loading branch information
antocuni committed Sep 8, 2020
1 parent 1ee0fcc commit 8a43ccd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# HPy autogen
hpy/tools/autogen/autogen_pypy.txt

# generated by setup.py:get_scm_config()
hpy/universal/src/version.h

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
6 changes: 6 additions & 0 deletions hpy/universal/src/hpymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "api.h"
#include "handles.h"
#include "version.h"

typedef HPy (*InitFuncPtr)(HPyContext ctx);

Expand Down Expand Up @@ -129,10 +130,15 @@ static PyObject *load_from_spec(PyObject *self, PyObject *spec)
return NULL;
}

static PyObject *get_version(PyObject *self, PyObject *ignored)
{
return Py_BuildValue("ss", HPY_VERSION, HPY_GIT_REVISION);
}

static PyMethodDef HPyMethods[] = {
{"set_debug", (PyCFunction)set_debug, METH_O, "TODO"},
{"load_from_spec", (PyCFunction)load_from_spec, METH_O, "Load a .hpy.so"},
{"get_version", (PyCFunction)get_version, METH_NOARGS, "Return a tuple ('version', 'git revision')"},
{NULL, NULL, 0, NULL}
};

Expand Down
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
else:
EXTRA_COMPILE_ARGS = []

def get_scm_config():
"""
We use this function as a hook to generate version.h before building.
"""
import textwrap
import subprocess
import pathlib
import setuptools_scm
version = setuptools_scm.get_version()
gitrev = subprocess.check_output('git describe --abbrev=7 --dirty '
'--always --tags --long'.split(), encoding='utf-8')
gitrev = gitrev.strip()
version_h = pathlib.Path('.').joinpath('hpy', 'universal', 'src', 'version.h')
version_h.write_text(textwrap.dedent(f"""
// automatically generated by setup.py:get_scm_config()
#define HPY_VERSION "{version}"
#define HPY_GIT_REVISION "{gitrev}"
"""))
return {} # use the default config

setup(
name="hpy.devel",
packages = ['hpy.devel'],
Expand Down Expand Up @@ -37,4 +57,6 @@
"hpy_ext_modules = hpy.devel:handle_hpy_ext_modules",
],
},
use_scm_version = get_scm_config,
setup_requires=['setuptools_scm'],
)
10 changes: 10 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

class TestBasic(HPyTest):

def test_get_version(self):
if self.compiler.hpy_abi != 'universal':
return
import hpy.universal
version, gitrev = hpy.universal.get_version()
# it's a bit hard to test the CONTENT of these values. Let's just
# check that they are strings...
assert isinstance(version, str)
assert isinstance(gitrev, str)

def test_empty_module(self):
import sys
mod = self.make_module("""
Expand Down

0 comments on commit 8a43ccd

Please sign in to comment.