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: tutorials/intro.md
+29-28Lines changed: 29 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ create a Python package.
7
7
8
8
:::{figure-md} packaging-outline
9
9
10
-
<imgsrc="../images/tutorials/packaging-101-outline.png"alt="Diagram showing the lessons in our packaging tutorial."width="800px">
10
+
<imgsrc="../images/tutorials/packaging-101-outline.png"alt="Diagram showing the lessons in our packaging tutorial. There are 6 total - what is a python package, make code pip installable, publish your package to PyPI, add a readme and license file, add metadata for pypi and finally publish to conda forge."width="800px">
11
11
12
-
Packaging tutorial overview graphic
12
+
This lesson is the first in a series of lessons to help you get started with Python packaging.
13
13
:::
14
14
15
15
## Who are these tutorials for?
@@ -43,7 +43,7 @@ After reading this lesson you will:
43
43
44
44
- Understand what a Python package is
45
45
- Be able to list the 5 core components of a Python package
46
-
-You will be able to explain the difference between generalizable code and code that supports a specific scientific application
46
+
-Be able to explain the difference between generalizable code and code that supports a specific scientific application
47
47
48
48
:::
49
49
@@ -60,7 +60,7 @@ Structurally, in Python, a package is a directory with a specific
60
60
file structure. Within the package directory structure, there are
61
61
modules which are files that end in `.py` (the same extension you'd
62
62
see in a Python script). These modules allow you to group and
63
-
structure yourPython code. Each module contains functions and classes,
63
+
structure your Python code. Each module contains functions and classes,
64
64
that you can think about as the tools in your toolbox.
65
65
66
66
:::{figure-md} python-toolbox
@@ -73,10 +73,11 @@ well.
73
73
:::
74
74
75
75
### Python packages are installable
76
+
76
77
A package is installable, which means that you can add the
77
78
functionality within the package's code to any Python environment and
78
79
import that functionality like you would import core Python packages such
79
-
as NumPy or matplotlib.
80
+
as NumPy or Matplotlib.
80
81
81
82
```python
82
83
import numpy
@@ -88,11 +89,11 @@ Structuring your code as a package is the first step you need to take so you can
88
89
89
90
## Why create a Python package?
90
91
91
-
There are numerous reasons why you might create a Python package:
92
+
You might create a Python package because you want to:
92
93
93
-
-**Use your code across multiple projects:** At its most basic level, creating a package allows you to install your code into a Python environment. This allows you to then import functions and classes into any workflows both locally and in the cloud..
94
-
-**Share your code:**Sharing your code with others is often a common reason to create a package. If you publish a package on a public repository such as PyPI or conda, immediately your package can be installed on any machine using pip or conda with a single command.
95
-
-**Build community around your code:** Packages make it easier for multiple people to work on the same project (particularly when published on Github). A version platform such as git (the version control system used by GitHub), further makes it easier to track changes to the codebase over time. Tools such as issues and pull requests make it easier for outside users to contribute bug fixes and to establish review processes for accepting changes to the code base..
94
+
-**Use your code across different projects:** At its most basic level, creating a package allows you to install your code into a Python environment. This allows you to then import functions and classes into any workflows both locally and in the cloud..
95
+
-**Share your code:** If you publish a package on a public repository such as PyPI or conda, your package can be installed on any machine using pip or conda with a single command.
96
+
-**Build community around your code:** Packages make it easier for multiple people to work on the same project (particularly when published on GitHub). A version platform such as git (the version control system used by GitHub), further makes it easier to track changes to the codebase over time. Tools such as issues and pull requests make it easier for outside users to contribute bug fixes and to establish review processes for accepting changes to the code base..
96
97
-**Organize your code:** Packages can be used to organize large code projects, dividing them into smaller, more manageable components. This structure can help with both maintaining the codebase and with making it easier to understand.
97
98
98
99
### What to consider before you create a package
@@ -105,7 +106,7 @@ time and effort. Before you begin, think about your goals including:
105
106
- Whether you have time to add things such as documentation and tests
106
107
- How long you might be able to maintain it: remember that once people begin using your package they will depend on your maintainer team to update it, fix bugs and answer questions.
107
108
108
-
Before creating a package that is user-facing, it's important to consider all of the above!
109
+
Before creating a user-facing package, it's important to consider all of the above.
109
110
110
111
## The elements of a Python package
111
112
@@ -227,8 +228,8 @@ supports a specific research project. It aims to enhance the reproducibility and
227
228
transparency of research by providing a comprehensive record of the methods,
228
229
data, and analyses used in a study.
229
230
230
-
A Python package however is a collection of modules that are focused on a
231
-
specific set of tasks that can be applied across numerous research projects.
231
+
A Python package is a collection of modules that can be used to perform a
232
+
specific set of tasks. These tasks should be applicable to numerous workflows.
232
233
As such a Python package is more generalizable than a Research Compendium
233
234
which supports a specific project.
234
235
@@ -240,30 +241,30 @@ which supports a specific project.
240
241
Below are a few examples well scoped pyOpenSci packages:
241
242
242
243
*[Crowsetta](https://crowsetta.readthedocs.io/en/latest/): is a package designed to work with annotating animal vocalizations and bioacoustics data. This package helps scientists process different types of bioacoustic data rather than focusing on a specific individual research application associated with a user-specific research workflow.
243
-
*[pandera](https://www.union.ai/pandera) is another more broadly used Python package. Pandera supports data testing and thus also has a broader research application.
244
+
*[Pandera](https://www.union.ai/pandera) is another more broadly used Python package. Pandera supports data testing and thus also has a broader research application.
244
245
245
246
:::{admonition} Matplotlib as an example
246
247
247
248
At the larger end of the user spectrum, Matplotlib is a great example.
248
-
Matplotlib does one (big important) thing really well:
249
+
Matplotlib does one thing really well:
249
250
250
251
*It creates visual plots of data.*
251
252
252
-
Matplotlib is used by thousands of users for different plotting applications
253
+
Thousands of people use Matplotlib for different plotting applications
253
254
using different types of data. While few scientific packages will have the same
254
-
broad application and large user base as tools like Matplotlib, the
255
+
broad application and large user base that Matplotlib has, the
255
256
idea of scoping out what your package does is still important.
256
257
:::
257
258
258
259
### Code should also be clean & readable & documented
259
260
260
-
The code in your package should also be clean, readable and well documented.
261
+
The code in your package should also be clean, readable, and well documented.
261
262
262
263
**Clean code:** Clean code refers to code that uses expressive variable names,
263
-
is concise and does not repeat itself. We will dive deeper into best practices
264
+
is concise and doesn't repeat itself. You can learn about best practices
264
265
for clean code in future pyOpenSci tutorials.
265
266
266
-
**Readable code:**Readable code is code written with a consistent style.
267
+
**Readable code:**readable code is code written with a consistent style.
267
268
You can use linters and code formatters such as black and flake8 to ensure
268
269
this consistency throughout your entire package. [Learn more about code formatters here.](../package-structure-code/code-style-linting-format.html)
269
270
@@ -275,15 +276,15 @@ what the input and output elements of each function is. [You can learn more abou
275
276
276
277
### Python packages and environments
277
278
278
-
A Python package can be installed into a Python environment in the same way
279
+
You can install a Python package into a Python environment in the same way
279
280
you might install NumPy or pandas. Installing your package into an environment
280
281
allows you to access it from any code run with that specific Python environment activated.
281
282
282
283
:::{figure-md} packages-environment
283
284
284
285
<imgsrc="../images/tutorials/environment-package-install.png"alt="Diagram showing the steps associated with creating a package and then installing it. The first arrow says your package and the second says pip install package. The second arrow leads to a box that represents a python environment that already has some packages installed such as pandas and NumPy. Your package will also get installed into that same environment when you pip install it."width="700px">
285
286
286
-
You don't have to publish to PyPI in order to make your code installable.
287
+
You don't have to publish to PyPI to make your code installable.
287
288
With the correct file structure and project metadata you can make your code
288
289
installable locally on your computer and use it for projects that you are working
289
290
on without having to ever publish to PyPI. Publishing to PyPI is useful when you
@@ -300,25 +301,25 @@ publish it in a repository such as **PyPI** or **conda-forge**.
300
301
The links below won't work until those lessons (which are written) are published.
301
302
:::
302
303
303
-
In this tutorial, you will learn [how to publish to PyPI.](6-publish-pypi.md)
304
+
Learn [how to publish your package to PyPI in this tutorial.](6-publish-pypi.md)
304
305
305
306
:::{todo}
306
307
This lesson is also not published - yet but will be reviewed soon.
307
308
:::
308
309
309
-
Then you can create a conda-forge recipe using the [grayskull](https://github.com/conda/grayskull) tool. This recipe can then be submitted to conda-forge. [You will learn more about the conda-forge publication process here.](7-publish-conda-forge.md)
310
+
Then you can create a conda-forge recipe using the [Grayskull](https://github.com/conda/grayskull) tool. You can then submit this recipe to conda-forge. [You will learn more about the conda-forge publication process here.](7-publish-conda-forge.md)
310
311
311
312
312
313
:::{figure-md} build-workflow-tutorial
313
314
<imgsrc="../images/tutorials/publish-package-pypi-conda.png"alt="Graphic showing the high level packaging workflow. On the left you see a graphic with code, metadata and tests in it. Those items all go into your package. Documentation and data are below that box because they aren't normally published in your packaging wheel distribution. an arrow to the right takes you to a build distribution files box. that box leads you to either publishing to testPyPI or the real PyPI. From PyPI you can then connect to conda forge for an automated build that sends distributions from PyPI to conda-forge."width="700px">
314
315
315
-
In the above image you can see the steps associated with publishing
316
-
your package on PyPI and conda forge. Note that the distribution files that PyPI requires are the [sdist](#sdist) and [wheel](#wheel) files. Once you are ready to make your code publicly installable, you can publish it on PyPI. Once your code is on PyPI it is straight forward to then publish to conda forge. You create a recipe using the grayskull package and then you open a pr in the conda-forge recipe repo. You will learn more about this process in the [conda-forge lesson](#).
316
+
In the image above, you can see the steps associated with publishing
317
+
your package on PyPI and conda forge. Note that the distribution files that PyPI requires are the [sdist](#sdist) and [wheel](#wheel) files. Once you are ready to make your code publicly installable, you can publish it on PyPI. Once your code is on PyPI it is straight forward to then publish to conda forge. You create a recipe using the Grayskull package and then you open a pr in the conda-forge recipe repo. You will learn more about this process in the [conda-forge lesson](#).
317
318
:::
318
319
319
320
## Yay, your package has users! Now what?
320
321
321
-
As the community using your package grows, you may also find yourself managing users, contributors and others who want to interact with your package. It’s important to consider all this before you dive into development. Once you have a user base in the community, people will depend upon your code to work and will need direction regarding how to use it.
322
+
As the community using your package grows, you may also find yourself managing users, contributors, and others who want to interact with your package. It’s important to consider all this before you dive into development. Once you have a user base in the community, people will depend upon your code to work and will need direction regarding how to use it.
322
323
323
324
To support your community, you'll want to add things like:
324
325
@@ -330,13 +331,13 @@ To support your community, you'll want to add things like:
330
331
331
332
If you intend for others to use and contribute to your code, consider who will maintain it over time. You will want a **contributing and development** guide to help new potential contributors get started with contributing to your package, as well as a **code of conduct** to ensure community interactions remain healthy both for you and your contributors and maintainer team.
332
333
333
-
The elements above are also important for future maintenance of your package. In the case that you are no long able to maintain it or simply want extra help, development and contributing documentation will help you onboard new maintainers.
334
+
The elements above are also important for future maintenance of your package. In the case that you are no long able to maintain it or simply want extra help, development, and contributing documentation will help you onboard new maintainers.
334
335
:::
335
336
336
337
*****
337
338
338
339
## What's next?
339
340
340
-
In future lessons we will talk more about the infrastructure around a published Python package that makes it both easier to maintain, easier for others to contribute to and easier for other scientists to use. However, first we want to get you to your initial goal of publishing a Python package.
341
+
In future lessons you will learn talk more about the infrastructure around a published Python package that makes it both easier to maintain, easier for others to contribute to and easier for other scientists to use. However, first we want to get you to your initial goal of publishing a Python package.
341
342
342
343
In this next lesson you will learn how to create a basic installable Python package.
0 commit comments