Skip to content

Commit

Permalink
Merge pull request #8 from qutip/feature/apply-black-to-misc-scripts
Browse files Browse the repository at this point in the history
Apply black to setup.py and doc/conf.py scripts
  • Loading branch information
hodgestar committed Mar 13, 2023
1 parent a5c2ae8 commit a0684f2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- uses: psf/black@stable
with:
options: "--check --diff"
src: "./src ./tests"
src: "./src ./tests ./doc/conf.py ./setup.py"
54 changes: 26 additions & 28 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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 ---------------------------------------
Expand All @@ -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),
}
38 changes: 21 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand All @@ -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


Expand All @@ -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)


Expand All @@ -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"],
)

0 comments on commit a0684f2

Please sign in to comment.