Skip to main content

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, headline will match files in this directory to those with the test_ 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 functions
    • calls : sort functions based on the number of references or "calls" they make to other functions
    • alphabetical: sort functions alphabetically, ignoring leading underscores
    • alphabetical_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 try headline on your code but not apply the changes inplace, this will create files with the suffix you specify, so my_file.py with suffix _example will have headline applied to it and save to my_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)

Source distribution for headline 0.0.1
File Size Uploaded
headline-0.0.1.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for headline 0.0.1
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page