Skip to content

Commit eeea3df

Browse files
authored
automated packaging in setup.py (#10)
1 parent eadf426 commit eeea3df

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[settings]
2-
known_third_party = arviz,matplotlib,numba,numpy,pandas,pandas_flavor,pymc,pytensor,pytest,scipy,sphinx_bootstrap_theme,tqdm
2+
known_third_party = arviz,matplotlib,numba,numpy,pandas,pandas_flavor,pymc,pytensor,pytest,scipy,setuptools,sphinx_bootstrap_theme,tqdm
33
multi_line_output = 3
44
include_trailing_comma = True
55
force_grid_wrap = 0

setup.py

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
# Copyright (C) 2019 Nicolas Legrand
2+
import codecs
23
import os
34

5+
from setuptools import setup
46

5-
def read(fname):
6-
return open(os.path.join(os.path.dirname(__file__), fname)).read()
7+
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
8+
REQUIREMENTS_FILE = os.path.join(PROJECT_ROOT, "requirements.txt")
79

810

9-
DESCRIPTION = "metadpy: Metacognitive efficiency modelling in Python"
10-
LONG_DESCRIPTION = (
11-
"Fitting behavioural and cognitive models of metacognitive efficiency in Python."
12-
)
11+
def get_requirements():
12+
with codecs.open(REQUIREMENTS_FILE) as buff:
13+
return buff.read().splitlines()
14+
15+
16+
# Get the package's version number of the __init__.py file
17+
def read(rel_path):
18+
"""Read the file located at the provided relative path."""
19+
here = os.path.abspath(os.path.dirname(__file__))
20+
with codecs.open(os.path.join(here, rel_path), "r") as fp:
21+
return fp.read()
22+
23+
24+
def get_version(rel_path):
25+
"""Get the package's version number.
26+
We fetch the version number from the `__version__` variable located in the
27+
package root's `__init__.py` file. This way there is only a single source
28+
of truth for the package's version number.
1329
30+
"""
31+
for line in read(rel_path).splitlines():
32+
if line.startswith("__version__"):
33+
delim = '"' if '"' in line else "'"
34+
return line.split(delim)[1]
35+
else:
36+
raise RuntimeError("Unable to find version string.")
37+
38+
39+
DESCRIPTION = "metadpy: Metacognitive efficiency modelling in Python"
1440
DISTNAME = "metadpy"
1541
MAINTAINER = "Nicolas Legrand"
1642
MAINTAINER_EMAIL = "nicolas.legrand@cas.au.dk"
1743
VERSION = "0.1.1"
1844

19-
INSTALL_REQUIRES = [
20-
"numpy>=1.18.1",
21-
"scipy>=1.3",
22-
"pandas>=0.24",
23-
"matplotlib>=3.1.3",
24-
"seaborn>=0.10.0",
25-
"pandas_flavor>=0.1.2",
26-
"numba>=0.55.1",
27-
]
28-
2945
PACKAGES = ["metadpy", "metadpy.datasets"]
3046

31-
try:
32-
from setuptools import setup
33-
34-
_has_setuptools = True
35-
except ImportError:
36-
from distutils.core import setup
3747

3848
if __name__ == "__main__":
3949

@@ -44,10 +54,11 @@ def read(fname):
4454
maintainer=MAINTAINER,
4555
maintainer_email=MAINTAINER_EMAIL,
4656
description=DESCRIPTION,
47-
long_description=LONG_DESCRIPTION,
57+
long_description=open("README.md", encoding="utf-8").read(),
58+
long_description_content_type="text/markdown",
4859
license="GPL-3.0",
49-
version=VERSION,
50-
install_requires=INSTALL_REQUIRES,
60+
version=get_version("metadpy/__init__.py"),
61+
install_requires=get_requirements(),
5162
include_package_data=True,
5263
packages=PACKAGES,
5364
)

0 commit comments

Comments
 (0)