-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
126 lines (109 loc) · 3.96 KB
/
setup.py
File metadata and controls
126 lines (109 loc) · 3.96 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
"""Create and manage DOIs using the DataCite API
This package provides a command line script to mint and manage
DataCite DOIs using the DataCite REST API.
"""
import setuptools
from setuptools import setup
import setuptools.command.build_py
import distutils.command.sdist
from distutils import log
from glob import glob
from pathlib import Path
import string
try:
import setuptools_scm
version = setuptools_scm.get_version()
except (ImportError, LookupError):
try:
import _meta
version = _meta.__version__
except ImportError:
log.warn("warning: cannot determine version number")
version = "UNKNOWN"
docstring = __doc__
class meta(setuptools.Command):
description = "generate meta files"
user_options = []
init_template = '''"""%(doc)s"""
__version__ = "%(version)s"
'''
meta_template = '''
__version__ = "%(version)s"
'''
def initialize_options(self):
self.package_dir = None
def finalize_options(self):
self.package_dir = {}
if self.distribution.package_dir:
for name, path in self.distribution.package_dir.items():
self.package_dir[name] = convert_path(path)
def run(self):
values = {
'version': self.distribution.get_version(),
'doc': docstring
}
try:
pkgname = self.distribution.packages[0]
except IndexError:
log.warn("warning: no package defined")
else:
pkgdir = Path(self.package_dir.get(pkgname, pkgname))
if not pkgdir.is_dir():
pkgdir.mkdir()
with (pkgdir / "__init__.py").open("wt") as f:
print(self.init_template % values, file=f)
with Path("_meta.py").open("wt") as f:
print(self.meta_template % values, file=f)
# Note: Do not use setuptools for making the source distribution,
# rather use the good old distutils instead.
# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/
class sdist(distutils.command.sdist.sdist):
def run(self):
self.run_command('meta')
super().run()
subst = {
"version": self.distribution.get_version(),
"url": self.distribution.get_url(),
"description": docstring.split("\n")[0],
"long_description": docstring.split("\n", maxsplit=2)[2].strip(),
}
for spec in glob("*.spec"):
with Path(spec).open('rt') as inf:
with Path(self.dist_dir, spec).open('wt') as outf:
outf.write(string.Template(inf.read()).substitute(subst))
class build_py(setuptools.command.build_py.build_py):
def run(self):
self.run_command('meta')
super().run()
with Path("README.rst").open("rt", encoding="utf8") as f:
readme = f.read()
setup(
name = "datacite",
version = version,
description = docstring.split("\n")[0],
long_description = readme,
url = "https://github.com/RKrahl/datacite",
author = "Rolf Krahl",
author_email = "rolf.krahl@helmholtz-berlin.de",
license = "Apache-2.0",
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
packages = ["datacite"],
scripts = ["scripts/datacite-doi.py", "scripts/datacite-validate-xml.py"],
python_requires = ">=3.4",
install_requires = ["keyring", "lxml", "requests", "PyYAML"],
cmdclass = dict(build_py=build_py, sdist=sdist, meta=meta),
)