|
1 | | -The file structure of the generated package looks like: |
| 1 | +# Developer documentation |
| 2 | + |
| 3 | +If you're looking for user documentation, go [here](README.md). |
| 4 | + |
| 5 | +## Development install |
| 6 | + |
| 7 | +### Install `cookiecutter` in user space |
| 8 | + |
| 9 | +We recommend installing `cookiecutter` in user space as per `cookiecutter`'s instructions. This way, you don't have to |
| 10 | +install `cookiecutter` for every new project. |
| 11 | + |
| 12 | +```shell |
| 13 | +python3 -m pip install --user --upgrade cookiecutter |
| 14 | +``` |
| 15 | + |
| 16 | +### Get your own copy of the repository |
| 17 | + |
| 18 | +Before you can do development work on the template, you'll need to check out a local copy of the repository: |
2 | 19 |
|
3 | 20 | ```shell |
4 | | -path/to/package/ |
5 | | -├── .editorconfig |
6 | | -└── .github/ |
7 | | - └── workflows |
8 | | - ├── build.yml |
9 | | - └── pypi_deploy.yml |
10 | | -├── .gitignore |
11 | | -├── pyproject.toml |
12 | | -├── .prospector.yml |
13 | | -├── CHANGELOG.md |
14 | | -├── CODE_OF_CONDUCT.md |
15 | | -├── CONTRIBUTING.md |
16 | | -├── docs |
17 | | -│ ├── conf.py |
18 | | -│ ├── index.rst |
19 | | -│ └── ... |
20 | | -├── LICENSE |
21 | | -├── MANIFEST.in |
22 | | -├── NOTICE |
23 | | -├── package |
24 | | -│ ├── __init__.py |
25 | | -│ ├── __version__.py |
26 | | -│ └── package.py |
27 | | -├── README.md |
28 | | -├── project_setup.md |
29 | | -├── requirements.txt |
30 | | -├── setup.cfg |
31 | | -├── setup.py |
32 | | -└── tests |
33 | | - ├── __init__.py |
34 | | - ├── test_lint.py |
35 | | - └── test_package.py |
| 21 | +cd <where you keep your GitHub repositories> |
| 22 | +git clone https://github.com/NLeSC/python-template.git |
| 23 | +cd python-template |
36 | 24 | ``` |
37 | 25 |
|
38 | | -* Code (existing or new) should be placed in `path/to/package/package/` (please choose a better name for your software!). |
39 | | -* Add documentation by editing `path/to/package/docs/index.rst` |
40 | | -* Tests go in the `path/to/package/tests/` directory |
41 | | -* The generated [project setup document]({{cookiecutter.project_name}}/project_setup.md) contains extensive documentation about the project setup and provides further instructions on what to do. |
| 26 | +### Create a virtual environment |
| 27 | + |
| 28 | +Next, make a virtual environment, activate it, and install the development dependencies in it. This will enable you to |
| 29 | +run the tests later. |
| 30 | + |
| 31 | +```shell |
| 32 | +# Create a virtual environment, e.g. with |
| 33 | +python3 -m venv env |
| 34 | + |
| 35 | +# activate virtual environment |
| 36 | +source env/bin/activate |
| 37 | + |
| 38 | +# make sure to have a recent version of pip and setuptools |
| 39 | +python3 -m pip install --upgrade pip setuptools |
| 40 | + |
| 41 | +# (from the project root directory) |
| 42 | +# install development dependencies |
| 43 | +python3 -m pip install --no-cache-dir .[dev] |
| 44 | +``` |
| 45 | + |
| 46 | +## Running the tests |
| 47 | + |
| 48 | +Running the tests requires an activated virtual environment with the development tools installed. |
| 49 | + |
| 50 | +```shell |
| 51 | +# unit tests |
| 52 | +pytest |
| 53 | +pytest tests/ |
| 54 | +``` |
| 55 | + |
| 56 | +## Using `cookiecutter` to generate a new package from the command line |
| 57 | + |
| 58 | +While making changes to the template, you'll regularly want to verify that the packages generated with the template |
| 59 | +still work. Any easy way to do this is to generate new packages in a temporary directory (which will get removed |
| 60 | +everytime you reboot), for example like so: |
| 61 | + |
| 62 | +```shell |
| 63 | +# change directory to a new temporary directory |
| 64 | +cd $(mktemp -d --tmpdir cookiecutter-generated.XXXXXX) |
| 65 | + |
| 66 | +# run cookiecutter with the template to generate a new package |
| 67 | +cookiecutter <path to where your template is> |
| 68 | + |
| 69 | +# when it asks you for the GitHub organization, put in your own name; |
| 70 | +# for the other questions, just accept the default |
| 71 | + |
| 72 | +# 'ls' should return just the one directory called 'my-python-project' |
| 73 | +ls |
| 74 | +``` |
| 75 | + |
| 76 | +If your Python package was created successfully, `cookiecutter` will point you to a file |
| 77 | +(`my-python-project/project_setup.md`) that contains information on next steps such as: |
| 78 | + |
| 79 | +1. making `my-python-project` a local git repository |
| 80 | +1. connecting the local repository to a new repository on GitHub |
| 81 | +1. pushing the freshly generated content to GitHub |
| 82 | +1. discovering what GitHub Actions there are, what they do, and how to inspect their results |
42 | 83 |
|
43 | | -### Step 3: Create and activate a Python environment |
| 84 | +Follow the instructions from `my-python-project/project_setup.md` and make sure that everything works. |
44 | 85 |
|
45 | | -* If you are using **virtualenv + pip3**, do: |
46 | | - ```bash |
47 | | - $ virtualenv -p python3 env |
48 | | - $ . env/bin/activate |
49 | | - ``` |
50 | | -* If you are using **conda**, type: |
51 | | - ```bash |
52 | | - $ conda create -n env python=3 |
53 | | - $ source activate env |
54 | | - ``` |
55 | | - (On windows use `activate env` to activate the conda environment.) |
| 86 | +In addition to the information in `my-python-project/project_setup.md`, the developer documentation |
| 87 | +`my-python-project/README.dev.md` contains information on a few more things to check, for example: |
56 | 88 |
|
57 | | -## Continuous integration with Github Actions |
| 89 | +1. generating `my-python-project`'s documentation locally |
| 90 | +1. running `my-python-project`'s tests locally |
| 91 | +1. running `my-python-project`'s linters locally |
| 92 | +1. verifying that the `my-python-project`'s version can be updated using `bumpversion` |
| 93 | +1. making a release of `my-python-project` on https://test.pypi.org/ |
58 | 94 |
|
59 | | -The template has two Ci workflows. They can be found in **.github/workflows** folder. |
| 95 | +Follow the instructions from `my-python-project/README.dev.md` and make sure that everything works. |
60 | 96 |
|
61 | | -1. **build.yml** |
| 97 | +## Making a release |
62 | 98 |
|
63 | | -This workflow install the dependencies, builds the package and runs tests. |
| 99 | +### Preparation |
64 | 100 |
|
65 | | -2. **pypi.yml** |
| 101 | +1. Make sure the `CHANGELOG.md` has been updated |
| 102 | +2. Verify that the information in `CITATION.cff` is correct, and that `.zenodo.json` contains equivalent data |
| 103 | +3. Make sure that `version` in [setup.cfg](setup.cfg) and `version` in [CITATION.cff](CITATION.cff) have been bumped to the to-be-released version of the template |
| 104 | +4. Run the unit tests with `pytest tests/` |
| 105 | +5. Go through the steps outlined above for [generating a new package from the command line](#using-cookiecutter-to-generate-a-new-package-from-the-command-line), and verify that the generated package works as it should. |
66 | 106 |
|
67 | | -This workflow pushes the package to [PYPI](https://pypi.org/). This action will require PYPI token to be stored as [Github secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). The workflow uses secret with a name of `PYPI_TOKEN`. |
| 107 | +### GitHub |
68 | 108 |
|
69 | | -You can learn more about Python packaging at [this link](https://packaging.python.org/tutorials/packaging-projects/). |
| 109 | +1. Make sure that the GitHub-Zenodo integration is enabled for https://github.com/NLeSC/python-template |
| 110 | +1. Go to https://github.com/NLeSC/python-template/releases and click `Draft a new release` |
0 commit comments