Skip to content

Surprising behaviour with compileall -s STRIPDIR parameter #105931

Closed
@hetmankp

Description

@hetmankp

The '-s' stripdir parameter to compileall has very unusual semantics that could lead to unexpected and potentially confusing outcomes.

For example, when run like this: python -m compileall -s/path/to/build/dst -p /lib /path/to/build/src/file.py

The source file path written to the compiled file will be: /lib/src/file.py. In other words the source file path is partially stripped even though the strip prefix doesn't fully match the source file path. Since this was introduced in #16012 I'd like to get @frenzymadness to comment if this was intentional, because it seems that it could be a source of really confusing bugs for end users who accidentally misspell something in their invocation and get a partially stripped result.

It gets weirder than that however, when run like this: python -m compileall -s/path/to/another/src -p /lib /path/to/build/src/file.py

The source file path written to the compiled file will be: /lib/build/file.py. The matching directories are removed around the non-matching ones. Even if there was some reason for the first behaviour it seems this second one is absolutely not a good idea.

I'm happy to fix this once it is confirmed this behaviour is unintentional.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions