Skip to content

Commit efe1033

Browse files
authored
Merge pull request #157 from FAIR2-for-research-software/ns-rse/146-move-conda-setup
2 parents ad011b7 + 9fa9529 commit efe1033

File tree

3 files changed

+103
-144
lines changed

3 files changed

+103
-144
lines changed

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ contact: 'n.shephard@sheffield.ac.uk' # FIXME
6060
# Order of episodes in your lesson
6161
episodes:
6262
- introduction.md
63+
- git_hygiene.md
6364
- branching.md
6465
- diverging_branches.md
65-
- git_hygiene.md
6666
- hooks.md
6767
- continuous_integration.md
6868
# - reviewing.md

episodes/hooks.md

Lines changed: 87 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ exec git pull
229229

230230
## Pre-Commit
231231

232+
::::::::::::::::::::::::::::::::::::: callout
233+
234+
## Extra Setup
235+
236+
This section requires you to either install `pre-commit` at the system level or setup a Virtual Environment.
237+
238+
Instructions on doing so can be found at the bottom of the [document](hooks.md#installing_pre-commit).
239+
240+
::::::::::::::::::::::::::::::::::::::::::::::::
241+
232242
Pre-commit hooks that run before commits are made are _really_ useful to the extent that they require special discussion
233243
and will be the focus of the remainder of this episode. Why are they so useful? It's because they shorten the feedback
234244
loop of changes that need to be made when checking and linting code.
@@ -254,7 +264,7 @@ hook that resides at `.git/hooks/pre-commit`, although we will look at that file
254264

255265
::::::::::::::::::::::::::::::::::::::::::::::::
256266

257-
### Why are Pre-Commit hooks so important?
267+
## Why are Pre-Commit hooks so important?
258268

259269
You may be wondering why running hooks prior to commits is so important. The short answer, as we've already hear, is
260270
that it reduces the feedback loop and speeds up the pace of development. The long answer is that it only really becomes
@@ -267,8 +277,9 @@ base, making some changes and committing them.
267277
other than Python. Many Linux systems have [pre-commit][pc] in their package management systems so if you are using
268278
Linux or OSX you can install these at the system level.
269279

270-
However, for this course the setup instructions asked you to install [Miniconda][miniconda3] and we can install
271-
[`pre-commit`][pc] in a Conda environment to leverage it. The steps to do so are
280+
However, for this section of the course you should install [Miniconda][miniconda3] so we can install
281+
[`pre-commit`][pc] in a Conda environment to leverage it. There are instructions at the bottom of this page on how to
282+
install Miniconda. Once you have done so you can proceed with creating a conda environment. The steps to do so are
272283

273284
1. Create a Conda environment called `python-maths` with `conda create -n python-maths python=3.11`
274285
2. Activate the newly created `python-maths` environment.
@@ -349,29 +360,6 @@ Proceed ([y]/n)?
349360
pre-commit installed at .git/hooks/pre-commit
350361
```
351362

352-
::::::::::::::::::::::::::::::::::::: callout
353-
354-
## Install Pre-commit globally
355-
356-
Examples of installing [pre-commit][pc] at the system level for different Linux systems or OSX. Note you will
357-
need to have `root` access to install packages on your Linux system.
358-
359-
``` bash
360-
# Arch Linux
361-
❱ pacman -Syu pre-commit
362-
# Gentoo
363-
❱ emerge -av pre-commit
364-
# Debin/Ubuntu
365-
❱ apt-get install pre-commit
366-
# OSX Homebrew
367-
❱ brew install pre-commit
368-
```
369-
370-
The advantage of this is that you will be able to `pre-commit install` in any repository without first having to
371-
activate a virtual environment.
372-
373-
::::::::::::::::::::::::::::::::::::::::::::::::
374-
375363
::::::::::::::::::::::::::::::::::::: challenge
376364

377365
## Challenge 2 - Checking out the installed `pre-commit` hook
@@ -599,16 +587,18 @@ of the others that are defined.
599587

600588
## Solution 1 : What version of the `numpydoc` repo is configured
601589

602-
Using [grep][grep] to search for the `numpydoc` string in the `.pre-commit-config.yaml` we can hone in on the `repo` and
603-
its associated `rev`.
590+
Using [grep][grep] to search for the [`numpydoc`][numpydoc] string in the `.pre-commit-config.yaml` we can hone in on
591+
the `repo` and its associated `rev`.
604592

605593
``` bash
606594
❱ grep -A1 numpydoc .pre-commit-config.yaml | grep -B1 rev
607595
- repo: https://github.com/numpy/numpydoc
608596
rev: v1.6.0
609597
```
610598

611-
We see that it is `v1.6.0` that is currently configured for `numpydoc`.
599+
We see that it is `v1.6.0` that is currently configured for [`numpydoc`][numpydoc].
600+
601+
**NB** This hook ensures the docstrings of Python functions comply with thet [numpydocstyle][numpydocstyle] guide.
612602

613603
:::::::::::::::::::::::::::::::::
614604

@@ -784,64 +774,12 @@ The file should then be staged, committed and pushed.
784774
## Adding repos
785775
786776
The definitive [list][pc-hooks] of `pre-commit` repos is maintained on the official website. Each entry links to the
787-
GitHub repository and most contain in their `README.md` instructions on how to use the hooks.
788-
789-
<!-- ::::::::::::::::::::::::::::::::::::: challenge -->
790-
791-
<!-- ## Challenge 7: Add the `numpydoc` repo, exclude the `tests/` and `doc/` directories and run it against-->
792-
<!-- the code base -->
793-
794-
<!-- The [numpydoc](https://github.com/numpy/numpydoc) repo defines hooks that check the Python docstrings -->
795-
<!-- conform to the [Numpydoc style guide](https://numpydoc.readthedocs.io/en/latest/format.html). Following the -->
796-
<!-- instructions add the repo to the `.pre-commit-config.yaml` (on a new branch) -->
797-
798-
<!-- :::::::::::::::::::::::: solution -->
799-
800-
<!-- ## Solution -->
801-
802-
<!-- Create a branch to undertake the work on. -->
803-
804-
<!-- ``` bash -->
805-
<!-- ❱ git switch main -->
806-
<!-- ❱ git pull -->
807-
<!-- ❱ git switch -c ns-rse/pre-commit-numpydoc -->
808-
<!-- ``` -->
809-
810-
<!-- The following should be added to your `.pre-commit-config.yaml` -->
811-
812-
<!-- ``` yaml -->
813-
<!-- - repo: https://github.com/numpy/numpydoc -->
814-
<!-- rev: v1.6.0 -->
815-
<!-- hooks: -->
816-
<!-- - id: numpydoc-validation -->
817-
<!-- exclude: | -->
818-
<!-- (?x)( -->
819-
<!-- tests/| -->
820-
<!-- docs/ -->
821-
<!-- ) -->
822-
<!-- ``` -->
823-
824-
<!-- Check that the code base passes the checks, correct any errors that are highlighted. -->
825-
826-
<!-- ``` bash -->
827-
<!-- ❱ pre-commit run numpydoc --all-files -->
828-
<!-- ``` -->
829-
830-
<!-- The file should then be staged, committed and pushed. -->
831-
832-
<!-- ``` bash -->
833-
<!-- ❱ git add .pre-commit-config.yaml -->
834-
<!-- ❱ git commit -m "pre-commit : adds the numpydoc repo/hook" -->
835-
<!-- ❱ git push -->
836-
<!-- ``` -->
837-
838-
<!-- ::::::::::::::::::::::::::::::::: -->
839-
840-
<!-- :::::::::::::::::::::::::::::::::::::::::::::::: -->
777+
GitHub repository and most contain in their `README.md` instructions on how to use the hooks. Which you will want to use
778+
will depend very much on your project.
841779

842780
## Local repos
843781

844-
Local repo are those that do not use hooks defined by others and are instead defined by the user. This comes in handy
782+
Local repos are those that do not use hooks defined by others and are instead defined by the user. This comes in handy
845783
when you want to run checks which have dependencies that are specific to the code such as running [pylint][pylint] which
846784
needs to import all the dependencies that are used or run a test suite.
847785

@@ -978,12 +916,76 @@ the Pre-commit hooks as part of the Continuous Integration on GitHub which is th
978916

979917
::::::::::::::::::::::::::::::::::::::::::::::::
980918

919+
## Installing Pre-commit
920+
921+
### Install Pre-commit globally
922+
923+
Examples of installing [pre-commit][pc] at the system level for different Linux systems or OSX. Note you will
924+
need to have `root` access to install packages on your Linux system.
925+
926+
``` bash
927+
# Arch Linux
928+
pacman -Syu pre-commit
929+
# Gentoo
930+
emerge -av pre-commit
931+
# Debin/Ubuntu
932+
apt-get install pre-commit
933+
# OSX Homebrew
934+
brew install pre-commit
935+
```
936+
937+
The advantage of this is that you will be able to `pre-commit install` in any repository without first having to
938+
activate a virtual environment.
939+
940+
### Virtual Environments
941+
942+
The other option is to install `pre-commit` within a Python Virtual Environment. If you are already familiar with using
943+
these then you can simply `pip install pre-commit` and you are good to go, although note that `pre-commit` will need
944+
installing in _every_ new environment you create that you want to use it.
945+
946+
If you are not familiar with Python Virtual Environments you can follow the instructions below to install and setup
947+
[miniconda3][miniconda3] or [miniforge3][miniforge3].
948+
949+
::::::::::::::::::::::::::::::::::::: callout
950+
951+
## Anaconda Licensing
952+
953+
It is important to fully understand and adhere to the [Anaconda Licensing][anacondalicense] which permits
954+
the use of their software (including Miniconda) in educational and research environments _only_ if there is no
955+
commercial benefit. If the work you undertake involves commercial collaboration you should seek alternative solutions
956+
for virtual environments (e.g. [miniforge3][miniforge3] or [virtualenvwrapper][virtualenvwrapper]).
957+
958+
::::::::::::::::::::::::::::::::::::::::::::::::
959+
960+
### Installing Miniconda/Miniforge3
961+
962+
Please follow the instructions at [Installing Miniconda](https://docs.anaconda.com/free/miniconda/miniconda-install/)
963+
for your Operating System.
964+
965+
Should you chose to use `miniforge3` the downloads and installation instructions for different operating systems can be
966+
found [here][miniforge3-install].
967+
968+
### Creating A Virtual Environment
969+
970+
You will have to create a virtual environment to undertake the course. If you have installed Miniconda as described
971+
above you open a terminal (Windows use the Git Bash Shell) and create a Virtual Environment called `git-collaboation`.
972+
973+
``` bash
974+
conda create --name git-collab python=3.11
975+
conda activate git-collab
976+
```
977+
978+
[anacondalicense]: https://www.anaconda.com/blog/update-on-anacondas-terms-of-service-for-academia-and-research
981979
[bash]: https://www.gnu.org/software/bash/
982980
[black]: https://black.readthedocs.io/en/stable/index.html
983981
[gh]: https://github.com
984982
[gl]: https://gitlab.com
985983
[grep]: https://en.wikipedia.org/wiki/Grep
986984
[miniconda3]: https://docs.anaconda.com/free/miniconda/
985+
[miniforge3]: https://conda-forge.org/
986+
[miniforge3-install]: https://github.com/conda-forge/miniforge
987+
[numpydoc]: https://github.com/numpy/numpydoc
988+
[numpydocstyle]: https://numpydoc.readthedocs.io/en/latest/format.html
987989
[pc]: https://pre-commit.com
988990
[pc-ci]: https://pre-commit.ci
989991
[pc-hooks]: https://pre-commit.com/hooks
@@ -992,4 +994,5 @@ the Pre-commit hooks as part of the Continuous Integration on GitHub which is th
992994
[python]: https://python.org
993995
[pm]: https://github.com/ns-rse/python-maths
994996
[ruff]: https://astral.sh/ruff
997+
[virtualenvwrapper]: https://rse.shef.ac.uk/blog/2024-08-13-python-virtualenvwrapper/
995998
[yaml]: https://yaml.org

learners/setup.md

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Environment (IDE).
2727

2828
For consistency across operating systems this course uses the Command Line Interface (CLI) to Git and instructions below
2929
will guide you through installation on different Operating Systems. The principles can be applied to any Git Porcelain
30-
(client) that you choose, including IDEs, although not all will support all of the functions introduced here (e.g. the
30+
(client) that you choose (e.g. [GitKraken][gitkraken]), including IDEs such as [VSCode][vscode], PyCharm,
31+
[RStudio][rstudio] and [Emacs][emacs], although not all will support all of the functions introduced here (e.g. the
3132
RStudio Git interface is very basic).
3233

3334
:::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -124,7 +125,9 @@ account][github_ssh].
124125

125126
There is a detailed [article][ssh-keygen] on creating SSH keys under Linux and OSX that works with Git Bash too. It is
126127
recommended to use the newer [ed25519][ssh-ed25519] algorithm. In a terminal or Git Bash shell, you can do this using
127-
the following commands.
128+
the following commands. You will be prompted to enter your password twice, **make sure to enter a secure (i.e. long)
129+
password, password-less keys are insecure!**, make sure you remember what the password is (**Hint** use a password
130+
manager!).
128131

129132
```bash
130133
ssh-keygen -a 100 -t ed25519
@@ -174,72 +177,25 @@ Hi ns-rse! You've successfully authenticated, but GitHub does not provide shell
174177
If you do **not** see the above successful authentication message please get in touch **before** the course starts.
175178
:::::::::::::::::::::::::
176179
177-
## Conda Environments
180+
::::::::::::::::::::::::::::::::::::: keypoints
178181
179-
::::::::::::::::::::::::::::::::::::: callout
180-
181-
## Anaconda Licensing
182-
183-
It is important to fully understand and adhere to the [Anaconda Licensing][anacondalicense] which permits
184-
the use of their software (including Miniconda) in educational and research environments _only_ if there is no
185-
commercial benefit. If the work you undertake involves commercial collaboration you should seek alternative solutions
186-
for virtual environments (e.g. [miniforge3][miniforge3] or [virtualenvwrapper][virtualenvwrapper]).
182+
- You should have Git installed on your computer and opening a Terminal (or Git Bash Shell on Windows) you should be
183+
able to type `git` and receive a summary of available commands.
184+
- You should have setup a GitHub account.
185+
- You should have created an SSH key and uploaded the public component to your GitHub Account (_Settings > SSH and GPG
186+
Keys_).
187187
188188
::::::::::::::::::::::::::::::::::::::::::::::::
189189
190-
::::::::::::::::::::::::::::::::::::::: discussion
191-
192-
In order to teach this course we need some code that is version controlled and some tasks to complete. [Python][python]
193-
has been chosen as the language to fulfill that task. You do _not_ need to know Python in order to complete the course,
194-
the code you need to use is all provided and can be copy and pasted.
195-
196-
However, you _do_ need what is known as a "_Virtual Environment_" setup to be able to install various programmes and run
197-
the checks that are part of this course. To that end you should install
198-
[Miniconda3][miniconda3]/[miniforge3][miniforge3] or another tool for managing Virtual Environments
199-
(e.g. [virtualenvwrapper][virtualenvwrapper]) on your system prior to attending the course.
200-
201-
If you are already familiar with Python and Virtual Environments you can simply create a fresh virtual environment to
202-
use for the course.
203-
204-
:::::::::::::::::::::::::::::::::::::::::::::::::::
205-
206-
:::::::::::::::: solution
207-
208-
### Installing Miniconda/Miniforge3
209-
210-
Please follow the instructions at [Installing Miniconda](https://docs.anaconda.com/free/miniconda/miniconda-install/)
211-
for your Operating System.
212-
213-
Should you chose to use `miniforge3` the downloads and installation instructions for different operating systems can be
214-
found [here][miniforge3-install].
215-
216-
:::::::::::::::::::::::::
217-
218-
:::::::::::::::: solution
219-
220-
### Creating A Virtual Environment
221-
222-
You will have to create a virtual environment to undertake the course. If you have installed Miniconda as described
223-
above you open a terminal (Windows use the Git Bash Shell) and create a Virtual Environment called `git-collaboation`.
224-
225-
``` bash
226-
conda create --name git-collab python=3.11
227-
conda activate git-collab
228-
```
229-
230-
:::::::::::::::::::::::::
231-
232-
[anacondalicense]: https://www.anaconda.com/blog/update-on-anacondas-terms-of-service-for-academia-and-research
190+
[emacs]: https://www.gnu.org/software/emacs/
233191
[gh]: https://github.com
234192
[git]: https://git-scm.com/
235193
[github_ssh]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
194+
[gitkraken]: https://www.gitkraken.com/
236195
[gitMac]: https://git-scm.com/download/mac
237196
[gitWin]: https://git-scm.com/download/win
238197
[git4windows]: https://carpentries.github.io/workshop-template/install_instructions/#shell
239-
[miniconda3]: https://docs.anaconda.com/free/miniconda/
240-
[miniforge3]: https://conda-forge.org/
241-
[miniforge3-install]: https://github.com/conda-forge/miniforge
242-
[python]: https://python.org
198+
[rstudio]: https://posit.co/download/rstudio-desktop/
243199
[ssh-ed25519]: https://blog.g3rt.nl/upgrade-your-ssh-keys.html
244200
[ssh-keygen]: https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-openssh-on-macos-or-linux
245-
[virtualenvwrapper]: https://rse.shef.ac.uk/blog/2024-08-13-python-virtualenvwrapper/
201+
[vscode]: https://code.visualstudio.com/

0 commit comments

Comments
 (0)