setup.find_meta()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
from codecs import open
2
from os import path
3
import re
4
# Always prefer setuptools over distutils
5
from setuptools import find_packages, setup
6
from subprocess import check_call
7
from setuptools import Extension
8
9
name = "nrlmsise00"
10
meta_path = path.join("src", name, "__init__.py")
11
here = path.abspath(path.dirname(__file__))
12
13
extnrlmsise00 = Extension(
14
		name="nrlmsise00._nrlmsise00",
15
		sources=[
16
			"src/nrlmsise00/nrlmsise00module.c",
17
			"src/c_nrlmsise-00/nrlmsise-00.c",
18
			"src/c_nrlmsise-00/nrlmsise-00_data.c"
19
		],
20
		include_dirs=["src/c_nrlmsise-00"])
21
22
extras_require = {
23
		"tests": ["pytest"],
24
		"dataset": ["spaceweather", "xarray"],
25
		"docs": ["sphinx!=3.2.0"],
26
}
27
extras_require["all"] = sorted(
28
		{v for req in extras_require.values() for v in req})
29
30
31
# Approach taken from
32
# https://packaging.python.org/guides/single-sourcing-package-version/
33
# and the `attrs` package https://www.attrs.org/
34
# https://github.com/python-attrs/attrs
35
def read(*parts):
36
	"""
37
	Builds an absolute path from *parts* and and return the contents of the
38
	resulting file.  Assumes UTF-8 encoding.
39
	"""
40
	with open(path.join(here, *parts), "rb", "utf-8") as f:
41
		return f.read()
42
43
44
def find_meta(meta, *path):
45
	"""
46
	Extract __*meta*__ from *path* (can have multiple components)
47
	"""
48
	meta_file = read(*path)
49
	meta_match = re.search(
50
		r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), meta_file, re.M
51
	)
52
	if not meta_match:
53
		raise RuntimeError("__{meta}__ string not found.".format(meta=meta))
54
	return meta_match.group(1)
55
56
57
# Get the long description from the README file
58
long_description = read("README.md")
59
version = find_meta("version", meta_path)
60
61
if __name__ == "__main__":
62
	# update git submodules
63
	if path.exists(".git"):
64
		check_call(["git", "submodule", "update", "--init", "--recursive"])
65
66
	setup(name=name,
67
		version=version,
68
		description="Python interface for the NRLMSISE-00 neutral atmosphere model",
69
		long_description=long_description,
70
		long_description_content_type="text/markdown",
71
		keywords="atmosphere earth model python-interface",
72
		author="Stefan Bender",
73
		author_email="[email protected]",
74
		url="https://github.com/st-bender/pynrlmsise00",
75
		project_urls={
76
			"Documentation": "https://pynrlmsise00.readthedocs.io",
77
		},
78
		license="GPLv2",
79
		classifiers=[
80
			"Development Status :: 4 - Beta",
81
			"Intended Audience :: Science/Research",
82
			"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
83
			"Operating System :: MacOS :: MacOS X",
84
			"Operating System :: Microsoft :: Windows",
85
			"Operating System :: POSIX :: Linux",
86
			"Programming Language :: Python",
87
			"Programming Language :: Python :: 2",
88
			"Programming Language :: Python :: 3",
89
			'Programming Language :: Python :: Implementation :: CPython',
90
			'Topic :: Scientific/Engineering :: Physics',
91
			'Topic :: Utilities',
92
		],
93
		packages=find_packages("src"),
94
		package_dir={"": "src"},
95
		package_data={},
96
		install_requires=[
97
			"numpy>=1.13.0",
98
		],
99
		extras_require=extras_require,
100
		ext_modules=[extnrlmsise00],
101
		scripts=[],
102
		entry_points={},
103
		zip_safe=False)
104