From cb6e34228685d7d21ed6fb946fe63d9c1d607120 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 22 Jul 2024 19:02:54 -0400 Subject: [PATCH] ENH: Use hatch and automated releases (#566) --- .github/workflows/release.yml | 49 ++++++++++++++++++++++ mne_nirs/__init__.py | 9 ++++- mne_nirs/_version.py | 1 - mne_nirs/io/snirf/_snirf.py | 6 ++- pyproject.toml | 71 ++++++++++++++++++++++++++++++++ setup.py | 76 ----------------------------------- 6 files changed, 132 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 mne_nirs/_version.py delete mode 100644 setup.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..506b65cb7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +# Upload a Python Package using Twine when a release is created + +name: Build +on: # yamllint disable-line rule:truthy + release: + types: [published] + push: + branches: ["main", "maint/*"] + pull_request: + branches: ["main", "maint/*"] + +permissions: + contents: read + +jobs: + package: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + - run: python -m build --sdist --wheel + - run: twine check --strict dist/* + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist + + pypi-upload: + needs: package + runs-on: ubuntu-latest + if: github.event_name == 'release' + permissions: + id-token: write # for trusted publishing + environment: + name: pypi + url: https://pypi.org/p/mne-nirs + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1 + if: github.event_name == 'release' diff --git a/mne_nirs/__init__.py b/mne_nirs/__init__.py index a8a5aabf4..706931e7e 100644 --- a/mne_nirs/__init__.py +++ b/mne_nirs/__init__.py @@ -1,4 +1,11 @@ -from ._version import __version__ +from importlib.metadata import version + +try: + __version__ = version("mne-nirs") +except Exception: + __version__ = "0.0.0" +del version + from . import channels from . import datasets diff --git a/mne_nirs/_version.py b/mne_nirs/_version.py deleted file mode 100644 index c6ca120a9..000000000 --- a/mne_nirs/_version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.7.0.dev0" diff --git a/mne_nirs/io/snirf/_snirf.py b/mne_nirs/io/snirf/_snirf.py index 83e2f3ff9..66e60074d 100644 --- a/mne_nirs/io/snirf/_snirf.py +++ b/mne_nirs/io/snirf/_snirf.py @@ -112,8 +112,10 @@ def _add_metadata_tags(raw, nirs): metadata_tags.create_dataset("FrequencyUnit", data=_str_encode("Hz")) # Add non standard (but allowed) custom metadata tags - if "birthday" in raw.info["subject_info"]: - birthday = datetime.date(*raw.info["subject_info"]["birthday"]) + if raw.info["subject_info"].get("birthday", None) is not None: + birthday = raw.info["subject_info"]["birthday"] + if isinstance(birthday, tuple): + birthday = datetime.date(*birthday) birthstr = birthday.strftime("%Y-%m-%d") metadata_tags.create_dataset("DateOfBirth", data=[_str_encode(birthstr)]) for key in ("first", "middle", "last"): diff --git a/pyproject.toml b/pyproject.toml index 771690ca1..273eab501 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,74 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "mne-nirs" +description = "An MNE compatible package for processing near-infrared spectroscopy data" +dynamic = ["version"] +maintainers = [{ name = "Robert Luke", email = "robert.luke@mq.edu.au" }] +license = { text = "BSD-3-Clause" } +readme = { file = "README.rst", content-type = "text/x-rst" } + +requires-python = ">=3.9" +keywords = [ + "neuroscience", + "neuroimaging", + "MEG", + "EEG", + "ECoG", + "fNIRS", + "brain", +] +classifiers = [ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved", + "Programming Language :: Python", + "Topic :: Software Development", + "Topic :: Scientific/Engineering", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "Operating System :: Unix", + "Operating System :: MacOS", + "Programming Language :: Python :: 3", +] +scripts = { mne = "mne.commands.utils:main" } +dependencies = [ + "numpy>=1.11.3,<3", + "scipy>=0.17.1", + "mne>=1.0", + "h5io>=0.1.7", + "nilearn>=0.9", + "seaborn", +] + + +[project.urls] +Homepage = "https://mne.tools/mne-nirs/" +Download = "https://github.com/mne-tools/mne-nirs" +"Source Code" = "https://github.com/mne-tools/mne-nirs/" + +[project.optional-dependencies] +tests = ["pytest", "pytest-cov"] +docs = ["sphinx", "sphinx-gallery", "sphinx_rtd_theme", "numpydoc", "matplotlib"] + +[tool.hatch.build] +exclude = [ + "/.*", + "/*.yml", + "/*.txt", + "/doc", + "/examples", + "/tools", + "/CONTRIBUTING.md", + "/Dockerfile", +] # tracked by git, but we don't want to ship those files + +[tool.hatch.version] +source = "vcs" +raw-options = { version_scheme = "release-branch-semver" } + [tool.codespell] ignore-words = ".github/workflows/ignore_words.txt" builtin = "clear,rare,informal,names,usage" diff --git a/setup.py b/setup.py deleted file mode 100644 index fac2e2832..000000000 --- a/setup.py +++ /dev/null @@ -1,76 +0,0 @@ -#! /usr/bin/env python -"""An MNE compatible package for processing near-infrared spectroscopy data.""" - -import codecs -import os - -from setuptools import find_packages, setup - -# get __version__ from _version.py -ver_file = os.path.join("mne_nirs", "_version.py") -with open(ver_file) as f: - exec(f.read()) - -DISTNAME = "mne-nirs" -DESCRIPTION = ( - "An MNE compatible package for processing near-infrared spectroscopy data." -) -with codecs.open("README.rst", encoding="utf-8-sig") as f: - LONG_DESCRIPTION = f.read() -MAINTAINER = "Robert Luke" -MAINTAINER_EMAIL = "robert.luke@mq.edu.au" -URL = "https://mne.tools/mne-nirs/" -LICENSE = "BSD (3-clause)" -DOWNLOAD_URL = "https://github.com/mne-tools/mne-nirs" -VERSION = __version__ # noqa: F821 -INSTALL_REQUIRES = ( - [ - "numpy>=1.11.3", - "scipy>=0.17.1", - "mne>=1.0", - "h5io>=0.1.7", - "nilearn>=0.9", - "seaborn", - ], -) -CLASSIFIERS = [ - "Intended Audience :: Science/Research", - "Intended Audience :: Developers", - "License :: OSI Approved", - "Programming Language :: Python", - "Topic :: Software Development", - "Topic :: Scientific/Engineering", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Operating System :: Unix", - "Operating System :: MacOS", - "Programming Language :: Python :: 3", -] -EXTRAS_REQUIRE = { - "tests": ["pytest", "pytest-cov"], - "docs": ["sphinx", "sphinx-gallery", "sphinx_rtd_theme", "numpydoc", "matplotlib"], -} - -setup( - name=DISTNAME, - maintainer=MAINTAINER, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - license=LICENSE, - url=URL, - version=VERSION, - download_url=DOWNLOAD_URL, - long_description=LONG_DESCRIPTION, - long_description_content_type="text/x-rst", - zip_safe=False, # the package can run out of an .egg file - classifiers=CLASSIFIERS, - keywords="neuroscience neuroimaging fNIRS NIRS brain", - packages=find_packages(), - project_urls={ - "Documentation": "https://mne.tools/mne-nirs/", - "Source": "https://github.com/mne-tools/mne-nirs/", - "Tracker": "https://github.com/mne-tools/mne-nirs/issues/", - }, - install_requires=INSTALL_REQUIRES, - extras_require=EXTRAS_REQUIRE, -)