Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ A lesson on creating and publishing packages in Python, implemented using the

The website can be built locally using:

Install R deps:
```R
> install.packages(c("sandpaper", "varnish", "pegboard"),
repos = c("https://carpentries.r-universe.dev/", getOption("repos")))
```

Build and serve website:
```bash
$ Rscript build_script.R
```

Please consult the Carpentries Workbench docs for info on setting up your R environment.

For `vscode`, install the `R Extension for Visual Studio Code` plugin and install the `languageserver` to get syntax highlighting in R Markdown documents.
34 changes: 4 additions & 30 deletions episodes/01-scripts-and-modules.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ exercises: 2

## Python as a Scripting Language

TODO: Cull text

Python is frequently used as a _scripting language_ by scientists and engineers due to
its expressiveness, simplicity, and its rich ecosystem of third-party libraries. There
isn't a hard line between a scripting language and a non-scripting language, but some
Expand Down Expand Up @@ -648,37 +650,9 @@ if __name__ == "__main__":
```
An issue with our example is that it still requires the user to manually edit the file
if they wish to change the input or outputs. This problem can be solved by instead
taking arguments from the command line. A simple interface can be created using
`sys.argv`, which is a list of command line arguments in the form of strings:

```python
# file: SIR_model.py
import sys

def main():
# Note: sys.argv[0] is the name of our program!
pop_size = int(sys.argv[1])
beta = float(sys.argv[2])
gamma = float(sys.argv[3])
days = int(sys.argv[4])
I_0 = int(sys.argv[5])
output = sys.argv[6]

S, I, R = SIR_model(
pop_size=pop_size,
beta=beta,
gamma=gamma,
days=days,
I_0=I_0,
)
plot_SIR_model(S, I, R, save_to=output)

if __name__ == "__main__":
main()
```
taking arguments from the command line.

However, this requires the user to provide every argument in order, and doesn't allow
default arguments. We can achieve a better interface using the built-in `argparse`
We can achieve a better interface using the built-in `argparse`
library. The comments in the code below explain how this works:

```python
Expand Down
2 changes: 1 addition & 1 deletion episodes/03-building-and-installing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ This indicates that `pip` should install any version of `numpy` greater than 1.2
that any version of `pyyaml` will do. If our installed `numpy` version is less than
1.20, or if it isn't installed at all, `pip` will upgrade to the latest version that's
compatible with the rest of our installed packages and our Python version. We'll cover
software versioning in more detail in the [lesson on publishing](05-publishing.Rmd), but
software versioning in more detail in the [lesson on publishing](04-publishing.Rmd), but
now we'll simply cover some ways to specify which software versions we need:

```toml
Expand Down
2 changes: 1 addition & 1 deletion episodes/04-publishing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ We can test the distribution of our package by uploading to TestPyPI.
First we will need to create a "token" on test-pypi to use as a temporary password.

```bash
$ hatch publish --repo testpypi --user __token__ --auth <your_token_here>
$ hatch publish --repo https://test.pypi.org/legacy/ --user __token__ --auth pypi-token-here
```

To avoid entering you token on the cmd line you can provide details as env variables
Expand Down
11 changes: 10 additions & 1 deletion learners/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ Setup your test-pypi account:

## Create project repo

TODO: Create github template with init script + license + .gitignore

Create a new repo in your github account called `learn-hatch` and clone it to your local machine.

Tutor to discuss `.gitignore` and licences.
Tutor to discuss `.gitignore` and licences.


## Create Conda env

TODO: create new conda env.yml to include in template repo

- inc biopython, seaborn