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: package-structure-code/intro.md
+32-11Lines changed: 32 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,41 +14,62 @@ best fitted for your workflow.
14
14
:gutter: 3
15
15
16
16
:::{grid-item-card}
17
-
:link: python-package-build-tools
17
+
:link: python-package-structure
18
18
:link-type: doc
19
19
20
-
✨ Finding the right packaging tool(s) ✨
20
+
✨ 1. Package file structure ✨
21
21
^^^
22
-
23
-
Learn more about the suite of packaging tools out there.
24
-
And learn which tool might be best for you.
22
+
src layout, flat layout and where should tests folders live? No matter what your level of packaging knowledge is, this page will help you decide upon a package structure that follows modern python best practices.
25
23
:::
26
24
27
25
:::{grid-item-card}
28
26
:link: python-package-structure
29
27
:link-type: doc
30
28
31
-
✨ Package file structure ✨
29
+
✨ 2. Learn about building your package ✨
32
30
^^^
33
-
src layout, flat layout and where should tests folders live? No matter what your level of packaging knowledge is, this page will help you decide upon a package structure that follows modern python best practices.
31
+
Building a Python package refers to the process of placing your package code
32
+
metadata (and tests) into a specific format that PyPI can read and that
33
+
your users can install. Learn more about building a Python package here.
34
34
:::
35
35
36
36
:::{grid-item-card}
37
37
:link: python-package-build-tools
38
38
:link-type: doc
39
39
40
-
✨ Publish to PyPI and Conda ✨
40
+
✨ 3. What Python package tool should you use? ✨
41
+
^^^
42
+
43
+
Learn more about the suite of packaging tools out there.
44
+
And learn which tool might be best for you.
45
+
:::
46
+
47
+
:::{grid-item-card}
48
+
:link: python-package-build-tools
49
+
:link-type: doc
50
+
51
+
✨ 4. Publish your package to PyPI and Conda ✨
41
52
^^^
42
53
If you have a pure python package, it's a straight forward
43
54
process to publish to both PyPI and then a Conda channel such as
44
55
conda-forge. Learn more here.
45
56
:::
46
57
58
+
:::{grid-item-card}
59
+
:link: python-package-versions
60
+
:link-type: doc
61
+
62
+
✨ 5. Setup package versioning ✨
63
+
^^^
64
+
Semver (numeric versioning) and Calver (versioning using the date) are 2
65
+
common ways to version a package. Which one should you pick? Learn more here.
66
+
:::
67
+
47
68
:::{grid-item-card}
48
69
:link: code-style-linting-format
49
70
:link-type: doc
50
71
51
-
✨ Code style & linters ✨
72
+
✨ 6. Code style & linters ✨
52
73
^^^
53
74
Black, blue, flake8, Ruff - which tools can help you ensure your
54
75
package follows best practices for code format? Learn more about the options and why this is important here.
@@ -134,8 +155,8 @@ if you are looking for pyOpenSci's Python package review requirements!
:alt: Image showing the left side bar of PiPy for the package xclim. The section at the top says Classifier. Below there is a list of items including Development status, intended audience, License, natural language, operating system, programming language and topic. Below each of those sections are various classifier options." width="300px">
3
+
:::{figure-md} build-workflow
4
+
<imgsrc="/images/python-package-development-process.png"alt="Alt tag to be added when image is final"width="700px">
6
5
7
-
Notice the metadata printed on the PyPI page for xclim. When you add the classifier section to your pyproject.toml
8
-
and your package is built, the build tool organizes the metadata into a format that PyPI can understand and
9
-
represent on your pypi landing page. These classifiers also allow users to sort through packages by version of python they support, categories and more.
10
-
```
6
+
You need to build your Python package in order to publish it to PyPI or Conda. For PyPI, the build process essentially organizes your code and metadata into a distribution format that PyPI can read and provide to potential users.
7
+
:::
11
8
12
9
## What is building a Python package?
13
10
14
-
In Python, if you want to publish your code in a way that can be
15
-
installed by both yourself and others, your code, tests and associated
16
-
metadata need to be organized in a specific way. This specific
17
-
organization and structure is important because it's the structure
18
-
that both `PyPI` and any installer that you use like `pip` can
19
-
understand and parse. This process of organizing and formatting your
11
+
To [publish your Python package](build-workflow) and make it easy for anyone to install, you first need to build it.
12
+
13
+
But, what does it mean to build a Python package?
14
+
15
+
[As shown in the figure above](build-workflow), when you build your Python package, you convert the source files into something called a distribution package. A distribution package contains your source code and metadata about the package, in the format required by the Python Package Index, so that it can be installed by tools like pip.
16
+
17
+
:::{note}
18
+
The term package used to mean many different things in Python and other languages. On this page, we adapt the convention of the [Python Packaging Authority](https://www.pypa.io/en/latest/) and refer to the product of the
19
+
build step as a **distribution package**.
20
+
:::
21
+
22
+
This process of organizing and formatting your
20
23
code, documentation, tests and metadata into a format that both pip
21
24
and PyPI can use, is called a build step.
22
25
26
+
### Project metadata and PyPI
27
+
23
28
For instance, when you publish to PyPI, you will notice that each package has metadata listed. Let’s have a look at [xclim](https://pypi.org/project/xclim/), one of our [pyOpenSci packages](https://www.pyopensci.org/python-packages.html). Notice that on the PyPI landing page you see some metadata about the package including python, maintainer information and more. PyPI is able to populate this metadata because it was defined using correct syntax and classifiers by Xclim's maintainers, [pyproject.toml file](https://github.com/Ouranosinc/xclim/blob/master/pyproject.toml). This metadata when the xclim package is built, is translated into a distribution file that allows PyPI to read the metadata and print it out on their website.
0 commit comments