setup.py 2.89 KB
Newer Older
Bas Nijholt's avatar
Bas Nijholt committed
1
#!/usr/bin/env python3
Bas Nijholt's avatar
Bas Nijholt committed
2
import json
3
import os
4
5
import sys
from importlib.util import module_from_spec, spec_from_file_location
6

Bas Nijholt's avatar
Bas Nijholt committed
7
8
9
import setuptools.command.develop
from setuptools import find_packages, setup

10

11
12
13
14
15
16
17
18
# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()


Joseph Weston's avatar
Joseph Weston committed
19
20
# Loads version.py module without importing the whole package.
def get_version_and_cmdclass(package_path):
Bas Nijholt's avatar
Bas Nijholt committed
21
    spec = spec_from_file_location("version", os.path.join(package_path, "_version.py"))
Joseph Weston's avatar
Joseph Weston committed
22
23
24
25
26
    module = module_from_spec(spec)
    spec.loader.exec_module(module)
    return module.__version__, module.cmdclass


Bas Nijholt's avatar
Bas Nijholt committed
27
version, cmdclass = get_version_and_cmdclass("semicon")
28

29
30

def import_submodule(path, name):
Bas Nijholt's avatar
Bas Nijholt committed
31
    spec = spec_from_file_location(name, os.path.join(path, name + ".py"))
32
33
34
35
36
    module = module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


Joseph Weston's avatar
Joseph Weston committed
37
def build_cache(dir):
Bas Nijholt's avatar
Bas Nijholt committed
38
39
40
    print("building model cache")
    sys.path.append("semicon")
    from kp_models import explicit_foreman, explicit_zeeman
Joseph Weston's avatar
Joseph Weston committed
41

Bas Nijholt's avatar
Bas Nijholt committed
42
43
44
45
46
    sys.path.pop()
    data = {
        "foreman": str(explicit_foreman.foreman),
        "zeeman": str(explicit_zeeman.zeeman),
    }
Joseph Weston's avatar
Joseph Weston committed
47

Bas Nijholt's avatar
Bas Nijholt committed
48
49
50
    cache_file = os.path.join(dir, "semicon", "model_cache.json")
    with open(cache_file, "w") as f:
        json.dump(data, f)
Joseph Weston's avatar
Joseph Weston committed
51

Joseph Weston's avatar
Joseph Weston committed
52

Bas Nijholt's avatar
Bas Nijholt committed
53
54
# Build model cache from 'kp_models' package
class build_py(cmdclass["build_py"]):
Joseph Weston's avatar
Joseph Weston committed
55
56
57
58
59
60
61
62
63
    def run(self):
        # make sure we run the miniver stuff
        super().run()
        build_cache(self.build_lib)


class develop(setuptools.command.develop.develop):
    def run(self):
        super().run()
64
        build_cache(".")
Joseph Weston's avatar
Joseph Weston committed
65
66


Bas Nijholt's avatar
Bas Nijholt committed
67
68
cmdclass["build_py"] = build_py
cmdclass["develop"] = develop
Joseph Weston's avatar
Joseph Weston committed
69

70
71
72
73
74
75
76
77
78
79
80
81
classifiers = """\
    Development Status :: 3 - Alpha
    Intended Audience :: Science/Research
    Intended Audience :: Developers
    Programming Language :: Python :: 3 :: Only
    Topic :: Software Development
    Topic :: Scientific/Engineering
    Operating System :: POSIX
    Operating System :: Unix"""

setup(
    name="semicon",
Joseph Weston's avatar
Joseph Weston committed
82
    version=version,
Bas Nijholt's avatar
Bas Nijholt committed
83
84
    author="R.J. Skolasinski",
    author_email="r.j.skolasinski@gmail.com",
Joseph Weston's avatar
Joseph Weston committed
85
    description=("Package for simulating quantum mechanical k·p Hamiltonians"),
86
87
88
    license="BSD",
    long_description=read("README.md"),
    platforms=["Unix", "Linux"],
89
    url="https://gitlab.kwant-project.org/semicon/semicon",
Bas Nijholt's avatar
Bas Nijholt committed
90
91
92
    packages=find_packages("."),
    package_data={"semicon": ["databank/*.yml"]},
    setup_requires=["sympy >= 1.2"],
93
    install_requires=[
Bas Nijholt's avatar
Bas Nijholt committed
94
95
96
97
98
99
        "sympy >= 1.2",
        "scipy >= 1.1.0",
        "pandas >= 0.23.3",
        "numpy >= 1.14.5",
        "kwant >= 1.4",
        "pyyaml",
100
    ],
Bas Nijholt's avatar
Bas Nijholt committed
101
    classifiers=[c.strip() for c in classifiers.split("\n")],
Joseph Weston's avatar
Joseph Weston committed
102
    cmdclass=cmdclass,
103
)