Skip to content

Commit 3bc7968

Browse files
authored
fix RTD build and update instructions (#3)
* fix RTD build and update instructions * fix pre-commit ignore files issue * use conda environment.yml for RTD build * add pip install to RTD config * fix RTD links * Add more template instructions * update readme
1 parent a5d09f7 commit 3bc7968

6 files changed

Lines changed: 92 additions & 116 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
exclude: |
66
(?x)(
7-
^\.github/config.yml$|
7+
^.github/config.yml
88
)
99
1010
repos:

.readthedocs.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
version: 2
55

66
build:
7-
os: ubuntu-24.04
7+
os: ubuntu-22.04
88
tools:
9-
python: "3.13"
9+
python: "mambaforge-22.9"
10+
jobs:
11+
install:
12+
- pip install --no-deps .
1013

1114
sphinx:
1215
configuration: docs/conf.py
1316

14-
python:
15-
install:
16-
- method: pip
17-
path: .
18-
extra_requirements:
19-
- docs
17+
conda:
18+
environment: environment.yml

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# How to contribute
22

33
## TLDR (Too long; didn't read)
4-
* open a [GitHub Issue](https://github.com/organizationname/samplepackagename/issues/new/choose) describing what you want to do
5-
* [fork](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project) the main branch and clone it locally
6-
* [create a branch](https://docs.github.com/en/get-started/using-github/github-flow#create-a-branch) for your edits
4+
* [fork](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project) the [repository](https://github.com/organizationname/samplepackagename) using the `Fork` button on GitHub.
5+
* clone your forked repository on your computer with `git clone https://github.com/organizationname/samplepackagename`.
6+
* [create a branch](https://docs.github.com/en/get-started/using-github/github-flow#create-a-branch) for your edits with `git branch new-branch`
77
* make your changes and run the style checkers with `nox -s style`
88
* once the style checks pass, commit your changes with `git commit -m "a short description of your changes"`
9-
* [make a Pull Request](http://makeapullrequest.com/) for your branch
9+
* push your changes with `git push -u origin new-branch`
10+
* [make a Pull Request](http://makeapullrequest.com/) for your branch from the main GitHub repository [PR page](https://github.com/organizationname/samplepackagename/pulls).
1011

1112
🎉 Thanks for considering contributing to this package! 🎉
1213

README.md

Lines changed: 76 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
# samplepackagename
2-
Short description of your package.
1+
# Python Package Template
32

4-
[![Actions Status][actions-badge]][actions-link]
5-
[![Documentation Status][rtd-badge]][rtd-link]
3+
This template is based on the [Scientific Python Development Guide](https://learn.scientific-python.org/development/). The main differences with the [template they provide](https://github.com/scientific-python/cookie) is that this is an _opinionated_ template, where I made certain decision I feel are optimal. Additional, this is setup for packages which have complex non-Python dependencies which can be installed with `pip`, but require `conda`. This is useful if your package will depends on packages such as `GeoPandas`, `PyGMT`, or `Cartopy`, as these all depend on code written in C or C+ which is easiest to install with conda.
64

7-
[![PyPI version][pypi-version]][pypi-link]
8-
[![Conda-Forge][conda-badge]][conda-link]
9-
[![PyPI platforms][pypi-platforms]][pypi-link]
5+
The below steps will create a complete Python package with testing, a documentation website, and builds uploaded to both PyPI (pip) and Conda-Forge (conda) for each new version release in GitHub. While it is quite tedious to initially setup, once you finished the below steps, almost everything is automated. The documentation website is automatically generated for each new PR, and new package versions are automatically released to PyPI and Conda-Forge each time you manually create a GitHub release.
106

11-
[![GitHub Discussion][github-discussions-badge]][github-discussions-link]
7+
## Packages which have used this template
128

13-
## Template Instructions
9+
* None yet 😔
1410

15-
The below steps will create a complete Python package with testing, a documentation website, and versions upload to both PyPI (pip) and Conda-Forge (conda) for each new version release in GitHub.
11+
## Template Instructions
1612

1713
Steps:
1814
1) Initiate your repository:
@@ -75,25 +71,76 @@ Steps:
7571
- Dependency version's should only be constrained to specific versions if you know there is an issue, and they should almost never be pinned to specific versions, as this will cause many issues for anyone who wants to use your package in their own environments.
7672
- this template also includes files and commands to create `conda` environments. These are used both in developing, and in GitHub automations. You need to manually ensure the dependencies listed in `environmental.yml` match those in `pyproject.toml`. Include all optional dependencies in the `environmental.yml`. If a dependency is only available via pip, and not conda, add it at the bottom to be installed via pip.
7773
5) Create environment, style check, test, and commit your changes.
78-
- follow the instructions in `CONTRIBUTING.md` from section `Setting up nox` to the bottom.
79-
6) Set up publishing on PyPI
80-
- First, we test the setup by publishing to Test-PyPI to ensure everything works before publishing to the real PyPI.
81-
- make an account on [TestPyPI](https://test.pypi.org/).
82-
- under 'Your Projects', and 'Publishing', 'Add a new pending publisher', fill out your info.
83-
- the project name and repository name should be what you chose for `samplepackagename`.
84-
- the owner should be what you used from `organizationname`.
85-
- Workflow name should be `cd.yml`
86-
- Environment name should be `pypi`
87-
- Note that this doesn't reserve your package name until you make your first actual release!
88-
- On GitHub, make a release.
89-
3) Set up publishing on Conda-Forge
90-
- create a conda-forge feedstock
91-
4) Set up ReadTheDocs for the documentation website
92-
-
93-
5) Zenodo release
94-
- add DOI to `docs/citing.md`
95-
6) Finalize
96-
- remove all the above instructions and
74+
- follow the instructions in `CONTRIBUTING.md` starting at section `Setting up nox` and stopping before `Publish a new release`.
75+
- these steps should result in a merged PR with your code.
76+
6) Set up automated Zenodo releases
77+
- if you haven't already, link your organization (or personal) GitHub account to [Zenodo](https://zenodo.org/) using `Linked accounts` under your Zenodo profile.
78+
- do to the `GitHub` menu on your Zenodo profile.
79+
- click the Sync button and then turn on the switch for your repository.
80+
- any future GitHub releases should now result in a new Zenodo release automatically.
81+
7) Set up publishing on TestPyPI
82+
- before publishing to the real PyPI, we will publish to Test-PyPI to ensure everything works .
83+
- make an account on [TestPyPI](https://test.pypi.org/).
84+
- under 'Your Projects', and 'Publishing', 'Add a new pending publisher', fill out your info.
85+
- the project name and repository name should be what you chose for `samplepackagename`.
86+
- the owner should be what you used from `organizationname`.
87+
- Workflow name should be `cd.yml`
88+
- Environment name should be `pypi`
89+
- note that this doesn't reserve your package name until you make your first actual release!
90+
8) Make a GitHub release
91+
- On the main GitHub page, on the right side click `Create a new release`.
92+
- click `Select tag` and type `v0.0.1`.
93+
- set a Release title: "Initial release"
94+
- click `Publish release`
95+
- this should automatically trigger a few things:
96+
1) a DOI will be added to your Zenodo, add this DOI to `docs/citing.md`.
97+
2) the GitHub action `CD` should be triggered, create a release of `v0.0.1` to TestPyPI.
98+
- to test this worked correctly, run the below commands to create a new conda environment using the TestPiPI release, and run your codes tests.
99+
```bash
100+
mamba create --name test_pypi python
101+
mamba activate test_pypi
102+
pip install -i https://test.pypi.org/simple/ samplepackagename
103+
nox -s test
104+
```
105+
9) Make a PyPI (pip) release
106+
- If the install and test above worked then we can change from TestPyPI to normal PyPI.
107+
- in `.github/workflows/cd.yml` comment out or delete the last line: `repository-url: https://test.pypi.org/legacy/`. Now any future reruns of this action will release to PyPI.
108+
- In this case, since the GitHub release has already been made, we need to manually trigger the `CD` workflow in GitHub.
109+
- At [this link](https://github.com/organizationname/samplepackagename/actions/workflows/cd.yml), click the `Run workflow` button.
110+
- This should build the package and release it to PyPI.
111+
10) Set up publishing on Conda-Forge
112+
- create a [conda-forge recipe and feedstock](https://conda-forge.org/docs/maintainer/adding_pkgs/#creating-recipes) with the below instructions:
113+
- Create a new environment using : `mamba create --name grayskull grayskull`
114+
- Activate this new environment : `conda activate MY_ENV`
115+
- Generate the recipe : `grayskull pypi --strict-conda-forge https://github.com/organizationname/samplepackagename`
116+
- this should create a `meta.yaml` file, which is the recipe.
117+
- fork and clone the [stage-recipes](https://github.com/conda-forge/staged-recipes) repository on conda-forge.
118+
- checkout a new branch : `git checkout -b samplepackagename`
119+
- create a new folder : `staged-recipes/recipes/samplepackagename`
120+
- copy your `meta.yaml` file into this folder, remove the `meta.yaml` from wherever it was generated.
121+
- commit and push your changes to your fork, and in the main [repository](https://github.com/conda-forge/staged-recipes) open a PR.
122+
11) Set up ReadTheDocs for the documentation website
123+
- log into ReadTheDocs using your GitHub account.
124+
- click `Add project` and ssearch for your repository.
125+
- Chose your project name, ideally its the same as your package name, but it doesn't have to be. If it's different, update the badge below: `[rtd-link]: https://samplepackagename.readthedocs.io/en/latest/?badge=latest`
126+
- Go to `settings` to update anything you'd like
127+
- check `Build pull requests for this project`.
128+
- for each commit to main, ReadTheDocs should automatically update the documentation website. Also, in PR's there should be a link to view the new docs to check them before merging the PR.
129+
12) Finalize
130+
- remove all the above instructions and raise any issues in this template's repository if you have any suggestion or found any errors in this template!
131+
- if you want, please submit a PR to this repository to add your package to this list at the top of this README to showcase it!
132+
133+
# samplepackagename
134+
Short description of your package.
135+
136+
[![Actions Status][actions-badge]][actions-link]
137+
[![Documentation Status][rtd-badge]][rtd-link]
138+
139+
[![PyPI version][pypi-version]][pypi-link]
140+
[![Conda-Forge][conda-badge]][conda-link]
141+
[![PyPI platforms][pypi-platforms]][pypi-link]
142+
143+
[![GitHub Discussion][github-discussions-badge]][github-discussions-link]
97144
98145
<!-- SPHINX-START-badges -->
99146
@@ -113,74 +160,3 @@ Steps:
113160
<!-- prettier-ignore-end -->
114161
115162
<!-- SPHINX-END-badges -->
116-
117-
118-
## Getting the code
119-
120-
You can download a copy of all the files for this project by cloning the GitHub repository:
121-
122-
git clone https://github.com/organizationname/samplepackagename
123-
124-
## Dependencies
125-
126-
These instructions assume you have `Make` installed. If you don't you can just open up the `Makefile` file and copy and paste the commands into your terminal. This also assumes you have Python installed.
127-
128-
Install the required dependencies with either `conda` or `mamba`:
129-
130-
cd samplepackagename
131-
132-
make create
133-
134-
Activate the newly created environment:
135-
136-
mamba activate samplepackagename
137-
138-
Install the local project
139-
140-
make install
141-
142-
143-
## How to use
144-
145-
To use this code, you need to first import the package. There are two options:
146-
147-
### 1: Import the main package
148-
149-
For example:
150-
```python
151-
import samplepackagename
152-
```
153-
154-
will allow you to access the function `example_function()` with either `samplepackagename.module1.example_function()` or just `samplepackagename.example_function()`.
155-
156-
Functions accessed in this way need to be explicitly added to the file `src/samplepackagename/__init__.py`
157-
158-
### 2: Import each module individually
159-
160-
For example:
161-
```python
162-
from samplepackagename import module1
163-
```
164-
Will allow you to access the function `example_function()` with `module1.example_function()`.
165-
166-
## Developer instructions
167-
168-
See the contributors guide for more details.
169-
170-
- Fork the [repository](https://github.com/organizationname/samplepackagename) using the `Fork` button on GitHub.
171-
- Clone your forked repository on your computer with `git clone https://github.com/organizationname/samplepackagename`.
172-
- Make a new branch with `git branch new-branch`
173-
- Make your changes
174-
- Add tests to make sure you changes are robust
175-
- Style-check your code:
176-
177-
nox -s style
178-
- Test your code
179-
180-
nox -s test
181-
- If necessary, update dependencies in both `environment.yml` and `pyproject.toml`. Then with your conda environment activated run:
182-
183-
make update
184-
- Build the documentation and check locally:
185-
186-
nox -s docs

docs/citing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This is research software made by scientists. Citations help us justify the effo
44

55
If you used `samplepackagename` in your research, please consider citing our software.
66

7-
If you would like to cite the specific version you used, which can improve reproducibility and let users know the state of the software at the time of your analysis, please use the version-specific citation and DOI (available from [Zenodo](https://zenodo.org/doi/)).
7+
If you would like to cite the specific version you used, which can improve reproducibility and let users know the state of the software at the time of your analysis, please use the version-specific citation and DOI (available from [Zenodo](https://doi.org/10.5281/zenodo.15863068)).

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"footer_icons": [
8787
{
8888
"name": "GitHub",
89-
"url": "https://github.com/asdf/asdfasdf",
89+
"url": "https://github.com/organizationname/samplepackagename",
9090
"html": """
9191
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
9292
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
@@ -95,7 +95,7 @@
9595
"class": "",
9696
},
9797
],
98-
"source_repository": "https://github.com/asdf/asdfasdf",
98+
"source_repository": "https://github.com/organizationname/samplepackagename",
9999
"source_branch": "main",
100100
"source_directory": "docs/",
101101
}

0 commit comments

Comments
 (0)