Skip to content

Commit

Permalink
Update README and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwermelinger committed Jan 5, 2024
1 parent 9c8f91a commit 90293ca
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 491 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, The Open University
Copyright (c) 2024, The Open University
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
138 changes: 101 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,139 @@
- is easy to install, use and understand
- adheres to good coding practices.

To learn what the library provides and how to use it, see https://dsa-ou.github.io/paddles.

The rest of this file documents how the library is developed,
in case you want to contribute.

## Licence
The code and text in this repository are Copyright © 2024 by The Open University, UK.
The code is licensed under a [BSD 3-clause licence](LICENSE.MD).
The text is licensed under a
[Creative Commons Attribution 4.0 International Licence](http://creativecommons.org/licenses/by/4.0).

By contributing code or documentation to this repository,
you agree to transfer the copyright of your contribution to The Open University, UK,
and that your contribution will be subject to the above licence.

## Environment
We use Python 3.10 and the [poetry](https://python-poetry.org) packaging and dependency manager.
To set up the environment:
- if you don't have Python 3.10, [install it](https://www.python.org/downloads/release/python-31011/)
- if you don't have `poetry`, [install it](https://python-poetry.org/docs/#installing-with-the-official-installer)
- clone this repository
- open a terminal and go to the folder to where you cloned this project
- enter `poetry install`

This installs the software needed to develop `paddles`, in a new
[virtual environment](https://docs.python.org/3/glossary.html#term-virtual-environment),
in order to not interfere with your existing Python projects.

To use the environment, while developing `paddles`, enter `poetry run C`
to execute command `C` in the virtual environment for `paddles`.

Alternatively, you can enter `poetry shell` to activate the environment, and
then you can just enter `C` to execute the command.
To deactivate the environment, enter `exit`.

In the rest of this document, the notation `[poetry run] C` means that you should enter
- `poetry run C` if you haven't activated the environment with `poetry shell`
- `C` if you have.

To finish the setup, you may optionally enter `[poetry run] pre-commit install`
to install pre-commit hooks (scripts that are run when committing changes to a repository).
Our environment has configured hooks that test, check and format your code and
generate the documentation before you commit your changes to the repository.

This project folder contains the following files and subfolders:

- `README.md`: this file
- `LICENSE`: the code licence
- `pyproject.toml`: project configuration
- `poetry.lock`: list of the packages installed by `poetry install`
- `.pre-commit-config.yaml`: list of pre-commit hooks
- `paddles/`: subfolder with the library's code
- `tests/`: subfolder with the test code
- `docs/`: subfolder with the documentation generated from the library code

## Testing

The library is tested with [pytest](https://pytest.org).
We use [pytest](https://pytest.org) to test `paddles`.
The unit tests are in the `tests` subfolder, with one test file per library module.
There's at least one test function per creator or modifier method.
There are no test functions for inspector methods: they are indirectly tested by
using them for closed-box (black-box) testing of the modifiers.

Each test file has the same structure: helper functions,
fixtures (functions that generate test data), tests for creator methods,
tests for modifier methods, used separately, and finally tests for combined use of modifiers.
Each test file contains, in this order:
1. helper functions
1. fixtures (functions that generate test data)
1. tests for creator methods
1. tests for modifier methods, used separately, and finally
1. tests for combined use of modifiers.

There are also simple interactive examples of how to use a class in that class's docstring,
in folder `paddles`. These are used as [doctests](https://docs.python.org/3.10/library/doctest.html).
Additionally, there are simple interactive examples of how to use a class in that class's docstring,
in subfolder `paddles`. These are used as [doctests](https://docs.python.org/3.10/library/doctest.html).

To run all tests, the doctests in `paddles` and the unit tests in `tests`, open a terminal,
go the project's main folder, i.e. the parent of `tests`, and enter `poetry run pytest`.
This will produce a report of which tests passed and which failed.
Any library code lines that weren't executed by the tests are also reported.
(We aim for 100% coverage.)
To run all tests, i.e. the doctests in `paddles` and the unit tests in `tests`,
enter `[poetry run] pytest`.

This will produce a report of which tests passed, which failed, and which
library code lines weren't executed. (We aim for 100% coverage.)
If two implementations of the same ADT use different messages
for the same exception for the same method, the tests fail.

## Linting

We check and format our code with [ruff](https://astral.sh/ruff).
We check and format all code (library and tests) with [ruff](https://astral.sh/ruff).

Open a terminal in the main project folder and enter `poetry run ruff check`.
The checked style rules are given [here](https://docs.astral.sh/ruff/rules),
with further explanations when you click on a rule's name.
To check the code against over 700 style rules, enter `[poetry run] ruff check`.
If `ruff` reports rule violations, open the [rules page](https://docs.astral.sh/ruff/rules),
search for the reported rule number (e.g. E101), and click on the rule name
(e.g. mixed-spaces-and-tabs) next to it in the page.
This will open a new page explaining the violated rule and its rationale, with an example,
like [this](https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs/).

To automatically fix violations, if possible, add the command line options
`--fix --unsafe-fixes` and check the changes made by `ruff`.
To automatically fix violations, when possible,
enter `[poetry run] ruff check --fix --unsafe-fixes` and double-check
the modifications made by `ruff`.

To automatically ignore the flagged code lines for a particular file,
enter `poetry run ruff check path/to/file.py --add-noqa`.
enter `[poetry run] ruff check path/to/file.py --add-noqa`.
This will add comments of the form `# noqa: ...` where `...` is the number of
the violated rule.

This should be used sparingly. For example, in the test files, the fixtures
that generate classes are on purpose named with initial uppercase, as classes are,
which violates the rule that function names and arguments should be in lowercase.

Finally, enter `poetry run ruff format` to format all the code.
Finally, enter `[poetry run] ruff format` to format the code.

## Type checking
We type check the code with [pytype](https://google.github.io/pytype).
Enter `poetry run pytype .` to type check all code.
Enter `[poetry run] pytype .` (note the dot) to type check all code.

## Documenting
We use [pydoc](https://pydoc.dev) to generate the documentation from the docstrings.

To check the documents during development, enter `poetry run pdoc paddles &`
to open a live site with the documentation. Any changes to docstrings of
library files are immediately reflected in the site, upon saving the files.

## Pre-commit hooks
If you enter `poetry run pre-commit install`, every time you commit your code,
these steps are done automatically on the _staged_ files only:
1. test the code
2. check the code for any type or style violations
3. format the code
4. generate the documentation.

If a test or check fails in steps 1 and 2 or a file is modified in steps 3 and 4,
We use [pdoc](https://pdoc.dev) to generate the documentation from the docstrings.

To check the documents during development, enter `[poetry run] pdoc paddles &`
to open a live site with the documentation. Any changes to the docstrings of
the library files are immediately reflected in the site, upon saving the files.

## Comitting
If you installed the pre-commit hooks when setting up the [environment](#environment)
then every time you commit your code,
these steps are done automatically on the _staged_ files:
1. test the code with `pytest`
2. type check the code with `pytype`
3. check (but _don't_ fix) the code with `ruff`
4. format the code with `ruff`
5. generate the documentation with `pdoc`.

If a test or check fails in steps 1–3 or if a file is modified in steps 4–5,
then the commit doesn't go ahead.
This allows you to review the errors and the automatically applied changes,
stage the modified files, and commit again.

Due to the automated four steps, each commit takes several seconds to complete.
But when it does, you know that your code hasn't broken existing tests,
Due to the automated steps, each commit takes many seconds to complete.
But when it successfully completes, you know that your code hasn't broken existing tests,
isn't poorly formatted, and has up-to-date documentation.
32 changes: 18 additions & 14 deletions docs/paddles.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ <h1 class="modulename">

<div class="docstring"><p><code><a href="">paddles</a></code> is a pedagogical algorithms and data structures library.</p>

<p>It currently implements the Stack, Queue and Deque <strong>abstract data types (ADTs)</strong>.</p>
<p>It currently implements the Stack, Queue and Deque abstract data types (ADTs).</p>

<p>The code repository is at <a href="https://github.com/dsa-ou/paddles">https://github.com/dsa-ou/paddles</a>.
The formatted documentation is at <a href="https://dsa-ou.github.io/paddles">https://dsa-ou.github.io/paddles</a>.</p>

<h2 id="licence">Licence</h2>

<p>The code and text in this repository are
Copyright © 2024 by The Open University, UK.
The code is licensed under a <a href="../LICENSE.MD">BSD-3-clause licence</a>.
The text is licensed under a
<p><code><a href="">paddles</a></code> is Copyright © 2024 by The Open University, UK.
The code is licensed under a <a href="https://github.com/dsa-ou/paddles/blob/main/LICENSE">BSD-3-clause licence</a>.
The documentation is licensed under a
<a href="http://creativecommons.org/licenses/by/4.0">Creative Commons Attribution 4.0 International Licence</a>.</p>
</div>

Expand All @@ -67,16 +69,18 @@ <h2 id="licence">Licence</h2>

<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="sd">&quot;&quot;&quot;`paddles` is a pedagogical algorithms and data structures library.</span>
</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="sd">It currently implements the Stack, Queue and Deque **abstract data types (ADTs)**.</span>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="sd">It currently implements the Stack, Queue and Deque abstract data types (ADTs).</span>
</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a>
</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="sd">## Licence</span>
</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a>
</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="sd">The code and text in this repository are</span>
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="sd">Copyright © 2024 by The Open University, UK.</span>
</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a><span class="sd">The code is licensed under a [BSD-3-clause licence](../LICENSE.MD).</span>
</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a><span class="sd">The text is licensed under a</span>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="sd">[Creative Commons Attribution 4.0 International Licence](http://creativecommons.org/licenses/by/4.0).</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a><span class="sd">&quot;&quot;&quot;</span>
</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="sd">The code repository is at https://github.com/dsa-ou/paddles.</span>
</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a><span class="sd">The formatted documentation is at https://dsa-ou.github.io/paddles.</span>
</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a>
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="sd">## Licence</span>
</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a>
</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a><span class="sd">`paddles` is Copyright © 2024 by The Open University, UK.</span>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="sd">The code is licensed under a [BSD-3-clause licence](https://github.com/dsa-ou/paddles/blob/main/LICENSE).</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a><span class="sd">The documentation is licensed under a</span>
</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a><span class="sd">[Creative Commons Attribution 4.0 International Licence](http://creativecommons.org/licenses/by/4.0).</span>
</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a><span class="sd">&quot;&quot;&quot;</span>
</span></pre></div>


Expand Down
Loading

0 comments on commit 90293ca

Please sign in to comment.