|
| 1 | +# Add a README file to your Python package |
| 2 | + |
| 3 | +In the previous lessons you learned: |
| 4 | + |
| 5 | +1. What a Python package is |
| 6 | +2. How to make your code installable and |
| 7 | +3. How to publish your package to (test) PyPI |
| 8 | + |
| 9 | +:::{admonition} Learning objectives |
| 10 | + |
| 11 | +In this lesson you will learn: |
| 12 | + |
| 13 | +1. How to add a **README.md** file to your package. |
| 14 | +2. What the core elements of a **README.md** file are. |
| 15 | +::: |
| 16 | + |
| 17 | +## What is a README file? |
| 18 | + |
| 19 | +The `README.md` file is a markdown file located at the root of your project directory that helps |
| 20 | +a user understand: |
| 21 | + |
| 22 | +- You package's name and what it does |
| 23 | +- The current development "state" of the package (through badges) |
| 24 | +- How to get started with using your package. |
| 25 | +- How to contribute to your package |
| 26 | +- How to cite your package |
| 27 | + |
| 28 | +Your **README.md** file is important as it is often the first thing that someone sees before they install your package. The README file also will be used to populate your PyPI landing page. |
| 29 | + |
| 30 | +Note that there is no required format for README files. This page simply outlines sections that we suggest you have in your README file. |
| 31 | + |
| 32 | +## Create a README.md file for your package |
| 33 | + |
| 34 | +It's time to add a `README.md` file to your project directory. |
| 35 | + |
| 36 | +### Step 0. Create a README file |
| 37 | +To get started, if you don't already have a README.md file in your project directory, create one. |
| 38 | + |
| 39 | +:::{tip} |
| 40 | +If you created your project directory from |
| 41 | + |
| 42 | +* a GitHub repository online |
| 43 | +* using `hatch init` |
| 44 | + |
| 45 | +Then you may already have a README.MD file in your project directory. |
| 46 | +::: |
| 47 | + |
| 48 | +<!-- If they use hatch init in the very first lesson - |
| 49 | +the readme will already be there--> |
| 50 | + |
| 51 | +### Step 1. Add package badges |
| 52 | + |
| 53 | +At the top of the `README.md` file, add the name of your package. |
| 54 | + |
| 55 | +### Step 2 - add badges to the top of your README file |
| 56 | + |
| 57 | +It's common for maintainers to add badges to the top of their README files. Badges allow you and your package users to track things like |
| 58 | + |
| 59 | +* Broken documentation and test builds |
| 60 | +* Versions of your package that are on PyPI and Conda. |
| 61 | +* Whether your package has been reviewed and vetted by an organization such as pyOpenSci and/or JOSS. |
| 62 | + |
| 63 | +If you have already published your package to pypi.org you can use [shields.io to create a package version badge](https://shields.io/badges/py-pi-version). This badge will dynamically update as you release new versions of your package to PyPI. |
| 64 | + |
| 65 | +If not you can leave the top empty for now and add badges to your README at a later point as they make sense for your package. |
| 66 | + |
| 67 | +### Step 3 - Add a description of what your package does |
| 68 | + |
| 69 | +Below the badges (if you have them), add a section of text |
| 70 | +that provides an easy-to-understand overview of what your |
| 71 | +package does. |
| 72 | + |
| 73 | +* Keep this section short. |
| 74 | +* Try to avoid jargon. |
| 75 | +* Define technical terms that you use to make the description accessible to more people. |
| 76 | + |
| 77 | +Remember that the more people understand what your package does, the more people will use it. |
| 78 | + |
| 79 | +### Step 4 - Add package installation instructions |
| 80 | + |
| 81 | +Next, add instructions that tell users how to install your package. |
| 82 | + |
| 83 | +For example, can they use pip to install your package? |
| 84 | +`pip install packagename` |
| 85 | + |
| 86 | +or conda? |
| 87 | + |
| 88 | +`conda install -c conda-forge packagename`. |
| 89 | + |
| 90 | +If you haven't yet published your package to pypi.org then |
| 91 | +you can skip this section and come back and add these |
| 92 | +instructions later. |
| 93 | + |
| 94 | +### Step 5 - Any additional setup |
| 95 | + |
| 96 | +In some cases, your package users may need to manually |
| 97 | +install other tools in order to use your package. If that |
| 98 | +is the case, be sure to add a section on additional setup |
| 99 | +to your README file. |
| 100 | + |
| 101 | +Here, briefly document (or link to documentation for) any |
| 102 | +additional setup that is required to use your package. |
| 103 | +This might include: |
| 104 | + |
| 105 | +* authentication information if it is applicable to your package. |
| 106 | +* additional tool installations such as GDAL. |
| 107 | + |
| 108 | +:::{note} |
| 109 | +Many packages won't need this section in their README. In that case you can always skip this section! |
| 110 | +::: |
| 111 | + |
| 112 | + |
| 113 | +### Step 6 - Add a get started section |
| 114 | + |
| 115 | +Next add a getting started section that shows how to use your package. This |
| 116 | +section should include a small code chunk that demonstrates importing and using |
| 117 | +some of the functionality in your package. |
| 118 | + |
| 119 | +For the pyosPackage, a short get started demo might look like this: |
| 120 | + |
| 121 | +```python |
| 122 | +>>> from pyospackage.add_numbers import add_num |
| 123 | +>>> add_num(1, 2) |
| 124 | +3 |
| 125 | +`````` |
| 126 | + |
| 127 | +Or it could simply be a link to a get started tutorial that you have created. If |
| 128 | +you don't have this yet, you can leave it empty for the time being. |
| 129 | + |
| 130 | +This would |
| 131 | +also be a great place to add links to any tutorials that you have created that |
| 132 | +help users understand how to use your package for common workflows. |
| 133 | + |
| 134 | + |
| 135 | +### Step 7 - Community section |
| 136 | + |
| 137 | +The community section of your README file is a place to include information for users who may want to engage with your project. This engagement will likely happen either on a platform like GitHub or GitLab. |
| 138 | + |
| 139 | +In the community section, you will add links to your contributing guide |
| 140 | +and `CODE_OF_CONDUCT.md`. You will add a [`CODE_OF_CONDUCT.md` file in the next lesson](add-license-coc). |
| 141 | + |
| 142 | +As your package grows you may also have a link to a development guide that contributors and your maintainer team will follow. |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +### Step 8 - Citation & License information |
| 147 | + |
| 148 | +Finally it is important to let users know |
| 149 | + |
| 150 | +1. how to cite your package and |
| 151 | +2. what the license is. |
| 152 | + |
| 153 | +You will create a license file for your package in this lesson. |
| 154 | + |
| 155 | +Your finished `README.md` file should look something like this: |
| 156 | + |
| 157 | +````markdown |
| 158 | +# pyOpenSci-package |
| 159 | + |
| 160 | +[](https://doi.org/10.5281/zenodo.8365068) |
| 161 | +[](https://github.com/pyOpenSci/software-review/issues/115) |
| 162 | + |
| 163 | +## What packagename does |
| 164 | + |
| 165 | +Short description here using non technical language that describes what your package does. |
| 166 | + |
| 167 | +## How to install |
| 168 | + |
| 169 | +<todo - when i add more to the pyos package this can use that readme> |
| 170 | +To install this package... use: |
| 171 | + |
| 172 | +`pip install packagename` |
| 173 | + |
| 174 | +## OPTIONAL - if you have additional setup instructions add them here. if not, skip this section. |
| 175 | + |
| 176 | +## Get started using packagename |
| 177 | + |
| 178 | +Here add a quick code demo showing a user how to use the package after it is installed. |
| 179 | + |
| 180 | +``` |
| 181 | +from packagename.module import xmethod |
| 182 | + |
| 183 | +a = xmethod.dosomething(var1, var2) |
| 184 | + |
| 185 | +``` |
| 186 | + |
| 187 | +You can also add any links to this section to tutorials in your documentation. |
| 188 | + |
| 189 | +## Community |
| 190 | + |
| 191 | +Add information here about contributing to your package. Be sure to add links to your `CODE_OF_CONDUCT` file and your development guide. For now this section might be empty. You can go back and fill it in later. |
| 192 | + |
| 193 | +## How to cite packagename |
| 194 | + |
| 195 | +citation information here |
| 196 | +```` |
| 197 | + |
| 198 | +## <i class="fa-solid fa-hands-bubbles"></i> Wrap up |
| 199 | + |
| 200 | +It's important to consider the information that a new user or contributor might |
| 201 | +need when creating your `README.md` file. While there is no perfect template, |
| 202 | +above is a set of recommendations as you are just getting started. You may find |
| 203 | +the need for other elements to be added to this file as you further develop your |
| 204 | +package and as a community begins to use your package. |
| 205 | + |
| 206 | +In the [next lesson](add-license-coc), you will add a LICENSE file to |
| 207 | +your Python package. A license file is critical as it tells users |
| 208 | +how they legally can (and can't use your package). It also: |
| 209 | + |
| 210 | +* Builds trust with your users |
| 211 | +* Discourages misuse of your package and associated code |
0 commit comments