From 4a18eecdd4fddd3511003ff95dfe029167c6c756 Mon Sep 17 00:00:00 2001 From: Wolfgang Preimesberger Date: Fri, 14 Jun 2024 16:39:01 +0200 Subject: [PATCH] Update meta packag --- docs/Makefile | 2 +- docs/conf.py | 96 +++++++++++++------------------------ docs/contributing.rst | 1 + docs/readme.rst | 1 + setup.cfg | 2 +- setup.py | 104 +++++++--------------------------------- src/pytesmo/__init__.py | 26 ++-------- tox.ini | 93 +++++++++++++++++++++++++++++++++++ 8 files changed, 150 insertions(+), 175 deletions(-) create mode 100644 docs/contributing.rst create mode 100644 tox.ini diff --git a/docs/Makefile b/docs/Makefile index fa2cc350..31655dd9 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -11,7 +11,7 @@ AUTODOCDIR = api # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1) -$(error "The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/") +$(error "The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/") endif .PHONY: help clean Makefile diff --git a/docs/conf.py b/docs/conf.py index 0f571cd8..6145cb9f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,56 +9,21 @@ import os import sys -import inspect import shutil -import subprocess - - -# Create kernel for notebooks -on_rtd = "READTHEDOCS" in os.environ and os.environ["READTHEDOCS"] -if on_rtd: - rtd_project = os.environ["READTHEDOCS_PROJECT"] - rtd_version = os.environ["READTHEDOCS_VERSION"] - interpreter = ( - f"/home/docs/checkouts/readthedocs.org/user_builds/{rtd_project}/" - f"conda/{rtd_version}/bin/python" - ) -else: - interpreter = "python" - -print("Installing kernel") -subprocess.run( - [ - interpreter, - "-m", - "ipykernel", - "install", - "--user", - "--name", - "conda-env-pytesmo-py", - "--display-name", - "Python [conda env:pytesmo]" - ], - check=True, - capture_output=True, -) -print("Done") # -- Path setup -------------------------------------------------------------- -__location__ = os.path.join( - os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe())) -) +__location__ = os.path.dirname(__file__) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -# sys.path.insert(0, os.path.join(__location__, "../src")) +sys.path.insert(0, os.path.join(__location__, "../src")) # -- Run sphinx-apidoc ------------------------------------------------------- # This hack is necessary since RTD does not issue `sphinx-apidoc` before running # `sphinx-build -b html . _build/html`. See Issue: -# https://github.com/rtfd/readthedocs.org/issues/1139 +# https://github.com/readthedocs/readthedocs.org/issues/1139 # DON'T FORGET: Check the box "Install your project inside a virtualenv using # setup.py install" in the RTD Advanced Settings. # Additionally it helps us to avoid running apidoc manually @@ -78,13 +43,7 @@ try: import sphinx - cmd_line_template = ( - "sphinx-apidoc --implicit-namespaces" - " -Me -d 3 -f -o {outputdir} {moduledir}" - ) - cmd_line = cmd_line_template.format( - outputdir=output_dir, moduledir=module_dir - ) + cmd_line = f"sphinx-apidoc --implicit-namespaces -f -o {output_dir} {module_dir}" args = cmd_line.split(" ") if tuple(sphinx.__version__.split(".")) >= ("1", "7"): @@ -113,7 +72,6 @@ "sphinx.ext.ifconfig", "sphinx.ext.mathjax", "sphinx.ext.napoleon", - "nbsphinx", ] # Add any paths that contain templates here, relative to this directory. @@ -130,16 +88,25 @@ # General information about the project. project = "pytesmo" -copyright = "2021, TU Wien" +copyright = "2024, TU Wien" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = "" # Is set by calling `setup.py docs` -# The full version, including alpha/beta/rc tags. -release = "" # Is set by calling `setup.py docs` +# version: The short X.Y version. +# release: The full version, including alpha/beta/rc tags. +# If you don’t need the separation provided between version and release, +# just set them both to the same value. +try: + from pytesmo import __version__ as version +except ImportError: + version = "" + +if not version or version.lower() == "unknown": + version = os.getenv("READTHEDOCS_VERSION", "unknown") # automatically set by RTD + +release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -178,32 +145,30 @@ # If true, keep warnings as "system message" paragraphs in the built documents. # keep_warnings = False +# If this is True, todo emits a warning for each TODO entries. The default is False. +todo_emit_warnings = True + # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = "sphinx_rtd_theme" - +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -html_theme_options = {"sidebar_width": "300px", "page_width": "1200px", - "show_navbar_depth": 2 - } +html_theme_options = { + "sidebar_width": "300px", + "page_width": "1200px" +} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -try: - from pytesmo import __version__ as version -except ImportError: - pass -else: - release = version +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None @@ -307,12 +272,15 @@ # -- External mapping -------------------------------------------------------- python_version = ".".join(map(str, sys.version_info[0:2])) intersphinx_mapping = { - "sphinx": ("http://www.sphinx-doc.org/en/stable", None), + "sphinx": ("https://www.sphinx-doc.org/en/master", None), "python": ("https://docs.python.org/" + python_version, None), "matplotlib": ("https://matplotlib.org", None), - "numpy": ("https://docs.scipy.org/doc/numpy", None), + "numpy": ("https://numpy.org/doc/stable", None), "sklearn": ("https://scikit-learn.org/stable", None), "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), + "setuptools": ("https://setuptools.pypa.io/en/stable/", None), "pyscaffold": ("https://pyscaffold.org/en/stable", None), } + +print(f"loading configurations for {project} {version} ...", file=sys.stderr) diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..0790f1ca --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1 @@ +.. include:: ../DEVELOPERS_GUIDE.md diff --git a/docs/readme.rst b/docs/readme.rst index 72a33558..81995ef4 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -1 +1,2 @@ +.. _readme: .. include:: ../README.rst diff --git a/setup.cfg b/setup.cfg index ae7c1aed..deb4ac16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -154,7 +154,7 @@ exclude = [pyscaffold] # PyScaffold's parameters when the project was created. # This will be used when updating. Do not change! -version = 4.0 +version = 4.5 package = pytesmo extensions = no_skeleton diff --git a/setup.py b/setup.py index c3db7e86..50b4a2a9 100644 --- a/setup.py +++ b/setup.py @@ -1,89 +1,21 @@ -# -*- coding: utf-8 -*- - +""" + Setup file for pytesmo. + Use setup.cfg to configure your project. + + This file was generated with PyScaffold 4.5. + PyScaffold helps you to put up the scaffold of your new Python project. + Learn more under: https://pyscaffold.org/ +""" from setuptools import setup -from setuptools.command.build_ext import build_ext as _build_ext -from setuptools.command.sdist import sdist as _sdist -from setuptools.extension import Extension -import numpy - - -# list of C/Cython extensions -def get_ext_modules(ext): - return [ - Extension( - "pytesmo.time_series.filters", - ["src/pytesmo/time_series/filters" + ext], - include_dirs=[numpy.get_include()], - define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")], - ), - Extension( - "pytesmo.metrics._fast", - ["src/pytesmo/metrics/_fast" + ext], - include_dirs=[numpy.get_include()], - define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")], - ), - Extension( - "pytesmo.metrics._fast_pairwise", - ["src/pytesmo/metrics/_fast_pairwise" + ext], - include_dirs=[numpy.get_include()], - define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")], - ), - ] - - -# defining a custom cythonize function that sets all the options we want and -# that can be reused for the different options -def cythonize_extensions(): - from Cython.Build import cythonize - - cythonize( - get_ext_modules(".pyx"), - compiler_directives={ - "embedsignature": True, - "language_level": 3, - # "warn.undeclared": True, - # "warn.maybe_unitialized": True, - "warn.unused": True, - # "warn.unused_arg": True, - # "warn.unused_result": True, - }, - # include_path=[numpy.get_include()], - ) - - -class CythonizeMixin(object): - - user_options = [ - ("cythonize", None, "recreate the c extionsions with cython") - ] - - def initialize_options(self): - super().initialize_options() - self.cythonize = False - - def run(self): - if self.cythonize: - cythonize_extensions() - super().run() - - -class sdist(CythonizeMixin, _sdist): - user_options = getattr(_sdist, 'user_options', [])\ - + CythonizeMixin.user_options - - -class build_ext(CythonizeMixin, _build_ext): - user_options = getattr(_build_ext, 'user_options', [])\ - + CythonizeMixin.user_options - if __name__ == "__main__": - cmdclass = {} - cmdclass["sdist"] = sdist - cmdclass["build_ext"] = build_ext - setup( - cmdclass=cmdclass, - # at this point the C modules have already been generated if necessary - ext_modules=get_ext_modules(".c"), - use_scm_version={"version_scheme": "no-guess-dev"} - ) + try: + setup(use_scm_version={"version_scheme": "no-guess-dev"}) + except: # noqa + print( + "\n\nAn error occurred while building the project, " + "please ensure you have the most updated version of setuptools, " + "setuptools_scm and wheel with:\n" + " pip install -U setuptools setuptools_scm wheel\n\n" + ) + raise diff --git a/src/pytesmo/__init__.py b/src/pytesmo/__init__.py index 5a48e60b..6c210eeb 100644 --- a/src/pytesmo/__init__.py +++ b/src/pytesmo/__init__.py @@ -1,17 +1,10 @@ import sys if sys.version_info[:2] >= (3, 8): - # TODO: Import directly (no need for conditional) when - # `python_requires = >= 3.8` - from importlib.metadata import ( - PackageNotFoundError, - version, - ) # pragma: no cover + # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` # noqa: E501 + from importlib.metadata import PackageNotFoundError, version # pragma: no cover # noqa: E501 else: - from importlib_metadata import ( - PackageNotFoundError, - version, - ) # pragma: no cover + from importlib_metadata import PackageNotFoundError, version # pragma: no cover # noqa: E501 try: # Change here if project is renamed and does not equal the package name @@ -21,16 +14,3 @@ __version__ = "unknown" finally: del version, PackageNotFoundError - - -# custom code not generated by PyScaffold -__all__ = [ - "metrics", - "scaling", - "temporal_matching", - "timedate", - "time_series", - "grid", - "colormaps", - "validation_framework" -] diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..69f81594 --- /dev/null +++ b/tox.ini @@ -0,0 +1,93 @@ +# Tox configuration file +# Read more under https://tox.wiki/ +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + +[tox] +minversion = 3.24 +envlist = default +isolated_build = True + + +[testenv] +description = Invoke pytest to run automated tests +setenv = + TOXINIDIR = {toxinidir} +passenv = + HOME + SETUPTOOLS_* +extras = + testing +commands = + pytest {posargs} + + +# # To run `tox -e lint` you need to make sure you have a +# # `.pre-commit-config.yaml` file. See https://pre-commit.com +# [testenv:lint] +# description = Perform static analysis and style checks +# skip_install = True +# deps = pre-commit +# passenv = +# HOMEPATH +# PROGRAMDATA +# SETUPTOOLS_* +# commands = +# pre-commit run --all-files {posargs:--show-diff-on-failure} + + +[testenv:{build,clean}] +description = + build: Build the package in isolation according to PEP517, see https://github.com/pypa/build + clean: Remove old distribution files and temporary build artifacts (./build and ./dist) +# https://setuptools.pypa.io/en/stable/build_meta.html#how-to-use-it +skip_install = True +changedir = {toxinidir} +deps = + build: build[virtualenv] +passenv = + SETUPTOOLS_* +commands = + clean: python -c 'import shutil; [shutil.rmtree(p, True) for p in ("build", "dist", "docs/_build")]' + clean: python -c 'import pathlib, shutil; [shutil.rmtree(p, True) for p in pathlib.Path("src").glob("*.egg-info")]' + build: python -m build {posargs} +# By default, both `sdist` and `wheel` are built. If your sdist is too big or you don't want +# to make it available, consider running: `tox -e build -- --wheel` + + +[testenv:{docs,doctests,linkcheck}] +description = + docs: Invoke sphinx-build to build the docs + doctests: Invoke sphinx-build to run doctests + linkcheck: Check for broken links in the documentation +passenv = + SETUPTOOLS_* +setenv = + DOCSDIR = {toxinidir}/docs + BUILDDIR = {toxinidir}/docs/_build + docs: BUILD = html + doctests: BUILD = doctest + linkcheck: BUILD = linkcheck +deps = + -r {toxinidir}/docs/requirements.txt + # ^ requirements.txt shared with Read The Docs +commands = + sphinx-build --color -b {env:BUILD} -d "{env:BUILDDIR}/doctrees" "{env:DOCSDIR}" "{env:BUILDDIR}/{env:BUILD}" {posargs} + + +[testenv:publish] +description = + Publish the package you have been developing to a package index server. + By default, it uses testpypi. If you really want to publish your package + to be publicly accessible in PyPI, use the `-- --repository pypi` option. +skip_install = True +changedir = {toxinidir} +passenv = + # See: https://twine.readthedocs.io/en/latest/ + TWINE_USERNAME + TWINE_PASSWORD + TWINE_REPOSITORY + TWINE_REPOSITORY_URL +deps = twine +commands = + python -m twine check dist/* + python -m twine upload {posargs:--repository {env:TWINE_REPOSITORY:testpypi}} dist/*