-
Notifications
You must be signed in to change notification settings - Fork 72
(Review 2 - complete) Packaging section - part 2 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
db390c8
47ca25a
e114a1b
4db3074
9cae7fa
3c6f7ff
9be2c29
f657772
cf36261
755cdd5
3e78288
0c4b77c
0a9cf7a
659ffeb
61b86eb
4b80f31
7ba8292
b64b59a
40eb8c6
1cbae63
fbf3ded
b082fb1
f2c1966
4a75fd9
e46dab2
68f5723
bef6801
a28b971
45b7ff8
d427e08
5c74e82
6d1cd13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ tmp/ | |
| .DS_Store | ||
| .nox | ||
| __pycache__ | ||
| *notes-from-review.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ We focus on pure-python packages in this guide. However, we also | |
| highlight tools that currently support packages with C/C++ and other language | ||
| extensions. | ||
|
|
||
| <!-- TODO: create build tool selection diagram - https://www.canva.com/design/DAFawXrierc/O7DTnqW5fmMEZ31ao-TK9w/edit --> | ||
|
|
||
| :::{figure-md} fig-target | ||
|
|
||
| <img src="../images/python-package-tools-decision-tree.png" alt="Figure showing... will finish this once we are all happy with the figure and it's not going to change more..." width="700px"> | ||
|
|
@@ -53,44 +51,6 @@ and **scikit-build** support complex builds with custom steps. If your | |
| build is particularly complex (i.e. you have more than a few `C`/`C++` | ||
| extensions), then we suggest you use **meson.build** or **scikit-build**. | ||
|
|
||
| <!-- | ||
| ### Build front-ends | ||
|
|
||
| Build front-ends have a user-friendly interface that allow you to perform | ||
| common Python packaging tasks such as building your package, creating an | ||
| environment to run package tests and build documentation, and pushing to PyPI. | ||
|
|
||
| For instance, you can use **Flit**, **Hatch**, **Poetry** and **PDM** to both build your | ||
| package and to publish your package to PyPI (or test PyPI). However, if you | ||
| want a tool that also support environment management and versioning your package, | ||
| then you might prefer to use **Hatch**, **Poetry** or **PDM**. | ||
|
|
||
| Using a tool like **Flit**, **Hatch**, **Poetry** or **PDM** will simplify your workflow. | ||
|
|
||
| Example to build your package with **Flit**: | ||
|
|
||
| `flit build` | ||
|
|
||
| Example to publish to PyPI: | ||
| `flit publish --repository testpypi` | ||
|
|
||
| In the Python package build space **setuptools** is | ||
| the "OG" -the original tool that everyone used to use. | ||
| With a tool like `setuptools` you have the flexibility | ||
| to publish python pure python packages and packages with custom build steps. However, you will also need to use other tools. For example, you will use `twine` to publish to PyPI. | ||
|
|
||
| ## An ecosystem of Python build tools | ||
|
|
||
| Below we introduce several of the most commonly used | ||
| Python packaging build tools. Each tool has various | ||
| features that might make you chose to use it | ||
| or not use it. There is no right or wrong tool to use | ||
| as far as pyOpenSci is concerned. We are just trying to | ||
| help you find the tool that works best for | ||
| your workflow. | ||
| Example build steps using setuptools: | ||
| ======= --> | ||
|
|
||
| ### Python package build front-ends | ||
|
|
||
| A packaging front-end tool refers to a tool that makes it easier for you to | ||
|
|
@@ -214,17 +174,6 @@ questions: | |
| NOTE: You can also use Hatch for non pure python builds but you will need to | ||
| write your own plugin for this support. | ||
|
|
||
| <!-- ### Build tools for Python packages with complex build steps | ||
| If your package is not pure Python, or it has complex build steps (or build | ||
| steps that you need to customize), then you should consider using: | ||
|
|
||
| * Setuptools | ||
| * Hatch | ||
| * PDM | ||
|
|
||
| These tools allow you to customize your workflow with build steps needed | ||
| to compile code. --> | ||
|
|
||
| ## Python packaging tools summary | ||
|
|
||
| <!-- NOTE - add language around the front end means that you have less individual tools in your build - such as nox / make with hatch --> | ||
lwasser marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
@@ -379,9 +328,6 @@ Build your sdist and wheel distributions|✅| Hatch will build the sdist and whe | |
|
|
||
| _\*\* There is some argument about this approach placing a burden on maintainers to create a custom build system. But others appreciate the flexibility_ | ||
|
|
||
| <!-- QUESTION: Does hatch allow you to use other envt managers like conda?? i don't see that it does | ||
| so it might be similar to Poetry in that regard --> | ||
|
|
||
| ### Why you might not want to use Hatch | ||
|
|
||
| There are a few features that hatch is missing that may be important for some. | ||
|
|
@@ -427,7 +373,7 @@ Install your package in editable mode|✅|Poetry supports installing your packag | |
| Build your sdist and wheel distributions|✅|Poetry will build your sdist and wheel distributions using `poetry build` | ||
| ``` | ||
|
|
||
| <!-- TODO: update this given responses here: https://github.com/python-poetry/poetry/discussions/7525 --> | ||
| <!-- TODO: responses here on poetry's future dev work: https://github.com/python-poetry/poetry/discussions/7525 --> | ||
|
|
||
| ### Challenges with Poetry | ||
|
|
||
|
|
@@ -516,79 +462,3 @@ when using setuptools. For instance: | |
| \*Setuptools also will include all of the files in your package | ||
| repository if you do not explicitly tell it to exclude files using a | ||
| **MANIFEST.in** file | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Speaking of this file, I think we should note how difficult it is to choose precisely what goes inside source distributions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. this was actually a pain point for me with our stravalib package. and it defaults to adding everything. do you have a suggestion for language to add here by chance? i'm not exactly sure what you mean by precisely as you can use that manifest file but i also haven't played with it extensively. i just saw what it did by default without a manifest file and was surprised
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean 2 things I suppose: one is that the pattern notation and directives are cumbersome to use in comparison to Git patterns and the other is that options in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok so i haven't actually worked on our manifest file yet.
are you saying that there is some sort of regex needed to specify patters in the. manifest.in file for setuptools that are cumbersome to use? vs what you'd use in a .gitignore file?
this i'm less familiar with. can you please clarify so i can add a bit of language?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| <!-- From stefan: build, run tests on built version, load the built version into | ||
| Python (?how is this different from install??), make editable install, build | ||
| wheel, build sdist --> | ||
|
|
||
| <!-- | ||
| The example below is taken from [this thread in GitHub](https://github.com/py-pkgs/py-pkgs/issues/95#issuecomment-1035584750). | ||
|
|
||
| ```toml | ||
| [tool.poetry.dependencies] | ||
| python = ">=3.6" # This is muddled in as a dependency, while it's not like the others | ||
| numpy = ">=1.13.3" | ||
| typing_extensions = { version = ">=3.7", python = "<3.8" } | ||
|
|
||
| sphinx = {version = "^4.0", optional = true} | ||
| sphinx_book_theme = { version = ">=0.0.40", optional = true } | ||
| sphinx_copybutton = { version = ">=0.3.1", optional = true } | ||
| pytest = { version = ">=6", optional = true } | ||
| importlib_metadata = { version = ">=1.0", optional = true, python = "<3.8" } # TOML error to add an ending comma or new line, even if this gets long | ||
| boost-histogram = { version = ">=1.0", optional = true } | ||
|
|
||
| [tool.poetry.dev-dependencies] | ||
| pytest = ">=5.2" # All the optional stuff above doesn't help here! | ||
| importlib_metadata = {version = ">=1.0", python = "<3.8" } | ||
| boost_histogram = ">=1.0" | ||
|
|
||
| [tool.poetry.extras] | ||
| docs = ["sphinx", "sphinx_book_theme", "sphinx_copybutton"] | ||
| test = ["pytest", "importlib_metadata", "boost_histogram" ] | ||
| ``` | ||
|
|
||
| vs PDM | ||
|
|
||
| ```toml | ||
| [project] | ||
| requires-python = ">=3.6" | ||
| dependencies = [ | ||
| "numpy>=1.13.3", | ||
| "typing-extensions>=3.7; python_version<'3.8'", | ||
| ] | ||
|
|
||
| # Only needed for extras | ||
| [project.optional-dependencies] | ||
| docs = [ | ||
| "sphinx>=4.0", | ||
| "sphinx-book-theme>=0.0.40", | ||
| "sphinx-copybutton>=0.3.1", | ||
| ] | ||
| test = [ | ||
| "pytest>=6", | ||
| "importlib-metadata>=1.0; python_version<'3.8'", | ||
| "boost-histogram>=1.0", | ||
| ] | ||
|
|
||
| # Only needed for "dev" installs | ||
| [tool.pdm.dev-dependencies] | ||
| dev = [ | ||
| "pytest>=6", | ||
| "importlib-metadata>=1.0; python_version<'3.8'", | ||
| "boost-histogram>=1.0", | ||
| ] | ||
| ``` | ||
|
|
||
| From Eli: | ||
|
|
||
| poetry: supports it (c extensions), but is undocumented and uses setuptools under the hood, they plan to change how this works and then document it | ||
| pdm-back-end: supports it, and documents it -- and also uses setuptools under the hood | ||
| hatchling: permits you to define hooks for you to write your own custom build steps, including to build C++ extensions | ||
|
|
||
|
|
||
| **PDM** does have some support for `C`/[`Cython`](https://cython.org/) extensions. [Click here to | ||
| learn more.](https://pdm.fming.dev/latest/pyproject/build/#build-platform-specific-wheels). This functionality uses setuptools "under the | ||
| hood". | ||
|
|
||
|
|
||
| --> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: i just realized there is another big difference between flit, setuptools and the other three - some have an init workflow that creates your package structure for you. Whereas flit init for instance only creates the .toml file and adds a license. it relies on the user to create the structure.
also the way it creates the toml needs to be. noted as by default it assumes dynamic version and description. so if you try to do flit init and then build it will fail by default unless you already have everything setup.
i'm not sure if the readme needs to be added as
file =somewhere or what dynamic description means so need to look into this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is particularly important for a new user. it would be nice to be able to create a structure, add code and install without running into errors that you don't understand initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PDM does the same but it includes a READMe.MD and a pyproject.toml only - no license file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hatch should automatically create and include the license for generated projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok many thanks. i need to test hatch next. maybe that is what i'll do today!!
i'm working on examples of each tool here, @ofek https://github.com/pyOpenSci/examplePy hatch isn't there yet but it will be it's just taking me time . each readme in that repo will then link to a online blog post about the tool.