Concept
Functions in a module should be laid out like a newspaper
Most important (the headline) at the top, then subsequent lower layers each with finer detail as we go down.
Functions with no level of indentation should be considered top level
Functions that are not called within the module can be considered the user end points for the module because if they are not called within the module then the intention is to call them from elsewhere.
So we order top level functions by the number of times they are called from lowest to highest count.
Of those, functions that call the most number of other functions in the same module should be near the top as they are pulling together the most amount of module specific processing.
lastly if the function is called the same as another and calls the same number of other functions then we order by name alphabetically.
Sort methods
newspaper
newspaper: functions that have the least calls themselves and call the most functions, if functions equally ranked with these metrics they are sorted alphabetically.
The idea is to read functions that are both not called within the module (thus are expected to be called elsewhere) and call the most functions from within the module, giving you the "headline" of the modules functionality while having to read the least but allow you to read internal functions with more detail if necessary in order of importance for the module.
called
called: functions that are called the most are at the top moving to those that are called the least. The idea is to get an idea of the core functionality of a module before reading the code where they are used.
calls
calls: functions that call the most other functions are at the top allowing for efficient reading of the code that "do" the most first.
alphabetical
alphabetical: self-explanatory, excludes leading underscores
example: ["a", "_b", "c"]
alphabetical_include_leading_underscores
alphabetical_include_leading_underscores: self-explanatory, includes leading underscores
example: ["_b", "a", "c"]
Leading underscores
If a function is:
- internal to another (nested) it is given a leading underscore.
- called by another in the same module it is given a leading underscore.
Otherwise it has no leading underscore.
To use
python3 -m headline <cwd> [src_dir] [tests_dir] [sort_type] [tests_only] [rename] [suffix]
args
-
cwd: the directory to run the process on -
src_dir: the directory with the source files,headlinewill match files in this directory to those with thetest_prefix in the specified tests directory -
test_dir: the directory where the test files are for the source files -
sort_type:newspaper: sort functions based on a custom "newspaper" logic.called: sort functions by the number of times they are referenced or "called" by other functionscalls: sort functions based on the number of references or "calls" they make to other functionsalphabetical: sort functions alphabetically, ignoring leading underscoresalphabetical_include_leading_underscores: sort functions alphabetically, including leading underscores in the sort order
-
rename: add leading underscores to functions that are used internally within the module -
suffix: if you want to tryheadlineon your code but not apply the changes inplace, this will create files with the suffix you specify, somy_file.pywith suffix_examplewill have headline applied to it and save tomy_file_example.py
Release files for headline 0.0.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 | |
|---|---|---|---|
| headline-0.0.1.tar.gz | 13.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| headline-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / headline-0.0.1.tar.gz
| Download URL | headline-0.0.1.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
470e19db50aa75fcf8d04d29c82217ed9b146b02288b6cd3fb29b1d1c1d640c3
|
|
BLAKE2b-256 checksum How to use checksums |
1db00e65308b58073dab90ab043b2cace4e596d7c6a4ef0320fab2a810bbc945
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2024.
Transparency logRelease files / headline-0.0.1-py3-none-any.whl
| Download URL | headline-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
100a28b1b4ea06235152fc01bf23579adcc15a0f49fdcd607a385faf68ac0156
|
|
BLAKE2b-256 checksum How to use checksums |
3d33a66b33dedd53addee36165da147d9437c7911041a02563fc4c366d0936e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2024.
Transparency log