This repository was archived by the owner on Mar 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.py
More file actions
139 lines (113 loc) · 4.16 KB
/
setup.py
File metadata and controls
139 lines (113 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# ***********************************************************************
# Copyright (C) 2018-2019 Blue Brain Project
#
# This file is part of NMODL distributed under the terms of the GNU
# Lesser General Public License. See top-level LICENSE file for details.
# ***********************************************************************
import inspect
import os
import subprocess
import sys
from setuptools import Command
from skbuild import setup
"""
A generic wrapper to access nmodl binaries from a python installation
Please create a softlink with the binary name to be called.
"""
import stat
from pkg_resources import working_set
from pywheel.shim.find_libpython import find_libpython
# Main source of the version. Dont rename, used by Cmake
try:
v = (
subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE)
.stdout.strip()
.decode()
)
__version__ = v[: v.rfind("-")].replace("-", ".") if "-" in v else v
# allow to override version during development/testing
if "NMODL_WHEEL_VERSION" in os.environ:
__version__ = os.environ['NMODL_WHEEL_VERSION']
except Exception as e:
raise RuntimeError("Could not get version from Git repo") from e
class lazy_dict(dict):
"""When the value associated to a key is a function, then returns
the function call instead of the function.
"""
def __getitem__(self, item):
value = dict.__getitem__(self, item)
if inspect.isfunction(value):
return value()
return value
def get_sphinx_command():
"""Lazy load of Sphinx distutils command class
"""
from sphinx.setup_command import BuildDoc
return BuildDoc
class Docs(Command):
description = "Generate & optionally upload documentation to docs server"
user_options = []
finalize_options = lambda self: None
initialize_options = lambda self: None
def run(self, *args, **kwargs):
self.run_command("doctest")
self.run_command("buildhtml")
def _config_exe(exe_name):
"""Sets the environment to run the real executable (returned)"""
package_name = "nmodl"
assert (
package_name in working_set.by_key
), "NMODL package not found! Verify PYTHONPATH"
NMODL_PREFIX = os.path.join(working_set.by_key[package_name].location, "nmodl")
NMODL_PREFIX_DATA = os.path.join(NMODL_PREFIX, ".data")
if sys.platform == "darwin":
os.environ["NMODL_WRAPLIB"] = os.path.join(
NMODL_PREFIX_DATA, "libpywrapper.dylib"
)
else:
os.environ["NMODL_WRAPLIB"] = os.path.join(NMODL_PREFIX_DATA, "libpywrapper.so")
# find libpython*.so in the system
os.environ["NMODL_PYLIB"] = find_libpython()
return os.path.join(NMODL_PREFIX_DATA, exe_name)
install_requirements = [
"PyYAML>=3.13",
"sympy>=1.3",
]
cmake_args = ["-DPYTHON_EXECUTABLE=" + sys.executable, "-DNMODL_ENABLE_LLVM=OFF", "-DNMODL_ENABLE_PYTHON_BINDINGS=ON"]
if "bdist_wheel" in sys.argv:
cmake_args.append("-DLINK_AGAINST_PYTHON=FALSE")
# For CI, we want to build separate wheel
package_name = "NMODL"
if "NMODL_NIGHTLY_TAG" in os.environ:
package_name += os.environ["NMODL_NIGHTLY_TAG"]
setup(
name=package_name,
version=__version__,
author="Blue Brain Project",
author_email="bbp-ou-hpc@groupes.epfl.ch",
description="NEURON Modeling Language Source-to-Source Compiler Framework",
long_description="",
packages=["nmodl"],
scripts=["pywheel/shim/nmodl", "pywheel/shim/find_libpython.py"],
include_package_data=True,
cmake_minimum_required_version="3.3.0",
cmake_args=cmake_args,
cmdclass=lazy_dict(
docs=Docs, doctest=get_sphinx_command, buildhtml=get_sphinx_command,
),
zip_safe=False,
setup_requires=[
"jinja2>=2.9.3",
"jupyter",
"m2r",
"mistune<2", # prevents a version conflict with nbconvert
"nbconvert<6.0", # prevents issues with nbsphinx
"nbsphinx>=0.3.2",
"pytest>=3.7.2",
"sphinx>=2.0",
"sphinx<3.0", # prevents issue with m2r where m2r uses an old API no more supported with sphinx>=3.0
"sphinx-rtd-theme",
]
+ install_requirements,
install_requires=install_requirements,
)