-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
55 lines (48 loc) · 2.07 KB
/
setup.py
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
#
# Copyright © 2025 Ernst Strüngmann Institute (ESI) for Neuroscience
# in Cooperation with Max Planck Society
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Builtins
import datetime
from setuptools import setup
from setuptools.config.setupcfg import read_configuration
import toml
# External packages
import yaml
# Manually set release version
releaseVersion = "2025.1"
# Read dependencies from setup.cfg + pyproject.toml and create conda environment file
envFile = "acme.yml"
setupOpts = read_configuration("setup.cfg")["options"]
tomlPkgs = toml.load("pyproject.toml")["build-system"]["requires"]
allPkgs = setupOpts["install_requires"] + setupOpts["extras_require"]["dev"] + tomlPkgs
pipPkgs = ["sphinx_automodapi"]
for k in range(len(pipPkgs)):
pkg = pipPkgs[k]
pipPkgs[k] = allPkgs.pop([allPkgs.index(dep) for dep in allPkgs if pkg in dep][0])
# Write conda environment file `envFile`
allPkgs += ["python " + str(setupOpts["python_requires"]), "pip", {"pip" : pipPkgs}]
ymlDict = {"name" : "acme",
"channels" : ["conda-forge"],
"dependencies" : allPkgs}
header = "#\n" +\
f"# Copyright © {datetime.datetime.now().strftime('%Y')} Ernst Strüngmann Institute (ESI) for Neuroscience " +\
"# in Cooperation with Max Planck Society\n#\n" +\
"# SPDX-License-Identifier: CC0-1.0\n#\n" +\
f"# This file was auto-generated by setup.py on {datetime.datetime.now().strftime('%d/%m/%Y at %H:%M:%S')}. \n" +\
"# Do not edit, all of your changes will be overwritten. \n"
with open(envFile, "w", encoding="utf8") as ymlFile:
ymlFile.write(header)
yaml.dump(ymlDict, ymlFile, default_flow_style=False)
# Update citation file
citationFile = "CITATION.cff"
with open(citationFile, "r", encoding="utf8") as ymlFile:
ymlObj = yaml.safe_load(ymlFile)
ymlObj["version"] = releaseVersion
ymlObj["date-released"] = datetime.datetime.now().strftime("%Y-%m-%d")
with open(citationFile, "w", encoding="utf8") as ymlFile:
yaml.dump(ymlObj, ymlFile)
# Run setup (note: identical arguments supplied in setup.cfg will take precedence)
setup(version=releaseVersion)