Skip to content

Commit

Permalink
fixing setup (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: code-review-doctor[bot] <72320148+code-review-doctor[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 13, 2023
1 parent 2877935 commit a2181a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
36 changes: 35 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import os
import re
import sys

try:
Expand All @@ -31,6 +32,23 @@
LOCAL_SOURCE = os.path.join("src", "gco_cpp")


try:
from importlib.util import module_from_spec, spec_from_file_location

def _load_py_module(module_name, location):
spec = spec_from_file_location(module_name, location)
py = module_from_spec(spec)
spec.loader.exec_module(py)
return py

except ImportError:
import imp

def _load_py_module(module_name, location):
py = imp.load_source(module_name, location)
return py


class BuildExt(build_ext):
"""build_ext command for use when numpy headers are needed.
SEE: https://stackoverflow.com/questions/2379898
Expand All @@ -57,22 +75,38 @@ def finalize_options(self):
if sys.version_info.major == 2:
# numpy v1.17 drops support for py2
SETUP_REQUIRES = INSTALL_REQUIRES = ["Cython>=0.23.1", "numpy>=1.8.2, <1.17"]
encode_kw = {}
else:
SETUP_REQUIRES = INSTALL_REQUIRES = ["Cython>=0.23.1", "numpy>=1.8.2"]
encode_kw = dict(encoding="utf_8")

ABOUT = _load_py_module(module_name="about", location=os.path.join("src", "gco", "__about__.py"))

with open("README.md", **encode_kw) as fp:
readme = re.sub(
# replace image pattern
pattern=r"\!\[([\w ]+)\]\(\./(.+)\)",
# with static urls and the same format
repl=r"![\1](https://raw.githubusercontent.com/borda/pyGCO/%s/\2)" % ABOUT.__version__,
# for whole README
string=fp.read(),
)

setup(
name="gco-wrapper",
url="http://vision.csd.uwo.ca/code/",
package_dir={"": "src"},
packages=find_packages(where="src"),
# edit also gco.__init__.py!
version="3.0.9",
version=ABOUT.__version__,
license="MIT",
author="Yujia Li & A. Mueller",
author_email="[email protected]",
maintainer="Jiri Borovec",
maintainer_email="[email protected]",
description="pyGCO: a python wrapper for the graph cuts package",
long_description=readme,
long_description_content_type="text/markdown",
download_url="https://github.com/Borda/pyGCO",
project_urls={
"Source Code": "https://github.com/Borda/pyGCO",
Expand Down
4 changes: 4 additions & 0 deletions src/gco/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__version__ = "3.0.9"
__version_info__ = tuple([int(i) for i in __version__.split(".")])

__all__ = ["__version__", "__version_info__"]
6 changes: 2 additions & 4 deletions src/gco/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# edit also setup.py!
__version__ = "3.0.8"
__version_info__ = tuple([int(i) for i in __version__.split(".")])

import numpy

from .__about__ import * # noqa: F403

# patch for numpy 1.24+
for name, tp in [("int", int), ("float", float), ("bool", bool)]:
if not hasattr(numpy, name):
Expand Down

0 comments on commit a2181a2

Please sign in to comment.