Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ci:
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-yaml
exclude: '^{{ cookiecutter.github_repo_name }}/.*\.yml$' # {{ cookiecutter.github_repo_name }} contains jinja variables in .yml, hook fails
Expand All @@ -25,21 +25,21 @@ repos:
args: ["--branch", "main"]
stages: [pre-commit]
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 26.3.1
hooks:
- id: black
exclude: '^({{ cookiecutter.github_repo_name }}/.*\.py|hooks/post_gen_project\.py)$' # {{ cookiecutter.github_repo_name }} contains jinja variables in .py, hook fails. hooks/post_gen_project.py contains jinja variables of # (c) {% now 'utc', '%Y' %} which is not a valid black format
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 9.0.0a3
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.2
hooks:
- id: codespell
additional_dependencies:
Expand All @@ -50,15 +50,14 @@ repos:
]
# prettier - multi formatter for .json, .yml, and .md files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
rev: v4.0.0-alpha.8
hooks:
- id: prettier
additional_dependencies:
- "prettier@^3.2.4"
# docformatter - PEP 257 compliant docstring formatter
- repo: https://github.com/s-weigand/docformatter
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.8
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
22 changes: 11 additions & 11 deletions hooks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
def template_files():
spm_template_files = {
"article-cls-in-spm.cls": r"Contents of article-cls-in-spm.cls",
"manuscript-in-spm.tex": r"""
\documentclass{article}
\usepackage{package-in-manuscript}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-manuscript}
\bibliographystyle{chicago}
\end{document}
""",
"bib-in-spm.bib": r"""Contents of bib-in-spm.bib""",
"manuscript-in-spm.tex": (
"\\documentclass{article}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography{bib-in-manuscript}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
"bib-in-spm.bib": r"Contents of bib-in-spm.bib.",
}
yield spm_template_files

Expand Down
135 changes: 69 additions & 66 deletions hooks/test_post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,52 +137,54 @@ def test_copy_all_files_bad(user_filesystem):
# a order that packages come before commands.
(
["usepackages.txt", "newcommands.txt"],
r"""
\documentclass{article}
\usepackage{package-from-user-usepackage}
\usepackage{package-in-manuscript}
\newcommand{\command_from_user_newcommands}[1]{\mathrm{#1}}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-manuscript}
\bibliographystyle{chicago}
\end{document}
""",
(
"\\documentclass{article}\n"
"\\usepackage{package-from-user-usepackage}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_from_user_newcommands}[1]"
"{\\mathrm{#1}}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography{bib-in-manuscript}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
),
# C2: Only usepackages.txt exists. Expect user's usepackages are
# inserted before manuscript's usepackages abd after
# inserted before manuscript's usepackages and after
# \begin{documentclass}
(
["usepackages.txt"],
r"""
\documentclass{article}
\usepackage{package-from-user-usepackage}
\usepackage{package-in-manuscript}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-manuscript}
\bibliographystyle{chicago}
\end{document}
""",
(
"\\documentclass{article}\n"
"\\usepackage{package-from-user-usepackage}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography{bib-in-manuscript}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
),
# C3: Only newcommands.txt exists. Expect user's newcommands are
# inserted before manuscript's newcommands and after manuscrip'ts
# usepackages.
(
["newcommands.txt"],
r"""
\documentclass{article}
\usepackage{package-in-manuscript}
\newcommand{\command_from_user_newcommands}[1]{\mathrm{#1}}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-manuscript}
\bibliographystyle{chicago}
\end{document}
""",
(
"\\documentclass{article}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_from_user_newcommands}[1]"
"{\\mathrm{#1}}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography{bib-in-manuscript}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
),
],
)
Expand Down Expand Up @@ -215,30 +217,31 @@ def test_load_headers(
# Expect bib names are inserted into the manuscript's bibliography.
(
True,
r"""
\documentclass{article}
\usepackage{package-in-manuscript}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-spm, user-bib-file-1, user-bib-file-2}
\bibliographystyle{chicago}
\end{document}
""",
(
"\\documentclass{article}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography"
"{bib-in-spm, user-bib-file-1, user-bib-file-2}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
),
# C2: manuscript.tex exists in the directory, but bib files don't.
# Expect the manuscript.tex content doesn't change.
(
False,
r"""
\documentclass{article}
\usepackage{package-in-manuscript}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliographystyle{chicago}
\end{document}
""",
(
"\\documentclass{article}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
),
),
],
)
Expand Down Expand Up @@ -294,16 +297,16 @@ def test_initialize_project(user_filesystem, mock_home, mock_clone, tmpdir):
initialize_project("article", manuscript_name, user_repo_url)
actual_manuscript_path = Path(tmpdir) / manuscript_name
actual_manuscript_content = actual_manuscript_path.read_text()
expected_manuscript_content = r"""
\documentclass{article}
\usepackage{package-from-user-usepackage}
\usepackage{package-in-manuscript}
\newcommand{\command_from_user_newcommands}[1]{\mathrm{#1}}
\newcommand{\command_in_manuscript}[1]{\mathbf{#1}}
\begin{document}
Contents of manuscript
\bibliography{bib-in-spm, user-bib-file-1, user-bib-file-2}
\bibliographystyle{chicago}
\end{document}
"""
expected_manuscript_content = (
"\\documentclass{article}\n"
"\\usepackage{package-from-user-usepackage}\n"
"\\usepackage{package-in-manuscript}\n"
"\\newcommand{\\command_from_user_newcommands}[1]{\\mathrm{#1}}\n"
"\\newcommand{\\command_in_manuscript}[1]{\\mathbf{#1}}\n"
"\\begin{document}\n"
"Contents of manuscript\n"
"\\bibliography{bib-in-spm, user-bib-file-1, user-bib-file-2}\n"
"\\bibliographystyle{chicago}\n"
"\\end{document}\n"
)
assert expected_manuscript_content == actual_manuscript_content
23 changes: 23 additions & 0 deletions news/update-docformatter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news added: Use official ``PyCQA/docformatter`` in ``pre-commit``.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
Loading