From ed2da774a02dcb264742a8fdd968fc498cab8eb2 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 24 Jul 2023 16:26:24 +0100
Subject: [PATCH] MNT: Replace setup.py with pyproject.toml

---
 COPYRIGHT              |   2 +-
 LICENSE                |   2 +-
 MANIFEST.in            |  13 +---
 pyproject.toml         | 111 +++++++++++++++++++++++++++++++++
 requirements-dev.txt   |   5 --
 requirements-extra.txt |   5 --
 requirements.txt       |   5 --
 setup.cfg              |  23 -------
 setup.py               | 137 -----------------------------------------
 9 files changed, 116 insertions(+), 187 deletions(-)
 create mode 100644 pyproject.toml
 delete mode 100644 requirements-dev.txt
 delete mode 100644 requirements-extra.txt
 delete mode 100644 requirements.txt
 delete mode 100644 setup.py

diff --git a/COPYRIGHT b/COPYRIGHT
index ca6e31789..ab5e5b029 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1 +1 @@
-Copyright 2016-2021 University of Oxford, Oxford, UK
+Copyright 2016-2023 University of Oxford, Oxford, UK
diff --git a/LICENSE b/LICENSE
index 29dca5745..785c943e8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The fslpy library
 
-Copyright 2016-2021 University of Oxford, Oxford, UK.
+Copyright 2016-2023 University of Oxford, Oxford, UK.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
diff --git a/MANIFEST.in b/MANIFEST.in
index b0332d964..60d1bd0ca 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,12 +1,5 @@
 include           AUTHOR
-include           LICENSE
-include           COPYRIGHT
 include           CHANGELOG.rst
-include           README.rst
-include           requirements.txt
-include           requirements-dev.txt
-include           requirements-extra.txt
-include           setup.cfg
-recursive-include doc      *
-recursive-exclude doc/html *
-recursive-include tests    *
+include           COPYRIGHT
+recursive-include doc   *
+recursive-include tests *
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 000000000..bf20ca7f4
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,111 @@
+[build-system]
+requires      = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+
+[project]
+name            = "fslpy"
+dynamic         = ["version"]
+description     = "FSL Python library"
+readme          = {file = "README.rst", content-type="text/x-rst"}
+license         = {text = "Apache License Version 2.0"}
+requires-python = ">=3.8"
+authors         = [{name = "Paul McCarthy", email = "pauldmccarthy@gmail.com"}]
+
+dependencies = [
+ "dill",
+ "h5py >=2.9",
+ "nibabel >=2.4",
+ "numpy >=1",
+ "scipy >=0.18"
+]
+
+classifiers = [
+  "Development Status :: 3 - Alpha",
+  "Intended Audience :: Developers",
+  "License :: OSI Approved :: Apache Software License",
+  "Programming Language :: Python :: 3.8",
+  "Programming Language :: Python :: 3.9",
+  "Programming Language :: Python :: 3.10",
+  "Programming Language :: Python :: 3.11",
+  "Topic :: Software Development :: Libraries :: Python Modules"
+]
+
+
+[project.urls]
+"Repository"    = "https://git.fmrib.ox.ac.uk/fsl/fslpy/"
+"Documentation" = "https://open.win.ox.ac.uk/pages/fsl/fslpy/"
+
+
+[project.optional-dependencies]
+extra = [
+  "indexed_gzip >=0.7",
+  "wxpython >=4",
+  "trimesh >=2.37.29",
+  "rtree >=0.8.3",
+  "Pillow >=3.2.0"
+]
+doc = [
+  "sphinx",
+  "sphinx_rtd_theme"
+]
+test = [
+  "pytest",
+  "coverage",
+  "pytest-cov",
+  "tomli; python_version < \"3.11\""
+]
+style = [
+  "pylint",
+  "flake8"
+]
+
+
+[project.scripts]
+imcp           = "fsl.scripts.imcp:main"
+imln           = "fsl.scripts.imln:main"
+immv           = "fsl.scripts.immv:main"
+imrm           = "fsl.scripts.imrm:main"
+imglob         = "fsl.scripts.imglob:main"
+imtest         = "fsl.scripts.imtest:main"
+remove_ext     = "fsl.scripts.remove_ext:main"
+fsl_abspath    = "fsl.scripts.fsl_abspath:main"
+Text2Vest      = "fsl.scripts.Text2Vest:main"
+Vest2Text      = "fsl.scripts.Vest2Text:main"
+atlasq         = "fsl.scripts.atlasq:main"
+atlasquery     = "fsl.scripts.atlasq:atlasquery_emulation"
+fsl_ents       = "fsl.scripts.fsl_ents:main"
+resample_image = "fsl.scripts.resample_image:main"
+fsl_convert_x5 = "fsl.scripts.fsl_convert_x5:main"
+fsl_apply_x5   = "fsl.scripts.fsl_apply_x5:main"
+
+
+[tool.setuptools.packages.find]
+include = ["fsl*"]
+
+
+[tool.setuptools.package-data]
+fsl = ["utils/filetree/trees/*"]
+
+
+[tool.setuptools.dynamic]
+version = {attr = "fsl.version.__version__"}
+
+
+[tool.coverage.run]
+include = ["fsl/*"]
+
+
+[tool.pytest.ini_options]
+testpaths = ["tests"]
+addopts   = "-v --cov=fsl --showlocals"
+markers   = [
+  "fsltest:    Requires FSL",
+  "wxtest:     Requires wxPython",
+  "dicomtest:  Requires dcm2niix",
+  "meshtest:   Requires trimesh and rtree",
+  "igziptest:  Requires indexed_gzip",
+  "piltest:    Requires Pillow",
+  "noroottest: Need to be executed as non-root user (will fail otherwise)",
+  "longtest:   Takes a long time",
+  "unixtest:   Only works on *nix systems"]
\ No newline at end of file
diff --git a/requirements-dev.txt b/requirements-dev.txt
deleted file mode 100644
index 0077afd5e..000000000
--- a/requirements-dev.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-sphinx
-sphinx_rtd_theme
-coverage
-pytest
-pytest-cov
diff --git a/requirements-extra.txt b/requirements-extra.txt
deleted file mode 100644
index 735bdaff4..000000000
--- a/requirements-extra.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-indexed_gzip>=0.7.0
-wxpython==4.*
-trimesh>=2.37.29
-rtree>=0.8.3
-Pillow>=3.2.0
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index d4f1b242f..000000000
--- a/requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-h5py>=2.9
-nibabel>=2.4
-numpy>=1
-scipy>=0.18
-dill
diff --git a/setup.cfg b/setup.cfg
index 59bf3d21a..2f1e33f90 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,25 +1,2 @@
-[aliases]
-test=pytest
-
-[bdist_wheel]
-universal=1
-
-[tool:pytest]
-markers =
-    fsltest:    Requires FSL
-    wxtest:     Requires wxPython
-    dicomtest:  Requires dcm2niix
-    meshtest:   Requires trimesh and rtree
-    igziptest:  Requires indexed_gzip
-    piltest:    Requires Pillow
-    noroottest: Need to be executed as non-root user (will fail otherwise)
-    longtest:   Takes a long time
-    unixtest:   Only works on *nix systems
-
-
-testpaths = tests
-addopts   = -v --cov=fsl -m "not longtest" --showlocals
-
-
 [flake8]
 ignore = E127,E201,E203,E221,E222,E241,E271,E272,E301,E302,E303,E701,W504
\ No newline at end of file
diff --git a/setup.py b/setup.py
deleted file mode 100644
index c588d8370..000000000
--- a/setup.py
+++ /dev/null
@@ -1,137 +0,0 @@
-#!/usr/bin/env python
-#
-# setup.py - setuptools configuration for installing the fslpy package.
-#
-# Author: Paul McCarthy <pauldmccarthy@gmail.com>
-#
-
-
-from __future__ import print_function
-
-import os.path       as op
-import                  shutil
-import unittest.mock as mock
-
-from setuptools import setup
-from setuptools import find_namespace_packages
-from setuptools import Command
-
-
-# The directory in which this setup.py file is contained.
-basedir = op.dirname(__file__)
-
-# Dependencies are listed in requirements.txt
-with open(op.join(basedir, 'requirements.txt'), 'rt') as f:
-    install_requires = [l.strip() for l in f.readlines()]
-
-# Optional dependencies are listed in requirements-extra.txt
-with open(op.join(basedir, 'requirements-extra.txt'), 'rt') as f:
-    extra_requires = {'extras' : [l.strip() for l in f.readlines()]}
-
-packages = find_namespace_packages(include=('fsl', 'fsl.*'))
-
-# Figure out the current fslpy version, as defined in fsl/version.py. We
-# don't want to import the fsl package,  as this may cause build problems.
-# So we manually parse the contents of fsl/version.py to extract the
-# version number.
-version = {}
-with open(op.join(basedir, "fsl", "version.py")) as f:
-    for line in f:
-        if line.startswith('__version__'):
-            exec(line, version)
-            break
-version = version['__version__']
-
-with open(op.join(basedir, 'README.rst'), 'rt') as f:
-    readme = f.read()
-
-
-class doc(Command):
-    """Build the API documentation. """
-
-    user_options = []
-
-    def initialize_options(self):
-        pass
-
-    def finalize_options(self):
-        pass
-
-    def run(self):
-
-        docdir  = op.join(basedir, 'doc')
-        destdir = op.join(docdir, 'html')
-
-        if op.exists(destdir):
-            shutil.rmtree(destdir)
-
-        print('Building documentation [{}]'.format(destdir))
-
-        import sphinx.cmd.build as sphinx_build
-
-        mockobj       = mock.MagicMock()
-        mockobj.__version__ = '2.2.0'
-        mockedModules = open(op.join(docdir, 'mock_modules.txt')).readlines()
-        mockedModules = [l.strip()   for l in mockedModules]
-        mockedModules = {m : mockobj for m in mockedModules}
-
-        patches = [mock.patch.dict('sys.modules', **mockedModules)]
-
-        [p.start() for p in patches]
-        sphinx_build.main([docdir, destdir])
-        [p.stop() for p in patches]
-
-
-setup(
-
-    name='fslpy',
-    version=version,
-    description='FSL Python library',
-    long_description=readme,
-    long_description_content_type='text/x-rst',
-    url='https://git.fmrib.ox.ac.uk/fsl/fslpy',
-    author='Paul McCarthy',
-    author_email='pauldmccarthy@gmail.com',
-    license='Apache License Version 2.0',
-    python_requires='>=3.7',
-
-    classifiers=[
-        'Development Status :: 3 - Alpha',
-        'Intended Audience :: Developers',
-        'License :: OSI Approved :: Apache Software License',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-        'Programming Language :: Python :: 3.9',
-        'Topic :: Software Development :: Libraries :: Python Modules'],
-
-    packages=packages,
-
-    install_requires=install_requires,
-    extras_require=extra_requires,
-    package_data={'fsl': ['utils/filetree/trees/*']},
-
-    test_suite='tests',
-
-    cmdclass={'doc' : doc},
-
-    entry_points={
-        'console_scripts' : [
-            'imcp           = fsl.scripts.imcp:main',
-            'imln           = fsl.scripts.imln:main',
-            'immv           = fsl.scripts.immv:main',
-            'imrm           = fsl.scripts.imrm:main',
-            'imglob         = fsl.scripts.imglob:main',
-            'imtest         = fsl.scripts.imtest:main',
-            'remove_ext     = fsl.scripts.remove_ext:main',
-            'fsl_abspath    = fsl.scripts.fsl_abspath:main',
-            'Text2Vest      = fsl.scripts.Text2Vest:main',
-            'Vest2Text      = fsl.scripts.Vest2Text:main',
-            'atlasq         = fsl.scripts.atlasq:main',
-            'atlasquery     = fsl.scripts.atlasq:atlasquery_emulation',
-            'fsl_ents       = fsl.scripts.fsl_ents:main',
-            'resample_image = fsl.scripts.resample_image:main',
-            'fsl_convert_x5 = fsl.scripts.fsl_convert_x5:main',
-            'fsl_apply_x5   = fsl.scripts.fsl_apply_x5:main'
-        ]
-    }
-)
-- 
GitLab