Skip to content

compileall shouldn't recompile up-to-date files with hash-based invalidation mode #121577

@kulikjak

Description

@kulikjak

Feature or enhancement

Proposal:

When you compile sources into .pyc files with python -m compileall while using the defaul invalidation mode (timestamp), the script verifies whether the compilation is necessary (the pyc file is up to date) and can skip it:

$> python -m compileall --invalidation-mode=timestamp script.py
Compiling 'script.py'...
$> python -m compileall --invalidation-mode=timestamp script.py
$>   # the compilation is skipped

When either of the hash invalidation modes is used instead, this doesn't work - the hash based check is not there. https://github.com/python/cpython/blob/main/Lib/compileall.py#L229

$> python -m compileall --invalidation-mode=checked-hash script.py
Compiling 'script.py'...
$> python -m compileall --invalidation-mode=checked-hash script.py
Compiling 'script.py'...
$>

I think it would make sense to add the same functionality for the other two invalidation modes as well?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions