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/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0608e6c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +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 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/_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/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 acd4f33..723a6b3 100644 --- a/docs/part1/packaging.md +++ b/docs/part1/packaging.md @@ -10,7 +10,7 @@ We recommend using the source layout. See [this chapter](https://py-pkgs.org/04- A [toml](https://toml.io/en/) (Tom's Obivous Minimal Language) file is a plain-text file, consisting of [tables](https://toml.io/en/v1.0.0#table) which are a selection of key-value pairs. -An example is +An example is ```toml [project] name = "catch_us" @@ -18,11 +18,11 @@ authors = [ {name = "Per Ulv", email = "per@acme.no"}, {name = "Bippe Stankelbein", email = "bippe@roadrunner.no"} ] -version = "x.y.z" +version = "x.y.z" description = "Meep Meep" -# "readme" the description field in your package, +# "readme" the description field in your package, # see: https://python-poetry.org/docs/pyproject/#readme -readme = "README.md" +readme = "README.md" requires-python = ">=3.8" # Path to license file, see: https://spdx.org/licenses/ # for a selection of licenses @@ -51,4 +51,4 @@ test = ["pytest"] Then, when installing the package, you call `pip3 install .[test]` instead of `pip3 install .` to get the additional dependencies. ### Other tables -For options related to coverage reports and code consistency, see the [Coverage](./coverage) and [Linting](./linting.md) section, respectively. \ No newline at end of file +For options related to coverage reports and code consistency, see the [Coverage](./coverage) and [Linting](./linting.md) section, respectively. diff --git a/docs/part1/pre_commit.md b/docs/part1/pre_commit.md new file mode 100644 index 0000000..f3a0ac0 --- /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` 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 +``` +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). 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 0afa463..c5a819d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,10 +9,10 @@ authors = [ {name = "Jørgen S. Dokken", email = "dokken@simula.no"}, {name = "Henrik N. Finsberg", email = "henriknf@simula.no"} ] -version = "0.1.0" +version = "0.1.0" description = "Minimal package for adding two numbers" # "readme" the description field in your package, see: https://python-poetry.org/docs/pyproject/#readme -readme = "README.md" +readme = "README.md" requires-python = ">=3.8" # Path to license file, see: https://spdx.org/licenses/ for options license = {file = "LICENSE"} @@ -46,7 +46,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 @@ -58,4 +58,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