Skip to content

Commit

Permalink
Update versioneer and run cython from CMake (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
clonker authored Apr 11, 2022
1 parent 5397046 commit fcec08e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 46 deletions.
5 changes: 2 additions & 3 deletions deeptime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
from . import _version
__version__ = _version.get_versions()['version']

from . import util
from . import numeric
Expand Down
28 changes: 21 additions & 7 deletions deeptime/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# that just contains the computed version number.

# This file is released into the public domain. Generated by
# versioneer-0.21 (https://github.com/python-versioneer/python-versioneer)
# versioneer-0.22 (https://github.com/python-versioneer/python-versioneer)

"""Git implementation of _version.py."""

Expand All @@ -16,6 +16,7 @@
import subprocess
import sys
from typing import Callable, Dict
import functools


def get_keywords():
Expand Down Expand Up @@ -73,14 +74,22 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
"""Call the given command(s)."""
assert isinstance(commands, list)
process = None

popen_kwargs = {}
if sys.platform == "win32":
# This hides the console window if pythonw.exe is used
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
popen_kwargs["startupinfo"] = startupinfo

for command in commands:
try:
dispcmd = str([command] + args)
# remember shell=False, so use git.cmd on windows, not just git
process = subprocess.Popen([command] + args, cwd=cwd, env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
else None), **popen_kwargs)
break
except OSError:
e = sys.exc_info()[1]
Expand Down Expand Up @@ -228,10 +237,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
version string, meaning we're inside a checked out source tree.
"""
GITS = ["git"]
TAG_PREFIX_REGEX = "*"
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
TAG_PREFIX_REGEX = r"\*"

# GIT_DIR can interfere with correct operation of Versioneer.
# It may be intended to be passed to the Versioneer-versioned project,
# but that should not change where we get our version from.
env = os.environ.copy()
env.pop("GIT_DIR", None)
runner = functools.partial(runner, env=env)

_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
hide_stderr=True)
Expand All @@ -240,12 +254,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
print("Directory %s not under git control" % root)
raise NotThisMethod("'git rev-parse --git-dir' returned error")

MATCH_ARGS = ["--match", "%s*" % tag_prefix] if tag_prefix else []

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = runner(GITS, ["describe", "--tags", "--dirty",
"--always", "--long",
"--match",
"%s%s" % (tag_prefix, TAG_PREFIX_REGEX)],
"--always", "--long", *MATCH_ARGS],
cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
Expand Down
10 changes: 10 additions & 0 deletions deeptime/numeric/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ project(_numeric_bindings CXX)

set(SRC src/numeric_module.cpp)
register_pybind_module(${PROJECT_NAME} ${SRC})

find_package(Cython)
if(Cython_FOUND)
find_package(PythonExtensions REQUIRED)
add_cython_target(eig_qr eig_qr.pyx)
add_library(eig_qr MODULE ${eig_qr})
python_extension_module(eig_qr)
file(RELATIVE_PATH REL_PATH "${DEEPTIME_ROOT_DIRECTORY}/deeptime" "${CMAKE_CURRENT_LIST_DIR}")
install(TARGETS eig_qr DESTINATION ${REL_PATH})
endif()
22 changes: 4 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# based on https://github.com/pybind/scikit_build_example/blob/master/setup.py

import os
import re
from pathlib import Path

import sys
import toml

from setuptools import find_packages, Extension
from Cython.Build import cythonize
from setuptools import find_packages
import toml

sys.path.insert(0, os.path.dirname(__file__))
import versioneer
Expand All @@ -25,13 +21,6 @@
pyproject = toml.load("pyproject.toml")


def eig_qr_extension():
module_name = 'deeptime.numeric.eig_qr'
sources = ["/".join(module_name.split(".")) + '.pyx']
return cythonize([Extension(module_name, sources=sources, extra_compile_args=['-std=c99'])],
compiler_directives={'language_level': '3'})[0]


def load_long_description():
with open(pyproject["project"]["readme"], mode='r', encoding="utf-8") as f:
return f.read()
Expand Down Expand Up @@ -61,12 +50,9 @@ def load_long_description():
cmake_args=cmake_args,
include_package_data=True,
python_requires=pyproject["project"]["requires-python"],
ext_modules=[eig_qr_extension()]
ext_modules=[],
cmdclass=versioneer.get_cmdclass()
)

if __name__ == '__main__':
# see issue https://github.com/scikit-build/scikit-build/issues/521
# invalidates _skbuild cache
for i in (Path(__file__).resolve().parent / "_skbuild").rglob("CMakeCache.txt"):
i.write_text(re.sub("^//.*$\n^[^#].*pip-build-env.*$", "", i.read_text(), flags=re.M))
setup(**metadata)
67 changes: 49 additions & 18 deletions versioneer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Version: 0.21
# Version: 0.22

"""The Versioneer - like a rocketeer, but for versions.
Expand All @@ -10,11 +10,11 @@
* https://github.com/python-versioneer/python-versioneer
* Brian Warner
* License: Public Domain
* Compatible with: Python 3.6, 3.7, 3.8, 3.9 and pypy3
* Compatible with: Python 3.6, 3.7, 3.8, 3.9, 3.10 and pypy3
* [![Latest Version][pypi-image]][pypi-url]
* [![Build Status][travis-image]][travis-url]
This is a tool for managing a recorded version number in distutils-based
This is a tool for managing a recorded version number in distutils/setuptools-based
python projects. The goal is to remove the tedious and error-prone "update
the embedded version string" step from your release process. Making a new
release should be as easy as recording a new tag in your version-control
Expand Down Expand Up @@ -288,6 +288,7 @@
import subprocess
import sys
from typing import Callable, Dict
import functools


class VersioneerConfig:
Expand Down Expand Up @@ -384,14 +385,22 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
"""Call the given command(s)."""
assert isinstance(commands, list)
process = None

popen_kwargs = {}
if sys.platform == "win32":
# This hides the console window if pythonw.exe is used
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
popen_kwargs["startupinfo"] = startupinfo

for command in commands:
try:
dispcmd = str([command] + args)
# remember shell=False, so use git.cmd on windows, not just git
process = subprocess.Popen([command] + args, cwd=cwd, env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
else None), **popen_kwargs)
break
except OSError:
e = sys.exc_info()[1]
Expand Down Expand Up @@ -422,7 +431,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
# that just contains the computed version number.
# This file is released into the public domain. Generated by
# versioneer-0.21 (https://github.com/python-versioneer/python-versioneer)
# versioneer-0.22 (https://github.com/python-versioneer/python-versioneer)
"""Git implementation of _version.py."""
Expand All @@ -432,6 +441,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
import subprocess
import sys
from typing import Callable, Dict
import functools
def get_keywords():
Expand Down Expand Up @@ -489,14 +499,22 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
"""Call the given command(s)."""
assert isinstance(commands, list)
process = None
popen_kwargs = {}
if sys.platform == "win32":
# This hides the console window if pythonw.exe is used
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
popen_kwargs["startupinfo"] = startupinfo
for command in commands:
try:
dispcmd = str([command] + args)
# remember shell=False, so use git.cmd on windows, not just git
process = subprocess.Popen([command] + args, cwd=cwd, env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
else None), **popen_kwargs)
break
except OSError:
e = sys.exc_info()[1]
Expand Down Expand Up @@ -644,10 +662,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
version string, meaning we're inside a checked out source tree.
"""
GITS = ["git"]
TAG_PREFIX_REGEX = "*"
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
TAG_PREFIX_REGEX = r"\*"
# GIT_DIR can interfere with correct operation of Versioneer.
# It may be intended to be passed to the Versioneer-versioned project,
# but that should not change where we get our version from.
env = os.environ.copy()
env.pop("GIT_DIR", None)
runner = functools.partial(runner, env=env)
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
hide_stderr=True)
Expand All @@ -656,12 +679,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
print("Directory %%s not under git control" %% root)
raise NotThisMethod("'git rev-parse --git-dir' returned error")
MATCH_ARGS = ["--match", "%%s*" %% tag_prefix] if tag_prefix else []
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = runner(GITS, ["describe", "--tags", "--dirty",
"--always", "--long",
"--match",
"%%s%%s" %% (tag_prefix, TAG_PREFIX_REGEX)],
"--always", "--long", *MATCH_ARGS],
cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
Expand Down Expand Up @@ -1162,10 +1185,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
version string, meaning we're inside a checked out source tree.
"""
GITS = ["git"]
TAG_PREFIX_REGEX = "*"
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
TAG_PREFIX_REGEX = r"\*"

# GIT_DIR can interfere with correct operation of Versioneer.
# It may be intended to be passed to the Versioneer-versioned project,
# but that should not change where we get our version from.
env = os.environ.copy()
env.pop("GIT_DIR", None)
runner = functools.partial(runner, env=env)

_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
hide_stderr=True)
Expand All @@ -1174,12 +1202,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
print("Directory %s not under git control" % root)
raise NotThisMethod("'git rev-parse --git-dir' returned error")

MATCH_ARGS = ["--match", "%s*" % tag_prefix] if tag_prefix else []

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = runner(GITS, ["describe", "--tags", "--dirty",
"--always", "--long",
"--match",
"%s%s" % (tag_prefix, TAG_PREFIX_REGEX)],
"--always", "--long", *MATCH_ARGS],
cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
Expand Down Expand Up @@ -1344,7 +1372,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):


SHORT_VERSION_PY = """
# This file was generated by 'versioneer.py' (0.21) from
# This file was generated by 'versioneer.py' (0.22) from
# revision-control system data, or from the parent directory name of an
# unpacked source archive. Distribution tarballs contain a pre-generated copy
# of this file.
Expand Down Expand Up @@ -1748,7 +1776,10 @@ def get_cmdclass(cmdclass=None):
cmds = {} if cmdclass is None else cmdclass.copy()

# we add "version" to both distutils and setuptools
from distutils.core import Command
try:
from setuptools import Command
except ImportError:
from distutils.core import Command

class cmd_version(Command):
description = "report generated version string"
Expand Down

0 comments on commit fcec08e

Please sign in to comment.