From a0684f2e139f00fceffc036ccf5351a3b4950936 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Mon, 13 Mar 2023 14:48:38 +0100 Subject: [PATCH] Merge pull request #8 from qutip/feature/apply-black-to-misc-scripts Apply black to setup.py and doc/conf.py scripts --- .github/workflows/black.yml | 2 +- doc/conf.py | 54 ++++++++++++++++++------------------- setup.py | 38 ++++++++++++++------------ 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 5743566..f3e7342 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -10,4 +10,4 @@ jobs: - uses: psf/black@stable with: options: "--check --diff" - src: "./src ./tests" + src: "./src ./tests ./doc/conf.py ./setup.py" diff --git a/doc/conf.py b/doc/conf.py index d169d33..458c43f 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -12,23 +12,21 @@ import os import pathlib import sys -sys.path.insert(0, os.path.abspath('.')) + +sys.path.insert(0, os.path.abspath(".")) # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'qutip_qtrl' -copyright = '2011-2023, QuTiP Community' -author = 'QuTiP Community' +project = "qutip_qtrl" +copyright = "2011-2023, QuTiP Community" +author = "QuTiP Community" def qutip_qtrl_version(): - """ Retrieve the qutip-qtrl version from ``../../VERSION``. - """ + """Retrieve the qutip-qtrl version from ``../../VERSION``.""" src_folder_root = pathlib.Path(__file__).absolute().parent.parent - version = src_folder_root.joinpath( - "VERSION" - ).read_text().strip() + version = src_folder_root.joinpath("VERSION").read_text().strip() return version @@ -41,28 +39,28 @@ def qutip_qtrl_version(): # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [ - 'sphinx.ext.mathjax', - 'matplotlib.sphinxext.plot_directive', - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.doctest', - 'sphinx.ext.todo', - 'numpydoc', - 'sphinx.ext.extlinks', - 'sphinx.ext.viewcode', - 'sphinx.ext.ifconfig', - 'sphinx.ext.napoleon', - 'sphinxcontrib.bibtex', - 'sphinx.ext.intersphinx', + "sphinx.ext.mathjax", + "matplotlib.sphinxext.plot_directive", + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.doctest", + "sphinx.ext.todo", + "numpydoc", + "sphinx.ext.extlinks", + "sphinx.ext.viewcode", + "sphinx.ext.ifconfig", + "sphinx.ext.napoleon", + "sphinxcontrib.bibtex", + "sphinx.ext.intersphinx", ] -templates_path = ['_templates'] -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" html_static_path = [] # -- Options for numpydoc --------------------------------------- @@ -82,11 +80,11 @@ def qutip_qtrl_version(): # -- Options for biblatex --------------------------------------- -bibtex_bibfiles = ['references.bib'] -bibtex_default_style = 'unsrt' +bibtex_bibfiles = ["references.bib"] +bibtex_default_style = "unsrt" # -- Options for intersphinx --------------------------------------- intersphinx_mapping = { - 'qutip': ('https://qutip.org/docs/latest/', None), + "qutip": ("https://qutip.org/docs/latest/", None), } diff --git a/setup.py b/setup.py index 1f490a4..f4b2676 100755 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ def process_options(): Is this a release build (True) or a local development build (False) """ options = {} - options['rootdir'] = os.path.dirname(os.path.abspath(__file__)) + options["rootdir"] = os.path.dirname(os.path.abspath(__file__)) options = _determine_version(options) return options @@ -38,21 +38,22 @@ def _determine_version(options): We do that here rather than in setup.cfg so we can apply the local versioning number as well. """ - version_filename = os.path.join(options['rootdir'], 'VERSION') + version_filename = os.path.join(options["rootdir"], "VERSION") with open(version_filename, "r") as version_file: version_string = version_file.read().strip() version = packaging.version.Version(version_string) - options['short_version'] = str(version.public) - options['release'] = not version.is_devrelease - if not options['release']: + options["short_version"] = str(version.public) + options["release"] = not version.is_devrelease + if not options["release"]: # Put the version string into canonical form, if it wasn't already. version_string = str(version) version_string += "+" try: git_out = subprocess.run( - ('git', 'rev-parse', '--verify', '--short=7', 'HEAD'), + ("git", "rev-parse", "--verify", "--short=7", "HEAD"), check=True, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) git_hash = git_out.stdout.decode(sys.stdout.encoding).strip() version_string += git_hash or "nogit" @@ -62,7 +63,7 @@ def _determine_version(options): # or a permission error). except (subprocess.CalledProcessError, OSError): version_string += "nogit" - options['version'] = version_string + options["version"] = version_string return options @@ -73,14 +74,17 @@ def create_version_py_file(options): overwrite an existing file at that location. """ filename = os.path.join( - options['rootdir'], 'src', 'qutip_qtrl', 'version.py') - content = "\n".join([ - "# This file is automatically generated by qutip-qtrl's setup.py.", - f"short_version = '{options['short_version']}'", - f"version = '{options['version']}'", - f"release = {options['release']}", - ]) - with open(filename, 'w') as file: + options["rootdir"], "src", "qutip_qtrl", "version.py" + ) + content = "\n".join( + [ + "# This file is automatically generated by qutip-qtrl's setup.py.", + f"short_version = '{options['short_version']}'", + f"version = '{options['version']}'", + f"release = {options['release']}", + ] + ) + with open(filename, "w") as file: print(content, file=file) @@ -90,5 +94,5 @@ def create_version_py_file(options): # Most of the kwargs to setup are defined in setup.cfg; the only ones we # keep here are ones that we have done some compile-time processing on. setup( - version=options['version'], + version=options["version"], )