Skip to content

Conversation

hetmankp
Copy link
Contributor

@hetmankp hetmankp commented Aug 30, 2023

This resolves issue #105931. Currently the '-s STRIPDIR' option on compileall can lead to some surprising results as it only strips away path components that match, but leaves alone the non-matching ones interspersed in between.

For example, with: python -m compileall -s/path/to/another/src /path/to/build/src/file.py

The resulting written path will be: build/file.py

This fix only strips directories that are a fully matching prefix of the source path. If a stripdir is provided that is not a valid prefix, a warning will be displayed (which can be silenced with '-qq').

This resolves issue python#105931. Currently the '-s STRIPDIR' option on
compileall can lead to some surprising results as it only strips away
path components that match, but leaves alone the non-matching ones
interspersed in between.

For example, with: python -m compileall -s/path/to/another/src
/path/to/build/src/file.py

The resulting written path will be: build/file.py

This fix only strips directories that are a fully matching prefix of the
source path. If a stripdir is provided that is not a valid prefix, a
warning will be displayed (which can be silenced with '-qq').
Copy link
Contributor

@frenzymadness frenzymadness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the simplicity of the solution and I have just one suggestion. I'm not a core developer so we'll need someone to approve and merge this, Cc: @encukou (helped with the original implementation so he has the necessary context).

@frenzymadness
Copy link
Contributor

@encukou could you please help us to move this forward?

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original behaviour is clearly wrong.
IMO, we don't need a deprecation period to change it: the filename is essentially debug information.
I don't plan to backport to this to previous versions (at least initially): new warnings/outputs tend to cause trouble for users.

@encukou encukou enabled auto-merge (squash) October 23, 2023 13:35
@encukou encukou merged commit 3726cb0 into python:main Oct 23, 2023
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…GH-108671)

Before, the '-s STRIPDIR' option on
compileall lead to some surprising results as it only strips away
path components that match, but leaves alone the non-matching ones
interspersed in between.

For example, with: python -m compileall -s/path/to/another/src
/path/to/build/src/file.py

The resulting written path will be: build/file.py

This fix only strips directories that are a fully matching prefix of the
source path. If a stripdir is provided that is not a valid prefix, a
warning will be displayed (which can be silenced with '-qq').
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…GH-108671)

Before, the '-s STRIPDIR' option on
compileall lead to some surprising results as it only strips away
path components that match, but leaves alone the non-matching ones
interspersed in between.

For example, with: python -m compileall -s/path/to/another/src
/path/to/build/src/file.py

The resulting written path will be: build/file.py

This fix only strips directories that are a fully matching prefix of the
source path. If a stripdir is provided that is not a valid prefix, a
warning will be displayed (which can be silenced with '-qq').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants