Skip to content

Commit 2e01fde

Browse files
committed
rust: exclude standard library test files from install_only archives
These files shouldn't be needed for most installs. So including them in the `install_only` archives is wasteful. On the 3.10 x86_64-unknown-linux-gnu distributions, this reduces the archive size from 29,628,194 to 25,109,023. The gzip compressed `install_only` archives are now smaller than the zstd compressed full archives. Part of #134.
1 parent b631692 commit 2e01fde

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/release.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use {
6-
anyhow::Result,
6+
crate::json::parse_python_json,
7+
anyhow::{anyhow, Result},
78
once_cell::sync::Lazy,
89
semver::VersionReq,
910
std::{
@@ -182,7 +183,25 @@ pub fn convert_to_install_only<W: Write>(reader: impl BufRead, writer: W) -> Res
182183

183184
let mut builder = tar::Builder::new(writer);
184185

185-
for entry in tar_in.entries()? {
186+
let mut entries = tar_in.entries()?;
187+
188+
// First entry in archive should be python/PYTHON.json.
189+
let mut entry = entries.next().expect("tar must have content")?;
190+
if entry.path_bytes().as_ref() != b"python/PYTHON.json" {
191+
return Err(anyhow!("first archive entry not PYTHON.json"));
192+
}
193+
194+
let mut json_data = vec![];
195+
entry.read_to_end(&mut json_data)?;
196+
197+
let json_main = parse_python_json(&json_data)?;
198+
199+
let stdlib_path = json_main
200+
.python_paths
201+
.get("stdlib")
202+
.expect("stdlib entry expected");
203+
204+
for entry in entries {
186205
let mut entry = entry?;
187206

188207
let path_bytes = entry.path_bytes();
@@ -191,7 +210,7 @@ pub fn convert_to_install_only<W: Write>(reader: impl BufRead, writer: W) -> Res
191210
continue;
192211
}
193212

194-
// Also strip the libpython static library, as it significantly
213+
// Strip the libpython static library, as it significantly
195214
// increases the size of the archive and isn't needed in most cases.
196215
if path_bytes
197216
.windows(b"/libpython".len())
@@ -202,6 +221,22 @@ pub fn convert_to_install_only<W: Write>(reader: impl BufRead, writer: W) -> Res
202221
continue;
203222
}
204223

224+
// Strip standard library test modules, as they aren't needed in regular
225+
// installs. We do this based on the metadata in PYTHON.json for
226+
// consistency.
227+
if json_main
228+
.python_stdlib_test_packages
229+
.iter()
230+
.any(|test_package| {
231+
let package_path =
232+
format!("python/{}/{}/", stdlib_path, test_package.replace('.', "/"));
233+
234+
path_bytes.starts_with(package_path.as_bytes())
235+
})
236+
{
237+
continue;
238+
}
239+
205240
let mut data = vec![];
206241
entry.read_to_end(&mut data)?;
207242

0 commit comments

Comments
 (0)