File: setup.py

package info (click to toggle)
nmodl 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,992 kB
  • sloc: cpp: 28,492; javascript: 9,841; yacc: 2,804; python: 1,967; lex: 1,674; xml: 181; sh: 136; ansic: 37; makefile: 18; pascal: 7
file content (154 lines) | stat: -rw-r--r-- 4,824 bytes parent folder | download | duplicates (2)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# ***********************************************************************
# Copyright (C) 2018-2022 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
    """
    # If nbconvert is installed to .eggs on the fly when running setup.py then
    # templates from it will not be found. This is a workaround.
    if 'JUPYTER_PATH' not in os.environ:
        import nbconvert
        os.environ['JUPYTER_PATH'] = os.path.realpath(os.path.join(os.path.dirname(nbconvert.__file__), '..', 'share', 'jupyter'))
        print("Setting JUPYTER_PATH={}".format(os.environ['JUPYTER_PATH']))

    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]
if "bdist_wheel" in sys.argv:
    cmake_args.append("-DLINK_AGAINST_PYTHON=FALSE")
    cmake_args.append("-DNMODL_ENABLE_TESTS=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"]

# Parse long description from README.md
with open('README.md', 'r', encoding='utf-8') as f:
    long_description = f.read()

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=long_description,
    long_description_content_type='text/markdown',
    packages=["nmodl"],
    scripts=["pywheel/shim/nmodl", "pywheel/shim/find_libpython.py"],
    include_package_data=True,
    cmake_minimum_required_version="3.15.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-client",
        "jupyter",
        "myst_parser",
        "mistune<3",  # prevents a version conflict with nbconvert
        "nbconvert",
        "nbsphinx>=0.3.2",
        "pytest>=3.7.2",
        "sphinxcontrib-applehelp<1.0.3",
        "sphinxcontrib-htmlhelp<=2.0.0",
        "sphinx<6",
        "sphinx-rtd-theme",
    ]
    + install_requirements,
    install_requires=install_requirements,
)