Skip to content

Commit

Permalink
Merge pull request #711 from hakonanes/licenseheaders-in-pre-commit
Browse files Browse the repository at this point in the history
Update tooling
  • Loading branch information
hakonanes authored Jan 1, 2025
2 parents b11329e + e5e01aa commit ba7912d
Show file tree
Hide file tree
Showing 35 changed files with 1,350 additions and 532 deletions.
29 changes: 29 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
##
## Copyright 2019-2025 the kikuchipy developers
##
## This file is part of kikuchipy.
##
## kikuchipy is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## kikuchipy is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.##

# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
7 changes: 5 additions & 2 deletions .github/workflows/perhaps_make_tagged_release_draft.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019-2024 The kikuchipy developers
#
# Copyright 2019-2025 the kikuchipy developers
#
# This file is part of kikuchipy.
#
Expand All @@ -13,7 +14,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.#

import re

Expand Down Expand Up @@ -45,10 +46,12 @@
elif line.startswith(pypi_version):
changelog_end = i - 1
with open("release_part_in_changelog.rst", mode="w") as f:
# fmt: off
f.write(
"kikuchipy is an open-source Python library for processing, simulating and indexing of electron backscatter diffraction (EBSD) patterns.\n\n"
f"See below, the `changelog <https://kikuchipy.org/en/stable/changelog.html>`_ or the `GitHub changelog <https://github.com/pyxem/kikuchipy/compare/v{pypi_version}...v{branch_version}>`_ for all updates from the previous release.\n\n"
)
# fmt: on
for line in content[changelog_start:changelog_end]:
f.write(line)

Expand Down
61 changes: 23 additions & 38 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
##
## Copyright 2019-2025 the kikuchipy developers
##
## This file is part of kikuchipy.
##
## kikuchipy is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## kikuchipy is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.
##
name: Tests

on:
Expand All @@ -10,37 +28,13 @@ on:
workflow_dispatch:

jobs:
code:
name: code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: psf/black@stable

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- uses: isort/isort-action@master
with:
configuration: --profile black --filter-files --force-sort-within-sections --check-only --diff

- name: Install Black with Jupyter extension
run: |
pip install black[jupyter]
- name: Check code style of Jupyter notebooks
run: |
black --diff --line-length 77 doc/tutorials/*.ipynb
tests:
name: ${{ matrix.os }}-py${{ matrix.python-version }}${{ matrix.LABEL }}
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
MPLBACKEND: agg
PYTEST_ARGS: --reruns 2 -n 2 --cov=kikuchipy
PYTEST_ARGS: --cov-branch --cov-report=xml --reruns 2 -n 2 --cov=kikuchipy
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -126,17 +120,8 @@ jobs:
run: |
coverage report --show-missing
- name: Upload coverage to Coveralls
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: AndreMiras/coveralls-python-action@develop
- name: Upload coverage reports to Codecov
if: ${{ github.repository_owner == 'pyxem' }}
uses: codecov/codecov-action@v5
with:
parallel: true

coveralls-finish:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Coveralls finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
token: ${{ secrets.CODECOV_TOKEN }}
16 changes: 16 additions & 0 deletions .license.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Copyright 2019-${years} the ${projectname} developers

This file is part of ${projectname}.

${projectname} is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

${projectname} is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ${projectname}. If not, see <http://www.gnu.org/licenses/>.
52 changes: 39 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
##
## Copyright 2019-2025 the kikuchipy developers
##
## This file is part of kikuchipy.
##
## kikuchipy is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## kikuchipy is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.
##
repos:
# https://black.readthedocs.io/en/stable/index.html
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
# https://docs.astral.sh/ruff/configuration
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff
- id: ruff-format
# https://black.readthedocs.io/en/stable/index.html
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black-jupyter
files: \.ipynb
args: [--line-length=77]
# https://pycqa.github.io/isort/
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args:
[--profile=black, --filter-files, --force-sort-within-sections]
- repo: https://github.com/johann-petrak/licenseheaders.git
rev: v0.8.8
hooks:
- id: licenseheaders
args: ["-t", ".license.tmpl", "-cy", "-n", "kikuchipy", "-f"]

# https://pre-commit.ci/#configuration
ci:
autofix_prs: false
# TODO: Remove skip once (nearly) all files are formatted with the license template
skip: [licenseheaders]
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ library.
.. |python| image:: https://img.shields.io/badge/python-3.10+-blue.svg
:target: https://www.python.org/downloads/

.. |Coveralls| image:: https://coveralls.io/repos/github/pyxem/kikuchipy/badge.svg?branch=develop
:target: https://coveralls.io/github/pyxem/kikuchipy?branch=develop
.. |coverage| image:: https://codecov.io/github/hakonanes/kikuchipy/graph/badge.svg?token=tyF8x9nJKC
:target: https://codecov.io/github/pyxem/kikuchipy

.. |pypi_downloads| image:: https://img.shields.io/pypi/dm/kikuchipy.svg?label=pypi%20downloads
:target: https://pypi.org/project/kikuchipy
Expand Down Expand Up @@ -54,7 +54,7 @@ library.
+----------------------+------------------------------------------------+
| Build status | |tests_status| |docs| |python| |
+----------------------+------------------------------------------------+
| Metrics | |Coveralls| |
| Metrics | |coverage| |
+----------------------+------------------------------------------------+
| Activity | |pypi_downloads| |conda_downloads| |
+----------------------+------------------------------------------------+
Expand Down
19 changes: 11 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019-2024 The kikuchipy developers
#
# Copyright 2019-2025 the kikuchipy developers
#
# This file is part of kikuchipy.
#
Expand All @@ -9,11 +10,11 @@
#
# kikuchipy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.#

# Why is this file located in the top directory and not in tests/?
# Because if it was, running "pytest --doctest-modules src" wouldn't
Expand Down Expand Up @@ -153,11 +154,13 @@ def dummy_signal(
s.xmap = CrystalMap(
rotations=Rotation.identity((nav_size,)),
# fmt: off
phase_id=np.array([
[0, 0, 1],
[1, 1, 0],
[0, 1, 0],
]).ravel(),
phase_id=np.array(
[
[0, 0, 1],
[1, 1, 0],
[0, 1, 0],
]
).ravel(),
# fmt: on
phase_list=phase_list,
x=x.ravel(),
Expand Down
21 changes: 19 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#
# Copyright 2019-2025 the kikuchipy developers
#
# This file is part of kikuchipy.
#
# kikuchipy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# kikuchipy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.#

# Configuration file for the Sphinx documentation app.
# See the documentation for a full list of configuration options:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
Expand All @@ -6,7 +24,6 @@
import inspect
import os
from os.path import dirname, relpath
from pathlib import Path
import re
import sys
import warnings
Expand Down Expand Up @@ -269,7 +286,7 @@ def linkcode_resolve(domain, info):
pv.set_jupyter_backend("static")
try:
pv.start_xvfb()
except:
except Exception:
pass

# -- Copy button customization (taken from PyVista)
Expand Down
12 changes: 2 additions & 10 deletions doc/dev/code_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ Code style
The code making up kikuchipy is formatted closely following the `Style Guide for Python
Code <https://peps.python.org/pep-0008/>`__ with
:doc:`The Black Code style <black:the_black_code_style/current_style>`.
We use `pre-commit <https://pre-commit.com>`__ to run ``black`` automatically prior to
each local commit.
We use `pre-commit <https://pre-commit.com>`__ to run ``black`` (via
`ruff <https://docs.astral.sh/ruff/>`__) automatically prior to each local commit.
Please install it in your environment::

pre-commit install

Next time you commit some code, your code will be formatted inplace according to
``black``.

``black`` can format Jupyter notebooks as well. Code lines in tutorial notebooks should
be limited to 77 characters to display nicely in the documentation::

black -l 77 <your_nice_notebook>.ipynb

Note that ``black`` won't format `docstrings <https://peps.python.org/pep-0257/>`__.
We follow the :doc:`numpydoc <numpydoc:format>` standard (with some exceptions), and the
docstrings are checked against this standard when building the documentation.
Expand Down
11 changes: 6 additions & 5 deletions doc/dev/continuous_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ Continuous integration (CI)
===========================

We use `GitHub Actions <https://github.com/pyxem/kikuchipy/actions>`__ to ensure that
kikuchipy can be installed on Windows, macOS and Linux (Ubuntu). After a successful
installation of the package, the CI server runs the tests. After the tests return no
errors, code coverage is reported to `Coveralls
<https://coveralls.io/github/pyxem/kikuchipy?branch=develop>`__. Add ``"[skip ci]"``
to a commit message to skip this workflow on any commit to a pull request.
kikuchipy can be installed on Windows, macOS, and Linux (Ubuntu).
After a successful installation of the package, the CI server runs the tests.
After the tests return no errors, code coverage is reported to `Codecov
<https://app.codecov.io/github/pyxem/kikuchipy>`__.
Add ``"[skip ci]"`` to a commit message to skip this workflow on any commit to a pull
request.
Loading

0 comments on commit ba7912d

Please sign in to comment.