From 8d33dc0aa54a62c4fd2ae864e4de000183a067b8 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Tue, 11 Oct 2022 09:10:37 +0200 Subject: [PATCH 1/4] Add pre-commit hook config file --- .pre-commit-config.yaml | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e51504d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,45 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-docstring-first + - id: debug-statements + - id: requirements-txt-fixer + + - repo: https://github.com/asottile/reorder_python_imports + rev: v3.8.3 + hooks: + - id: reorder-python-imports + + - repo: https://github.com/psf/black + rev: 22.8.0 + hooks: + - id: black + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.0.0 + hooks: + - id: flake8 + + - repo: https://github.com/asottile/add-trailing-comma + rev: v2.3.0 + hooks: + - id: add-trailing-comma + + - repo: https://github.com/asottile/setup-cfg-fmt + rev: v2.0.0 + hooks: + - id: setup-cfg-fmt + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.981 + hooks: + - id: mypy + + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.4.0 + hooks: + - id: pretty-format-toml From 9c0aa7ab6e3083b116c28198ba69ad1d122c288d Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Tue, 11 Oct 2022 09:10:55 +0200 Subject: [PATCH 2/4] Run pre-commit hooks --- .flake8 | 2 +- .github/ISSUE_TEMPLATE/bug_report.yml | 4 ++-- .github/workflows/build_docs.yml | 4 ++-- CITATION.cff | 2 +- CONTRIBUTING.md | 3 +-- Dockerfile | 2 +- Makefile | 4 ++-- README.md | 1 - demo/demo.py | 4 ---- docs/_config.yml | 3 --- docs/api.rst | 2 +- docs/part1/packaging.md | 1 - docs/part1/testing.md | 2 +- docs/part1/typing.md | 2 +- docs/part2/citeable.md | 3 +-- docs/part2/github.md | 1 - docs/part2/issues.md | 2 -- docs/part3/auto_api.md | 2 +- docs/part3/auto_demos.md | 2 +- docs/part3/publishing.md | 3 +-- pyproject.toml | 4 ++-- src/mypackage/__init__.py | 5 ++--- src/mypackage/functions.py | 6 ++---- test/test_code.py | 1 - 24 files changed, 23 insertions(+), 42 deletions(-) diff --git a/.flake8 b/.flake8 index 2561054..0b791a0 100644 --- a/.flake8 +++ b/.flake8 @@ -2,4 +2,4 @@ # https://github.com/PyCQA/flake8/issues/234 [flake8] exclude = docs,venv -max-line-length = 100 \ No newline at end of file +max-line-length = 100 diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 068f9de..2487e43 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -25,7 +25,7 @@ body: cachedir: .pytest_cache rootdir: /root/shared plugins: anyio-3.6.1, cov-3.0.0 - collected 1 item + collected 1 item test/test_code.py::test_addition PASSED ============================================== 1 passed in 0.01s =============================================== @@ -49,7 +49,7 @@ body: placeholder: i.e. "I'm Ubuntu 20.04" or "Im using Windows 11" - type: textarea id: extra - attributes: + attributes: label: Additional information description: If you have any additional information, please add it here. placeholder: You can drag and drop files here to attach them diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 02da51c..3f803c2 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: python -m pip install ".[test,docs]" - + - name: Build docs run: make doc @@ -32,4 +32,4 @@ jobs: uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ${{ env.PUBLISH_DIR }} \ No newline at end of file + publish_dir: ${{ env.PUBLISH_DIR }} diff --git a/CITATION.cff b/CITATION.cff index 9addc9b..99ccdf9 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -6,4 +6,4 @@ authors: orcid: "https://orcid.org/0000-0001-6489-8858" title: "Template for reproducible research" version: 0.1.0 -date-released: 2022-09-13 \ No newline at end of file +date-released: 2022-09-13 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a3811a..df7ccb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,8 @@ # Contributing -To contribute to this repository: +To contribute to this repository: 1. Create a [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) of the repository. 2. [Clone](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository) the forked repository. 3. Checkout a new branch (using `git checkout -b name_of_branch`), where name of branch should be replaced by `your_github_username/description_of_feature`. For instance, `jorgensd/add_guidelines`. 4. Add your contribution and push it to your fork. 5. Make a [pull request from your fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork). - diff --git a/Dockerfile b/Dockerfile index 7e74e6b..b7282ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,4 +36,4 @@ USER root RUN chown -R ${NB_UID} ${HOME} USER ${NB_USER} -ENTRYPOINT [] \ No newline at end of file +ENTRYPOINT [] diff --git a/Makefile b/Makefile index 88c798a..29a37a1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -# List of Python demos (without file extenion) from the repo `demo` to include in the jupyterbook. +# List of Python demos (without file extenion) from the repo `demo` to include in the jupyterbook. # These files should be listed in `docs/_toc.yml` DEMOS = demo -doc: # Generate Sphinx HTML documentation, including API docs +doc: # Generate Sphinx HTML documentation, including API docs # We use --set-kernel with jupytext to make it possible for binder to pick it up @for demo in ${DEMOS}; do \ jupytext --to=ipynb --set-kernel=python3 demo/$$demo.py --output=docs/$$demo.ipynb ;\ diff --git a/README.md b/README.md index fce77d5..9d7f374 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,3 @@ The documentation for this repository can be found [here](https://jorgensd.githu [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jorgensd/reproducibility/gh-pages?labpath=_sources) [![Jupyter Book Badge](https://jupyterbook.org/badge.svg)](https://jorgensd.github.io/reproducibility) [![MIT License](https://img.shields.io/github/license/jorgensd/reproducibility)](LICENSE) - diff --git a/demo/demo.py b/demo/demo.py index ceb3d49..ac1e1c2 100644 --- a/demo/demo.py +++ b/demo/demo.py @@ -4,17 +4,13 @@ # # SPDX-License-Identifier: MIT # - - # + [markdown] # We start a new cell explicitly by using the "+" sign and can explicitly end # it by using the "-" sign. # - - # If we do not use explicit indicators for starting or ending a cell, it creates a # new cell whenever there is a blank line - # This is a new cell - # Comments can be added to code by not adding a new line before the code import mypackage diff --git a/docs/_config.yml b/docs/_config.yml index b9be07b..f2433a8 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -36,6 +36,3 @@ sphinx: - 'sphinx.ext.autodoc' - 'sphinx.ext.napoleon' - 'sphinx.ext.viewcode' - - - diff --git a/docs/api.rst b/docs/api.rst index 283b1c3..bcea409 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -2,4 +2,4 @@ API Reference ============= .. automodule:: mypackage - :members: \ No newline at end of file + :members: diff --git a/docs/part1/packaging.md b/docs/part1/packaging.md index ea85bb3..a3006bc 100644 --- a/docs/part1/packaging.md +++ b/docs/part1/packaging.md @@ -4,4 +4,3 @@ To be able to create a python package, we need a folder with the name of the pac ## Pyproject.toml - diff --git a/docs/part1/testing.md b/docs/part1/testing.md index 94cfd7d..f00b526 100644 --- a/docs/part1/testing.md +++ b/docs/part1/testing.md @@ -1 +1 @@ -# Testing \ No newline at end of file +# Testing diff --git a/docs/part1/typing.md b/docs/part1/typing.md index 445c584..a95ca06 100644 --- a/docs/part1/typing.md +++ b/docs/part1/typing.md @@ -1 +1 @@ -# Python typing \ No newline at end of file +# Python typing diff --git a/docs/part2/citeable.md b/docs/part2/citeable.md index fbc2c5b..95a011d 100644 --- a/docs/part2/citeable.md +++ b/docs/part2/citeable.md @@ -1,4 +1,3 @@ # Make a repository citable -The easiest way to make your repository citable is to add a `CITATION.cff` file to the repository, as it is supported by both +The easiest way to make your repository citable is to add a `CITATION.cff` file to the repository, as it is supported by both [Zenodo's](https://zenodo.org/) and it's [Github integration](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content) and [Github](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files) itself. - diff --git a/docs/part2/github.md b/docs/part2/github.md index 0c9b0d4..f08734b 100644 --- a/docs/part2/github.md +++ b/docs/part2/github.md @@ -1,2 +1 @@ # Github tools - diff --git a/docs/part2/issues.md b/docs/part2/issues.md index 95ba4c7..c60d0a5 100644 --- a/docs/part2/issues.md +++ b/docs/part2/issues.md @@ -1,4 +1,2 @@ # Issue template See [Adding an issue template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository) for more information. - - diff --git a/docs/part3/auto_api.md b/docs/part3/auto_api.md index ca7e3d4..ef2e7f9 100644 --- a/docs/part3/auto_api.md +++ b/docs/part3/auto_api.md @@ -1 +1 @@ -# Auto-generation \ No newline at end of file +# Auto-generation diff --git a/docs/part3/auto_demos.md b/docs/part3/auto_demos.md index f1fcd58..d42f225 100644 --- a/docs/part3/auto_demos.md +++ b/docs/part3/auto_demos.md @@ -14,4 +14,4 @@ This is illustrated in the following auto-converted demo. # Auto-conversion of demos -In the [Makefile](https://github.com/jorgensd/reproducibility/blob/main/Makefile) one can find the instructions for auto-converting the demos and building the book. \ No newline at end of file +In the [Makefile](https://github.com/jorgensd/reproducibility/blob/main/Makefile) one can find the instructions for auto-converting the demos and building the book. diff --git a/docs/part3/publishing.md b/docs/part3/publishing.md index eb983da..83d8bb2 100644 --- a/docs/part3/publishing.md +++ b/docs/part3/publishing.md @@ -4,5 +4,4 @@ ## `_toc.yml` -## `_config.yml` - +## `_config.yml` diff --git a/pyproject.toml b/pyproject.toml index d006f20..cdfc5e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ pypi = [ [tool.mypy] ignore_missing_imports = true # Does not show errors when importing untyped libraries exclude = [ # We only want mypy to consider files that are not generated in installing or building documentation - "docs/", + "docs/", "build/" ] files = [ # Folder to which files that should be checked by mypy @@ -53,4 +53,4 @@ files = [ # Folder to which files that should be checked by mypy addopts = "--cov=mypackage --cov-report html --cov-report term-missing -v" testpaths = [ "test" -] \ No newline at end of file +] diff --git a/src/mypackage/__init__.py b/src/mypackage/__init__.py index a1a8f90..f84d4eb 100644 --- a/src/mypackage/__init__.py +++ b/src/mypackage/__init__.py @@ -1,12 +1,11 @@ - # Copyright (C) 2022 Jørgen Schartum Dokken # # This file is part of my_package # SPDX-License-Identifier: MIT - import importlib.metadata -from .functions import addition, print_add +from .functions import addition +from .functions import print_add __version__ = importlib.metadata.version(__package__) diff --git a/src/mypackage/functions.py b/src/mypackage/functions.py index 74f9a69..5c1b8c9 100644 --- a/src/mypackage/functions.py +++ b/src/mypackage/functions.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2022 Jørgen Schartum Dokken # # This file is part of mypackage @@ -9,12 +7,12 @@ def addition(a: int, b: int) -> int: - """ Computes a+b """ + """Computes a+b""" return a + b def print_add(a: int, b: int) -> int: - """ Computes and prints a + b""" + """Computes and prints a + b""" c = a + b print(c) return c diff --git a/test/test_code.py b/test/test_code.py index 5ca3b70..e764380 100644 --- a/test/test_code.py +++ b/test/test_code.py @@ -2,7 +2,6 @@ # # This file is part of my_package # SPDX-License-Identifier: MIT - from mypackage import addition From a071760dad24c6ab755e28519a255ec6744bbe66 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Tue, 11 Oct 2022 09:18:57 +0200 Subject: [PATCH 3/4] Add pre-commit to docs --- docs/_toc.yml | 1 + docs/part1/pre_commit.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 docs/part1/pre_commit.md diff --git a/docs/_toc.yml b/docs/_toc.yml index 779f090..a1848cc 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -9,6 +9,7 @@ parts: - file: "part1/linting" - file: "part1/typing" - file: "part1/testing" + - file: "part1/pre_commit.md" - caption: Github tools chapters: diff --git a/docs/part1/pre_commit.md b/docs/part1/pre_commit.md new file mode 100644 index 0000000..14b156b --- /dev/null +++ b/docs/part1/pre_commit.md @@ -0,0 +1,21 @@ +# Pre-commit hooks + +Using pre-commit hooks is a great way to make sure that the code you commit to the repo follows some common style. This way, you will not end up changing the style back and forth when collaborating with other people. + +The file [`.pre-commit-config.yaml`](../../.pre-commit-config.yaml) contains a set of default pre-commit hooks. You can find more hooks in the [pre-commit home page](https://pre-commit.com/hooks.html). + +To install the pre-commit hook you first need to install pre-commit +``` +python -m pip install pre-commit +``` +and then install the pre-commit hook +``` +pre-commit install +``` +The pre-commit hook will only run on the files you commit to the repo. To run the pre-commit hook on all the files in your repo, you can execute the command. +``` +pre-commit run --all +``` + +## Running pre-commit in CI +You can also run the pre-commit hooks as a part of your continuous integration. You can check out the [GitHub action](https://github.com/pre-commit/action), or you can set up at webhook using [pre-commit.ci](https://pre-commit.ci). From 967dbc5c6e67f1bb2ea75cd528e38009d40cd5c9 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Tue, 11 Oct 2022 09:22:45 +0200 Subject: [PATCH 4/4] Remove link to pre-commit hook --- docs/part1/pre_commit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/part1/pre_commit.md b/docs/part1/pre_commit.md index 14b156b..f3a0ac0 100644 --- a/docs/part1/pre_commit.md +++ b/docs/part1/pre_commit.md @@ -2,7 +2,7 @@ Using pre-commit hooks is a great way to make sure that the code you commit to the repo follows some common style. This way, you will not end up changing the style back and forth when collaborating with other people. -The file [`.pre-commit-config.yaml`](../../.pre-commit-config.yaml) contains a set of default pre-commit hooks. You can find more hooks in the [pre-commit home page](https://pre-commit.com/hooks.html). +The file `.pre-commit-config.yaml` in the root of the repo contains a set of default pre-commit hooks. You can find more hooks in the [pre-commit home page](https://pre-commit.com/hooks.html). To install the pre-commit hook you first need to install pre-commit ```