Merge pull request #16866 from cho-m/venv-all-bottle

cleaner: remove RECORD and modify INSTALLER
This commit is contained in:
Michael Cho 2024-03-10 19:55:47 -04:00 committed by GitHub
commit ae0ceee74f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 12 deletions

View File

@ -58,7 +58,7 @@ class Cleaner
end end
rewrite_shebangs rewrite_shebangs
remove_pip_direct_url clean_python_metadata
prune prune
end end
@ -165,25 +165,27 @@ class Cleaner
end end
end end
# Remove non-reproducible pip direct_url.json which records the /tmp build directory # Remove non-reproducible pip direct_url.json which records the /tmp build directory.
# Remove RECORD files to prevent changes to the installed Python package.
# Modify INSTALLER to provide information that files are managed by brew.
#
# @see https://packaging.python.org/en/latest/specifications/recording-installed-packages/
sig { void } sig { void }
def remove_pip_direct_url def clean_python_metadata
basepath = @formula.prefix.realpath basepath = @formula.prefix.realpath
basepath.find do |path| basepath.find do |path|
Find.prune if @formula.skip_clean?(path) Find.prune if @formula.skip_clean?(path)
next if path.directory? || path.symlink? next if path.directory? || path.symlink?
next if path.basename.to_s != "direct_url.json"
next if path.parent.extname != ".dist-info" next if path.parent.extname != ".dist-info"
odebug "Removing #{path}" case path.basename.to_s
path.unlink when "direct_url.json", "RECORD"
observe_file_removal path
record = path.parent/"RECORD" when "INSTALLER"
next unless record.file? odebug "Modifying #{path} contents from #{path.read.chomp} to brew"
path.atomic_write("brew\n")
odebug "Modifying #{record}" end
@formula.inreplace record, %r{^.*/direct_url\.json,.*$\n?}, "", false
end end
end end
end end

View File

@ -155,6 +155,52 @@ RSpec.describe Cleaner do
expect(arch_file).not_to exist expect(arch_file).not_to exist
expect(name_file).to exist expect(name_file).to exist
end end
it "removes '*.dist-info/direct_url.json' files" do
dir = f.lib/"python3.12/site-packages/test.dist-info"
file = dir/"direct_url.json"
unrelated_file = dir/"METADATA"
unrelated_dir_file = f.lib/"direct_url.json"
dir.mkpath
touch file
touch unrelated_file
touch unrelated_dir_file
cleaner.clean
expect(file).not_to exist
expect(unrelated_file).to exist
expect(unrelated_dir_file).to exist
end
it "removes '*.dist-info/RECORD' files" do
dir = f.lib/"python3.12/site-packages/test.dist-info"
file = dir/"RECORD"
unrelated_file = dir/"METADATA"
unrelated_dir_file = f.lib/"RECORD"
dir.mkpath
touch file
touch unrelated_file
touch unrelated_dir_file
cleaner.clean
expect(file).not_to exist
expect(unrelated_file).to exist
expect(unrelated_dir_file).to exist
end
it "modifies '*.dist-info/INSTALLER' files" do
file = f.lib/"python3.12/site-packages/test.dist-info/INSTALLER"
file.dirname.mkpath
file.write "pip\n"
cleaner.clean
expect(file.read).to eq "brew\n"
end
end end
describe "::skip_clean" do describe "::skip_clean" do