|
| 1 | +``{{ cookiecutter.package_name }}`` developer documentation |
| 2 | +===================================== |
| 3 | + |
| 4 | +If you're looking for user documentation, go `here <README.md>`_. |
| 5 | + |
| 6 | +| |
| 7 | +| |
| 8 | +
|
| 9 | +Development install |
| 10 | +------------------- |
| 11 | + |
| 12 | +.. code:: shell |
| 13 | +
|
| 14 | + # Create a virtual environment, e.g. with |
| 15 | + python3 -m venv env |
| 16 | +
|
| 17 | + # activate virtual environment |
| 18 | + source env/bin/activate |
| 19 | + |
| 20 | + # make sure to have a recent version of pip and setuptools |
| 21 | + pip install --upgrade pip setuptools |
| 22 | +
|
| 23 | + # (from the project root directory) |
| 24 | + # install {{ cookiecutter.package_name }} as an editable package |
| 25 | + pip install --no-cache-dir --editable . |
| 26 | + # install development dependencies |
| 27 | + pip install --no-cache-dir --editable .[dev] |
| 28 | +
|
| 29 | +Afterwards check that the install directory is present in the ``PATH`` |
| 30 | +environment variable. |
| 31 | + |
| 32 | +Running the tests |
| 33 | +----------------- |
| 34 | + |
| 35 | +Running the tests requires an activated virtual environment with the development tools installed. |
| 36 | + |
| 37 | +.. code:: shell |
| 38 | +
|
| 39 | + # unit tests |
| 40 | + pytest |
| 41 | + pytest tests/ |
| 42 | + |
| 43 | +Running linters locally |
| 44 | +----------------------- |
| 45 | +For linting we will use [prospector](https://pypi.org/project/prospector/) and to sort imports we will use [isort](https://pycqa.github.io/isort/). |
| 46 | +Running the linters requires an activated virtual environment with the development tools installed. |
| 47 | + |
| 48 | +.. code:: shell |
| 49 | +
|
| 50 | + # linter |
| 51 | + prospector |
| 52 | +
|
| 53 | + # recursively check import style for the {{ cookiecutter.package_name }} module only |
| 54 | + isort --recursive --check-only {{ cookiecutter.package_name }} |
| 55 | +
|
| 56 | + # recursively check import style for the {{ cookiecutter.package_name }} module only and show |
| 57 | + # any proposed changes as a diff |
| 58 | + isort --recursive --check-only --diff {{ cookiecutter.package_name }} |
| 59 | +
|
| 60 | + # recursively fix import style for the {{ cookiecutter.package_name }} module only |
| 61 | + isort --recursive {{ cookiecutter.package_name }} |
| 62 | +
|
| 63 | +You can enable automatic linting with ``prospector`` and ``isort`` on commit by enabling the git hook from |
| 64 | +``.githooks/pre-commit``, like so: |
| 65 | + |
| 66 | +.. code:: shell |
| 67 | +
|
| 68 | + git config --local core.hooksPath .githooks |
| 69 | +
|
| 70 | +Versioning |
| 71 | +---------- |
| 72 | + |
| 73 | +Bumping the version across all files is done with bump2version, e.g. |
| 74 | + |
| 75 | +.. code:: shell |
| 76 | +
|
| 77 | + bump2version major |
| 78 | + bump2version minor |
| 79 | + bump2version patch |
| 80 | +
|
| 81 | +Making a release |
| 82 | +---------------- |
| 83 | + |
| 84 | +Preparation |
| 85 | +^^^^^^^^^^^ |
| 86 | + |
| 87 | +1. Update the ``CHANGELOG.md`` |
| 88 | +2. Verify that the information in ``CITATION.cff`` is correct, and that ``.zenodo.json`` contains equivalent data |
| 89 | +3. Make sure the version has been updated. |
| 90 | +4. Run the unit tests with ``pytest tests/`` |
| 91 | + |
| 92 | +PyPI |
| 93 | +^^^^ |
| 94 | + |
| 95 | +In a new terminal, without an activated virtual environment or an `env` directory: |
| 96 | + |
| 97 | +.. code:: shell |
| 98 | +
|
| 99 | + # prepare a new directory |
| 100 | + cd $(mktemp -d --tmpdir {{ cookiecutter.package_name }}.XXXXXX) |
| 101 | + |
| 102 | + # fresh git clone ensures the release has the state of origin/main branch |
| 103 | + git clone {{ cookiecutter.repository }} . |
| 104 | + |
| 105 | + # prepare a clean virtual environment and activate it |
| 106 | + python3 -m venv env |
| 107 | + source env/bin/activate |
| 108 | + |
| 109 | + # make sure to have a recent version of pip and setuptools |
| 110 | + pip install --upgrade pip setuptools |
| 111 | +
|
| 112 | + # install runtime dependencies and publishing dependencies |
| 113 | + pip install --no-cache-dir . |
| 114 | + pip install --no-cache-dir .[publishing] |
| 115 | + |
| 116 | + # clean up any previously generated artefacts |
| 117 | + rm -rf {{ cookiecutter.package_name }}.egg-info |
| 118 | + rm -rf dist |
| 119 | + |
| 120 | + # create the source distribution and the wheel |
| 121 | + python setup.py sdist bdist_wheel |
| 122 | +
|
| 123 | + # upload to test pypi instance (requires credentials) |
| 124 | + twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 125 | +Visit https://test.pypi.org/project/{{cookiecutter.package_name}} and verify that your package was uploaded successfully. |
| 126 | +Keep the terminal open, we'll need it later. |
| 127 | + |
| 128 | +In a new terminal, without an activated virtual environment or an `env` directory: |
| 129 | + |
| 130 | +.. code:: shell |
| 131 | + |
| 132 | + cd $(mktemp -d --tmpdir {{ cookiecutter.package_name }}-test.XXXXXX) |
| 133 | +
|
| 134 | + # prepare a clean virtual environment and activate it |
| 135 | + python3 -m venv env |
| 136 | + source env/bin/activate |
| 137 | + |
| 138 | + # make sure to have a recent version of pip and setuptools |
| 139 | + pip install --upgrade pip setuptools |
| 140 | +
|
| 141 | + # install from test pypi instance: |
| 142 | + python3 -m pip -v install --no-cache-dir \ |
| 143 | + --index-url https://test.pypi.org/simple/ \ |
| 144 | + --extra-index-url https://pypi.org/simple {{ cookiecutter.package_name }} |
| 145 | +
|
| 146 | +Check that the package works as it should when installed from pypitest. |
| 147 | + |
| 148 | +Then upload to pypi.org with: |
| 149 | + |
| 150 | +.. code:: shell |
| 151 | +
|
| 152 | + # Back to the first terminal, |
| 153 | + # FINAL STEP: upload to PyPI (requires credentials) |
| 154 | + twine upload dist/* |
| 155 | +
|
| 156 | +GitHub |
| 157 | +^^^^^^ |
| 158 | + |
| 159 | +Don't forget to also make a release on GitHub. If your repository uses the GitHub-Zenodo integration this will also |
| 160 | +trigger Zenodo into making a snapshot of your repository and sticking a DOI on it. |
0 commit comments