-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-28494: Test existing zipfile working behavior. #15853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Test data for `test_zipfile` | ||
|
||
The test executables in this directory are created manually from header.sh and | ||
the `testdata_module_inside_zip.py` file. You must have infozip's zip utility | ||
installed (`apt install zip` on Debian). | ||
|
||
## Purpose | ||
|
||
These are used to test executable files with an appended zipfile, in a scenario | ||
where the executable is _not_ a Python interpreter itself so our automatic | ||
zipimport machinery (that'd look for `__main__.py`) is not being used. | ||
|
||
## Updating the test executables | ||
|
||
If you update header.sh or the testdata_module_inside_zip.py file, rerun the | ||
commands below. These are expected to be rarely changed, if ever. | ||
|
||
### Standard old format (2.0) zip file | ||
|
||
``` | ||
zip -0 zip2.zip testdata_module_inside_zip.py | ||
cat header.sh zip2.zip >exe_with_zip | ||
rm zip2.zip | ||
``` | ||
|
||
### Modern format (4.5) zip64 file | ||
|
||
Redirecting from stdin forces infozip's zip tool to create a zip64. | ||
|
||
``` | ||
zip -0 <testdata_module_inside_zip.py >zip64.zip | ||
cat header.sh zip64.zip >exe_with_z64 | ||
rm zip64.zip | ||
``` | ||
|
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
INTERPRETER_UNDER_TEST="$1" | ||
if [[ ! -x "${INTERPRETER_UNDER_TEST}" ]]; then | ||
echo "Interpreter must be the command line argument." | ||
exit 4 | ||
fi | ||
EXECUTABLE="$0" exec "${INTERPRETER_UNDER_TEST}" -E - <<END_OF_PYTHON | ||
import os | ||
import zipfile | ||
namespace = {} | ||
filename = os.environ['EXECUTABLE'] | ||
print(f'Opening {filename} as a zipfile.') | ||
with zipfile.ZipFile(filename, mode='r') as exe_zip: | ||
for file_info in exe_zip.infolist(): | ||
data = exe_zip.read(file_info) | ||
exec(data, namespace, namespace) | ||
break # Only use the first file in the archive. | ||
print('Favorite number in executable:', namespace["FAVORITE_NUMBER"]) | ||
### Archive contents will be appended after this file. ### | ||
END_OF_PYTHON |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Test data file to be stored within a zip file. | ||
FAVORITE_NUMBER = 5 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using shutil.which('bash') instead? There are some windows machines with bash installed now... will the test work there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think windows supported #! line executables as a concept. executable is based on filename ending in bat/cmd/com/exe, not an execute bit there.