Skip to content

Commit 2368259

Browse files
authored
Merge pull request #175 from scipp/black
Swicth to Black python formatting and fix some docs issues
2 parents 501a726 + cafb3b9 commit 2368259

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2969
-2088
lines changed

.github/workflows/docs.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
default: ''
1414
required: false
1515
type: string
16+
branch:
17+
description: 'Branch/tag with documentation source. If not set, the current branch will be used.'
18+
default: ''
19+
required: false
20+
type: string
1621
platform:
1722
default: 'ubuntu-22.04'
1823
type: string
@@ -25,6 +30,11 @@ on:
2530
default: ''
2631
required: false
2732
type: string
33+
branch:
34+
description: 'Branch/tag with documentation source. If not set, the current branch will be used.'
35+
default: ''
36+
required: false
37+
type: string
2838
platform:
2939
default: 'ubuntu-22.04'
3040
type: string
@@ -45,7 +55,7 @@ jobs:
4555
steps:
4656
- uses: actions/checkout@v3
4757
with:
48-
ref: ${{ inputs.version }}
58+
ref: ${{ inputs.branch == '' && github.ref_name || inputs.branch }}
4959
fetch-depth: 0 # history required so setuptools_scm can determine version
5060

5161
- name: Setup conda environment
@@ -55,7 +65,7 @@ jobs:
5565
environment-file: environment.yml
5666
cache-env: true
5767

58-
- run: conda develop src
68+
- run: python -m pip install .
5969
- run: jupyter --paths
6070
- run: python docs/make_docs.py --build-dir=html_${{ inputs.platform }}
6171

.github/workflows/pr_and_main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ jobs:
6565
uses: ./.github/workflows/docs.yml
6666
with:
6767
publish: false
68+
version: ${{ github.ref_name }}
69+
branch: ${{ github.head_ref == '' && github.ref_name || github.head_ref }}
6870
platform: ${{ matrix.os }}
6971
strategy:
7072
fail-fast: false

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ jobs:
100100
- name: Set outputs
101101
id: version
102102
run: |
103-
echo "new=$(python docs/version.py --repo=scipp --version=${GITHUB_REF_NAME} --action=is-new)" >> $GITHUB_OUTPUT
104-
echo "replaced=$(python docs/version.py --repo=scipp --version=${GITHUB_REF_NAME} --action=get-replaced)" >> $GITHUB_OUTPUT
103+
echo "new=$(python docs/version.py --version=${GITHUB_REF_NAME} --action=is-new)" >> $GITHUB_OUTPUT
104+
echo "replaced=$(python docs/version.py --version=${GITHUB_REF_NAME} --action=get-replaced)" >> $GITHUB_OUTPUT
105105
106106
replaced-docs:
107107
needs: [upload_packages, manage-versions]

.pre-commit-config.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ repos:
1818
hooks:
1919
- id: isort
2020
name: isort (python)
21-
- repo: https://github.com/pre-commit/mirrors-yapf
22-
rev: v0.32.0
21+
- repo: https://github.com/psf/black
22+
rev: 23.3.0
2323
hooks:
24-
- id: yapf
25-
args: [ "-i", "-r" ]
26-
types: [ "python" ]
27-
additional_dependencies: [ "toml" ]
24+
- id: black
2825
- repo: https://github.com/kynan/nbstripout
2926
rev: 0.6.0
3027
hooks:

docs/conf.py

+33-24
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ def add_buttons(
3838
base = "https://scipp.github.io"
3939
l1 = []
4040
l1.append({"type": "link", "text": "scipp", "url": f"{base}"})
41+
l1.append({"type": "link", "text": "plopp", "url": f"{base}/plopp"})
4142
l1.append({"type": "link", "text": "scippnexus", "url": f"{base}/scippnexus"})
4243
l1.append({"type": "link", "text": "scippneutron", "url": f"{base}/scippneutron"})
4344
l1.append({"type": "link", "text": "ess", "url": f"{base}/ess"})
4445
header_buttons = context["header_buttons"]
45-
header_buttons.append({
46-
"type": "group",
47-
"buttons": l1,
48-
"icon": "fa fa-caret-down",
49-
"text": "Related projects"
50-
})
46+
header_buttons.append(
47+
{
48+
"type": "group",
49+
"buttons": l1,
50+
"icon": "fa fa-caret-down",
51+
"text": "Related projects",
52+
}
53+
)
5154
releases = version_info.minor_releases(first='0.1')
5255
if outdated:
5356
current = f"{long_version} (outdated)"
@@ -59,17 +62,12 @@ def add_buttons(
5962
entries = releases[1:]
6063
lines = [{"type": "link", "text": latest, "url": f"{base}/{project}"}]
6164
for r in entries:
62-
lines.append({
63-
"type": "link",
64-
"text": f"{r}",
65-
"url": f"{base}/{project}/release/{r}"
66-
})
67-
header_buttons.append({
68-
"type": "group",
69-
"buttons": lines,
70-
"icon": "fa fa-caret-down",
71-
"text": current
72-
})
65+
lines.append(
66+
{"type": "link", "text": f"{r}", "url": f"{base}/{project}/release/{r}"}
67+
)
68+
header_buttons.append(
69+
{"type": "group", "buttons": lines, "icon": "fa fa-caret-down", "text": current}
70+
)
7371

7472

7573
sphinx_book_theme.add_launch_buttons = add_buttons
@@ -104,7 +102,7 @@ def add_buttons(
104102
'numpy': ('https://numpy.org/doc/stable/', None),
105103
'scipp': ('https://scipp.github.io/', None),
106104
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
107-
'xarray': ('https://xarray.pydata.org/en/stable/', None)
105+
'xarray': ('https://xarray.pydata.org/en/stable/', None),
108106
}
109107

110108
# autodocs includes everything, even irrelevant API internals. autosummary
@@ -198,7 +196,8 @@ def add_buttons(
198196
f"⚠️ You are viewing the documentation for an old version of {project}. "
199197
f"Switch to <a href='https://scipp.github.io/{project}' "
200198
"style='color:white;text-decoration:underline;'"
201-
">latest</a> version. ⚠️")
199+
">latest</a> version. ⚠️"
200+
)
202201

203202
html_logo = "_static/logo.svg"
204203
html_favicon = "_static/favicon.ico"
@@ -236,8 +235,15 @@ def add_buttons(
236235
# (source start file, target name, title, author,
237236
# dir menu entry, description, category)
238237
texinfo_documents = [
239-
(master_doc, 'ess', u'ess Documentation', author, 'ess',
240-
'One line description of project.', 'Miscellaneous'),
238+
(
239+
master_doc,
240+
'ess',
241+
u'ess Documentation',
242+
author,
243+
'ess',
244+
'One line description of project.',
245+
'Miscellaneous',
246+
),
241247
]
242248

243249
# -- Options for Matplotlib in notebooks ----------------------------------
@@ -255,9 +261,12 @@ def add_buttons(
255261

256262
# Using normalize whitespace because many __str__ functions in scipp produce
257263
# extraneous empty lines and it would look strange to include them in the docs.
258-
doctest_default_flags = doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL | \
259-
doctest.DONT_ACCEPT_TRUE_FOR_1 | \
260-
doctest.NORMALIZE_WHITESPACE
264+
doctest_default_flags = (
265+
doctest.ELLIPSIS
266+
| doctest.IGNORE_EXCEPTION_DETAIL
267+
| doctest.DONT_ACCEPT_TRUE_FOR_1
268+
| doctest.NORMALIZE_WHITESPACE
269+
)
261270

262271
# -- Options for linkcheck ------------------------------------------------
263272

docs/developer/style-guide.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Formatting
7373

7474
Your Python code will be checked for errors and formatting when opening a PR.
7575
We use the `flake8 <https://flake8.pycqa.org/en/latest/>`_ linter to check code quality,
76-
and `yapf <https://github.com/google/yapf>`_ to enforce code formatting.
76+
and `black <https://github.com/psf/black>`_ to enforce code formatting.
7777
Make sure that running your code though these tools does not generate any output before
7878
you push your changes.
7979

@@ -82,7 +82,7 @@ From the top level directory, you can use
8282
.. code-block:: sh
8383
8484
>$ flake8 .
85-
>$ yapf --diff --recursive .
85+
>$ black .
8686
8787
Jupyter notebooks style
8888
-----------------------

0 commit comments

Comments
 (0)