che[ck-e]xtra 🔎
When you're writing a python library, being able to define extras is sweet. People who are either new to programming in general or python's dynamic nature specifically might be caught off-guard by this feature though, so it might be nice to give them a little help when they run into
Traceback (most recent call last):
File "/home/me/code.py", line 1, in <module>
import foo
ModuleNotFoundError: No module named 'foo'
instead of letting them assume that you shipped them a broken distribution.
Usage
This package can be pip-installed
pip install chextra
If you decide that this is a feature that you want in your library, you
have to declare chextra as a project dependency as well.
Expected Project Layout
Code that relies on extras being installed will usually sit in a sub-package as a kind of barrier between it and the rest of the code.
It makes sense for the sub-package to have the same name as the extra, since extras are supposed to denote a functionality, which coincides with package naming conventions.
Given a distribution foo with an extra bar, this would be the expected
structure:
foo
├── __init__.py
└── bar
├── __init__.py
└── code.py
Triggering a Warning
You only need add the following code to the __init__.py of the sub-package:
import chextra
chextra.warn(pkg="foo", extras="bar")
And you're done. If someone tries to run import foo.bar or from foo.bar import code, they'll get the following message:
/home/me/my_project.py:3: UserWarning:
The feature you're trying to use requires the extra 'bar',
install it by running `pip install foo[bar]`.
chextra.warn(pkg="foo", extras="bar")
If the code is only executed within an attempted import and your extra has the same normalized name as the sub-package, you can also omit the arguments, since their values can be guessed from context.
import chextra
chextra.warn()
Focus
This package tries to be light-weight and not any fancier than it needs to. Installing dependencies automatically when they were found to be missing might sound great, but has been proven to be a bad idea.
Metadata
Release files for chextra 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chextra-0.1.1.tar.gz | 5.9 kB | Without provenance | Details for chextra-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chextra-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for chextra-0.1.1-py3-none-any.whl |
Total release size: 12.1 kB
Release files / chextra-0.1.1.tar.gz
| Download URL | chextra-0.1.1.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0cbf320f0b4ecb1d431fd55c7ad1b68df33967643a3a0d42ec252f779a3acf2a
|
|
BLAKE2b-256 checksum How to use checksums |
944e4d7f1db3523e6b9ed78ec48718c26f2708846f78a12d0e78687408f8f78d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.9 CPython/3.10.6
|
Release files / chextra-0.1.1-py3-none-any.whl
| Download URL | chextra-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52f69c038a068d19921f15054cf065a1ee686d69f1d5ee90c487380646d23d66
|
|
BLAKE2b-256 checksum How to use checksums |
51fa463cb40b31de28048374b8670112fcac31af206d99eec5e90664add6221c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.9 CPython/3.10.6
|
Security for chextra 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.