You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-12Lines changed: 26 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
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.
4
4
5
+
If you just want to host some code but not publish it as a Python package, I have a [simpler template for that](https://github.com/mdtanker/research_repo_template).
6
+
5
7
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.
6
8
7
9
## Packages which have used this template
@@ -44,9 +46,21 @@ Steps:
44
46
git push -u origin new-branch
45
47
```
46
48
- in the GitHub repository, go to the `Pull request` tab and open a PR for your changes. Merge this into main.
47
-
3) Add your code
48
-
- pull in your above changes with `git checkout main` and `git merge upstream/main`
49
-
- if your working off a fork: push the above commit to sync your fork with upstream with `git push origin main`.
49
+
3) Pull in your merged changes
50
+
- how you do this depends if you pushed your changed directly to the repository, or through a fork of the repository:
51
+
1) PR submitted directly to repository:
52
+
- fetch your recent changes: `git fetch`
53
+
- checkout your main branch: `git checkout main`
54
+
- OPTIONAL: delete your feature branch: `git branch -d new-branch`
55
+
- pull in your changes: `git pull`
56
+
2) PR submitted through a fork:
57
+
- fetch your recent changes: `git fetch upstream`
58
+
- checkout your main branch: `git checkout main`
59
+
- OPTIONAL: delete your feature branch: `git branch -d new-branch`
60
+
- merge changes from upstream: `git merge upstream/main`
61
+
- this syncs your local repository to the upstream one
62
+
- push your changes to your upstream (forked) repository: `git push origin main`
63
+
4) Add your code
50
64
- decide on a module name(s)
51
65
- these need to be lowercase, should be short and while possible, shouldn't include underscores.
52
66
- if your package is going to be small, a single module with the same name as the package is fine. If it's going to be more than a few hundred lines of code, it's best to separate your code into distinct modules which perform similar tasks. - for each module you want do the following:
@@ -69,21 +83,21 @@ Steps:
69
83
```
70
84
- to allow `function1` to be imported as above, you need to manually add it to the list in`src/samplepackagename/_init_.py`. If you only have 1 module, this may be a better technique.
71
85
- add tests foryour modules' test filein`tests/`.
72
-
4) Specify your dependencies
86
+
5) Specify your dependencies
73
87
- dependencies foryour package should typically only be those that are directly used (imported)in your source code (or are explicitly needed but not import), but not the dependencies of your dependencies. If you use a package in your documentation, but not in the source code, include this as an _optional_ dependency. If you have a portion of your code that some users may not utilize, such as visualization functions, the dependencies you require for that, such as matplotlib, can also be include as _optional_ dependencies to reduces the constraints for users who don't require it.
74
88
- core dependencies are specified in `pyproject.toml` under the `[project]` section with the format `dependencies = ["pandas", "scipy>=1.0"]`.
75
89
- optional dependencies are specified in `pyproject.toml` under the `[dependency-groups]` section with the following format, for example for optional documentation dependencies: `docs = ["sphinx>=7.0",]`.
76
90
- 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 foranyone who wants to use your packagein their own environments.
77
91
- 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.
78
-
5) Create environment, style check, test, and commit your changes.
92
+
6) Create environment, style check, test, and commit your changes.
79
93
- follow the instructions in`CONTRIBUTING.md` starting at section `Setting up nox` and stopping before `Publish a new release`.
80
94
- these steps should result in a merged PR with your code.
81
-
6) Set up automated Zenodo releases (only for Public repositories)
95
+
7) Set up automated Zenodo releases (only for Public repositories)
82
96
- if you haven't already, link your organization (or personal) GitHub account to [Zenodo](https://zenodo.org/) using `Linked accounts` under your Zenodo profile.
83
97
- do to the `GitHub` menu on your Zenodo profile.
84
98
- click the Sync button and then turn on the switch for your repository.
85
99
- any future GitHub releases should now result in a new Zenodo release automatically.
86
-
7) Set up publishing on TestPyPI
100
+
8) Set up publishing on TestPyPI
87
101
- before publishing to the real PyPI, we will publish to Test-PyPI to ensure everything works .
88
102
- make an account on [TestPyPI](https://test.pypi.org/).
89
103
- under 'Your Projects', and 'Publishing', 'Add a new pending publisher', fill out your info.
@@ -92,7 +106,7 @@ Steps:
92
106
- Workflow name should be `cd.yml`
93
107
- Environment name should be `pypi`
94
108
- note that this doesn't reserve your package name until you make your first actual release!
95
-
8) Make a GitHub release
109
+
9) Make a GitHub release
96
110
- On the main GitHub page, on the right side click `Create a new release`.
- If the install and test above worked then we can change from TestPyPI to normal PyPI.
112
126
- 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.
113
127
- In this case, since the GitHub release has already been made, we need to manually trigger the `CD` workflow in GitHub.
114
128
- At [this link](https://github.com/organizationname/samplepackagename/actions/workflows/cd.yml), click the `Run workflow` button.
115
129
- This should build the package and release it to PyPI.
116
-
10) Set up publishing on Conda-Forge
130
+
11) Set up publishing on Conda-Forge
117
131
- create a [conda-forge recipe and feedstock](https://conda-forge.org/docs/maintainer/adding_pkgs/#creating-recipes) with the below instructions:
118
132
- Create a new environment using :`mamba create --name grayskull grayskull`
119
133
- Activate this new environment :`conda activate MY_ENV`
@@ -124,14 +138,14 @@ Steps:
124
138
- create a new folder :`staged-recipes/recipes/samplepackagename`
125
139
- copy your `meta.yaml` file into this folder, remove the `meta.yaml` from wherever it was generated.
126
140
- commit and push your changes to your fork, and in the main [repository](https://github.com/conda-forge/staged-recipes) open a PR.
127
-
11) Set up ReadTheDocs for the documentation website
141
+
13) Set up ReadTheDocs for the documentation website
128
142
- log into ReadTheDocs using your GitHub account.
129
143
- click `Add project` and ssearch for your repository.
130
144
- 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`
131
145
- Go to `settings` to update anything you'd like
132
146
- check `Build pull requests for this project`.
133
147
- 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.
134
-
12) Finalize
148
+
14) Finalize
135
149
- 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!
136
150
- 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!
0 commit comments