dynamically reorder functions
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file headline-0.0.1.tar.gz.
File metadata
- Download URL: headline-0.0.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
470e19db50aa75fcf8d04d29c82217ed9b146b02288b6cd3fb29b1d1c1d640c3
|
|
| MD5 |
e126459065b56448fd3140ab097dedd9
|
|
| BLAKE2b-256 |
1db00e65308b58073dab90ab043b2cace4e596d7c6a4ef0320fab2a810bbc945
|
Provenance
The following attestation bundles were made for headline-0.0.1.tar.gz:
Publisher:
publish.yaml on second-ed/headline
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
headline-0.0.1.tar.gz -
Subject digest:
470e19db50aa75fcf8d04d29c82217ed9b146b02288b6cd3fb29b1d1c1d640c3 - Sigstore transparency entry: 145996916
- Sigstore integration time:
-
Permalink:
second-ed/headline@e9040da8997442b73a9044ef7c0ec0315db46af5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/second-ed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e9040da8997442b73a9044ef7c0ec0315db46af5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file headline-0.0.1-py3-none-any.whl.
File metadata
- Download URL: headline-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
100a28b1b4ea06235152fc01bf23579adcc15a0f49fdcd607a385faf68ac0156
|
|
| MD5 |
b4ff629023d07e79f5fec9a7ba908847
|
|
| BLAKE2b-256 |
3d33a66b33dedd53addee36165da147d9437c7911041a02563fc4c366d0936e0
|
Provenance
The following attestation bundles were made for headline-0.0.1-py3-none-any.whl:
Publisher:
publish.yaml on second-ed/headline
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
headline-0.0.1-py3-none-any.whl -
Subject digest:
100a28b1b4ea06235152fc01bf23579adcc15a0f49fdcd607a385faf68ac0156 - Sigstore transparency entry: 145996917
- Sigstore integration time:
-
Permalink:
second-ed/headline@e9040da8997442b73a9044ef7c0ec0315db46af5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/second-ed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e9040da8997442b73a9044ef7c0ec0315db46af5 -
Trigger Event:
release
-
Statement type: