From eeea3df55828eb92b00834c53687d3ca5c091ce4 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Thu, 23 Mar 2023 10:39:28 +0100 Subject: [PATCH] automated packaging in setup.py (#10) --- .isort.cfg | 2 +- setup.py | 61 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/.isort.cfg b/.isort.cfg index b4f1f42..bb9c3e5 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,5 +1,5 @@ [settings] -known_third_party = arviz,matplotlib,numba,numpy,pandas,pandas_flavor,pymc,pytensor,pytest,scipy,sphinx_bootstrap_theme,tqdm +known_third_party = arviz,matplotlib,numba,numpy,pandas,pandas_flavor,pymc,pytensor,pytest,scipy,setuptools,sphinx_bootstrap_theme,tqdm multi_line_output = 3 include_trailing_comma = True force_grid_wrap = 0 diff --git a/setup.py b/setup.py index 2fd904c..840c15b 100644 --- a/setup.py +++ b/setup.py @@ -1,39 +1,49 @@ # Copyright (C) 2019 Nicolas Legrand +import codecs import os +from setuptools import setup -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() +PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) +REQUIREMENTS_FILE = os.path.join(PROJECT_ROOT, "requirements.txt") -DESCRIPTION = "metadpy: Metacognitive efficiency modelling in Python" -LONG_DESCRIPTION = ( - "Fitting behavioural and cognitive models of metacognitive efficiency in Python." -) +def get_requirements(): + with codecs.open(REQUIREMENTS_FILE) as buff: + return buff.read().splitlines() + + +# Get the package's version number of the __init__.py file +def read(rel_path): + """Read the file located at the provided relative path.""" + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, rel_path), "r") as fp: + return fp.read() + + +def get_version(rel_path): + """Get the package's version number. + We fetch the version number from the `__version__` variable located in the + package root's `__init__.py` file. This way there is only a single source + of truth for the package's version number. + """ + for line in read(rel_path).splitlines(): + if line.startswith("__version__"): + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + else: + raise RuntimeError("Unable to find version string.") + + +DESCRIPTION = "metadpy: Metacognitive efficiency modelling in Python" DISTNAME = "metadpy" MAINTAINER = "Nicolas Legrand" MAINTAINER_EMAIL = "nicolas.legrand@cas.au.dk" VERSION = "0.1.1" -INSTALL_REQUIRES = [ - "numpy>=1.18.1", - "scipy>=1.3", - "pandas>=0.24", - "matplotlib>=3.1.3", - "seaborn>=0.10.0", - "pandas_flavor>=0.1.2", - "numba>=0.55.1", -] - PACKAGES = ["metadpy", "metadpy.datasets"] -try: - from setuptools import setup - - _has_setuptools = True -except ImportError: - from distutils.core import setup if __name__ == "__main__": @@ -44,10 +54,11 @@ def read(fname): maintainer=MAINTAINER, maintainer_email=MAINTAINER_EMAIL, description=DESCRIPTION, - long_description=LONG_DESCRIPTION, + long_description=open("README.md", encoding="utf-8").read(), + long_description_content_type="text/markdown", license="GPL-3.0", - version=VERSION, - install_requires=INSTALL_REQUIRES, + version=get_version("metadpy/__init__.py"), + install_requires=get_requirements(), include_package_data=True, packages=PACKAGES, )