@@ -30,7 +30,7 @@ code organized and reliable.
3030 repository is a GitHub template, which means that when you create a new
3131 repository based on this template, it will already be set up with * git* for
3232 version control.
33-
33+
3434- ** Testing:** Automated tests help ensure that your code behaves as expected.
3535 For example, if you know the expected output of a function for certain
3636 inputs, you can write a test that verifies this behavior automatically.
@@ -46,6 +46,13 @@ code organized and reliable.
4646 ensures that all required dependencies are * explicitly* listed in the
4747 ` project_template_env.yml ` file, which is important for reproducibility.
4848
49+ - ** Code Linting and Formatting:** Linting checks your code for errors, bad
50+ practices, and style violations (e.g. unused imports or undefined
51+ variables). A formatter automatically rewrites your code to follow
52+ consistent style rules (e.g. a specific maximum line length). This template
53+ uses [ Ruff] ( https://docs.astral.sh/ruff/ ) which is a fast Python linter and
54+ formatter.
55+
4956- ** Clean Code:** Writing clean and readable code is always advisable. Some
5057 useful principles include:
5158
@@ -130,15 +137,13 @@ The repository is organized into four main folders.
130137# # 3. How To Use This Template
131138
132139** Prerequisites:** To use this template, you need a GitHub account and `git`
133- installed on your local machine. To clone repositories via SSH , you should also
134- set up SSH keys for your GitHub account (cloning via HTTPS is also possible).
135- In addition, you need `conda` installed to create and manage the Python
136- environment used in this project. If you want to compile the LaTeX paper, you
137- will also need a LaTeX distribution such as [* TeX
140+ installed on your local machine. In addition, you need `conda` installed to
141+ create and manage the Python environment used in this project. If you want to
142+ compile the LaTeX paper, you will also need a LaTeX distribution such as [* TeX
138143Live* ](https:// www.tug.org/ texlive/ ) installed on your machine.
139144
140145If this is the first time you are using this template, it is recommended to
141- work through the following steps:
146+ work through all of the following steps:
142147
1431481 . ** Use the Template and Clone:** On the GitHub page of this repository, click
144149 on " Use this template" to create a new repository based on this template.
@@ -186,30 +191,49 @@ work through the following steps:
186191 `our_library` folder; and `results` mirrors `experiments` . This is a useful
187192 convention that helps keep things organized.
188193
189- 4 . ** Run the Tests:** Take a look at `source/ our_library/ some_functions.py` and
190- the corresponding tests in `source/ tests/ test_some_functions.py` . Note that
191- the tests use `@ pytest.mark.parametrize` , which is a convenient way to run
192- the same test with multiple inputs. Run `pytest .` from the `source`
193- directory to see the automated tests in action. Feel free to extend
194- `our_library` and add additional tests.
194+ 4 . ** Run the Tests and Ruff:** Take a look at
195+ `source/ our_library/ some_functions.py` and the corresponding tests in
196+ `source/ tests/ test_some_functions.py` . Note that the tests use
197+ `@ pytest.mark.parametrize` , which is a convenient way to run the same test
198+ with multiple inputs. Run `pytest .` from the `source` directory to see the
199+ automated tests in action. Feel free to extend `our_library` and add
200+ additional tests.s
201+
202+ In addition, you can manually run the linter and formatter via
203+ ```
204+ ruff check .
205+ ruff format .
206+ ```
195207
1962085 . ** Trigger the GitHub Workflow:** Take a look at the GitHub workflow
197209 `run_pytest.yml` in `.github/ workflows` . This workflow is triggered
198- automatically whenever you push changes to GitHub (see the section
199- beginning with `on` ). It creates a fresh environment, installs the
200- dependencies, and runs the tests. You can make a small change to the code
201- (e.g. by adding another test case to `test_some_functions.py` ), push it to
202- GitHub, and then check the results in the * Actions* tab of your GitHub
203- repository.
204-
205- 6 . ** Run the Experiments:** Take a look at the experiments in the `experiments`
206- folder. Note how reusable code from `source/ our_library` is imported and
207- how results are written to the `results` folder. Run the first experiment
208- to see this in action.
209-
210- 7 . ** Compile the LaTeX Paper:** Try compiling the LaTeX paper in
210+ automatically whenever you push changes to GitHub (see the section beginning
211+ with `on` ). It creates a fresh environment, installs the dependencies,
212+ checks the code using Ruff, and runs the tests using `pytest` . You can make
213+ a small change to the code (e.g. by adding another test case to
214+ `test_some_functions.py` ) and push it to GitHub. Then, open your browser, go
215+ to your repository and click on the * Actions* tab to inspect the workflow.
216+
217+ 6 . ** Enable Automatic Checks Before Commits:** You can run formatting and
218+ linting automatically before each commit using the `pre- commit` package.
219+ This helps catch issues early and keeps the codebase clean without any extra
220+ effort. Run `pre- commit install` , which uses the configuration specified in
221+ the `.pre- commit- config.yaml` file . After this, every time you create a
222+ commit (e.g. via the terminal or an editor like VS Code), the code will be
223+ automatically checked and formatted using Ruff. If issues are found, the
224+ commit will be blocked until they are resolved.
225+
226+ 7 . ** Run the Experiments:** Take a look at the experiments in the `experiments`
227+ folder. Note how reusable code from `source/ our_library` is imported and how
228+ results are written to the `results` folder. Run the first experiment to see
229+ this in action. Feel free to add an additional experiment. For this, you
230+ could add code to `source/ our_library` , write a corresponding test, import
231+ the new function in your experiment and finally generate and save some
232+ results.
233+
234+ 8 . ** Compile the LaTeX Paper:** Try compiling the LaTeX paper in
211235 `documentation/ paper` . The template demonstrates how figures from the
212236 `results` folder can be included in the paper.
213237
214- 8 . ** Adapt and Extend the Template:** Adapt and extend the template as needed
238+ 9 . ** Adapt and Extend the Template:** Adapt and extend the template as needed
215239 for your own research project.
0 commit comments