diff --git a/Readme.md b/Readme.md index 88d008afe..f28ec1cd6 100644 --- a/Readme.md +++ b/Readme.md @@ -8,7 +8,7 @@ Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages. -This project was meant as a zero configuration replacement for [setuptools-rust](https://github.com/PyO3/setuptools-rust). It supports building wheels for python 3.5+ on windows, linux and mac, can upload them to [pypi](https://pypi.org/) and has basic pypy support. +This project is meant as a zero configuration replacement for [setuptools-rust](https://github.com/PyO3/setuptools-rust) and [milksnake](https://github.com/getsentry/milksnake). It supports building wheels for python 3.5+ on windows, linux and mac, can upload them to [pypi](https://pypi.org/) and has basic pypy support. ## Usage @@ -18,12 +18,6 @@ You can either download binaries from the [latest release](https://github.com/Py pip install pyo3-pack ``` -You can also install pyo3-pack from source, though it's an older version: - -```shell -cargo install pyo3-pack -``` - There are three main commands: * `pyo3-pack publish` builds the crate into python packages and publishes them to pypi. diff --git a/src/module_writer.rs b/src/module_writer.rs index b9e0fc8c6..5c88326b7 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -27,10 +27,10 @@ use zip::{self, ZipWriter}; /// Allows writing the module to a wheel or add it directly to the virtualenv pub trait ModuleWriter { /// Adds a directory relative to the module base path - fn add_directory(&mut self, path: impl AsRef) -> Result<(), io::Error>; + fn add_directory(&mut self, path: impl AsRef) -> Result<(), Error>; /// Adds a file with bytes as content in target relative to the module base path - fn add_bytes(&mut self, target: impl AsRef, bytes: &[u8]) -> Result<(), io::Error> { + fn add_bytes(&mut self, target: impl AsRef, bytes: &[u8]) -> Result<(), Error> { // 0o644 is the default from the zip crate self.add_bytes_with_permissions(target, bytes, 0o644) } @@ -42,18 +42,19 @@ pub trait ModuleWriter { target: impl AsRef, bytes: &[u8], permissions: u32, - ) -> Result<(), io::Error>; + ) -> Result<(), Error>; /// Copies the source file the the target path relative to the module base path fn add_file( &mut self, target: impl AsRef, source: impl AsRef, - ) -> Result<(), io::Error> { - let mut file = File::open(source)?; + ) -> Result<(), Error> { + let mut file = File::open(&source).context("Failed to read file at {}")?; let mut buffer = Vec::new(); file.read_to_end(&mut buffer)?; - self.add_bytes(target, &buffer) + self.add_bytes(target, &buffer)?; + Ok(()) } } @@ -106,8 +107,9 @@ impl PathWriter { } impl ModuleWriter for PathWriter { - fn add_directory(&mut self, path: impl AsRef) -> Result<(), io::Error> { - fs::create_dir_all(self.base_path.join(path)) + fn add_directory(&mut self, path: impl AsRef) -> Result<(), Error> { + fs::create_dir_all(self.base_path.join(path))?; + Ok(()) } fn add_bytes_with_permissions( @@ -115,7 +117,7 @@ impl ModuleWriter for PathWriter { target: impl AsRef, bytes: &[u8], _permissions: u32, - ) -> Result<(), io::Error> { + ) -> Result<(), Error> { let path = self.base_path.join(target); // We only need to set the executable bit on unix @@ -134,7 +136,8 @@ impl ModuleWriter for PathWriter { } }; - file.write_all(bytes) + file.write_all(bytes)?; + Ok(()) } } @@ -147,7 +150,7 @@ pub struct WheelWriter { } impl ModuleWriter for WheelWriter { - fn add_directory(&mut self, _path: impl AsRef) -> Result<(), io::Error> { + fn add_directory(&mut self, _path: impl AsRef) -> Result<(), Error> { Ok(()) // We don't need to create directories in zip archives } @@ -156,7 +159,7 @@ impl ModuleWriter for WheelWriter { target: impl AsRef, bytes: &[u8], permissions: u32, - ) -> Result<(), io::Error> { + ) -> Result<(), Error> { // So apparently we must use unix style paths for pypi's checks to succeed; Without // the replacing we get a "400 Client Error: Invalid distribution file." let target = target.as_ref().to_str().unwrap().replace("\\", "/"); @@ -183,7 +186,7 @@ impl WheelWriter { metadata21: &Metadata21, scripts: &HashMap, tags: &[String], - ) -> Result { + ) -> Result { let wheel_path = wheel_dir.join(format!( "{}-{}-{}.whl", metadata21.get_distribution_escaped(), @@ -230,7 +233,7 @@ pub struct SDistWriter { } impl ModuleWriter for SDistWriter { - fn add_directory(&mut self, _path: impl AsRef) -> Result<(), io::Error> { + fn add_directory(&mut self, _path: impl AsRef) -> Result<(), Error> { Ok(()) } @@ -239,12 +242,18 @@ impl ModuleWriter for SDistWriter { target: impl AsRef, bytes: &[u8], permissions: u32, - ) -> Result<(), io::Error> { + ) -> Result<(), Error> { let mut header = tar::Header::new_gnu(); header.set_size(bytes.len() as u64); header.set_mode(permissions); header.set_cksum(); - self.tar.append_data(&mut header, target, bytes)?; + self.tar + .append_data(&mut header, &target, bytes) + .context(format!( + "Failed to add {} bytes to sdist as {}", + bytes.len(), + target.as_ref().display() + ))?; Ok(()) } @@ -252,8 +261,14 @@ impl ModuleWriter for SDistWriter { &mut self, target: impl AsRef, source: impl AsRef, - ) -> Result<(), io::Error> { - self.tar.append_path_with_name(source, target)?; + ) -> Result<(), Error> { + self.tar + .append_path_with_name(&source, &target) + .context(format!( + "Failed to add file from {} to sdist as {}", + source.as_ref().display(), + target.as_ref().display(), + ))?; Ok(()) } } @@ -518,7 +533,7 @@ pub fn write_dist_info( metadata21: &Metadata21, scripts: &HashMap, tags: &[String], -) -> Result<(), io::Error> { +) -> Result<(), Error> { let dist_info_dir = metadata21.get_dist_info_dir(); writer.add_directory(&dist_info_dir)?; diff --git a/test-dockerfile.sh b/test-dockerfile.sh index 9db4deb42..0ac22b3fa 100755 --- a/test-dockerfile.sh +++ b/test-dockerfile.sh @@ -12,7 +12,7 @@ source venv-docker/bin/activate pip install cffi > /dev/null -docker run --rm -v $(pwd)/test-crates/hello-world:/io pyo3-pack build -b bin +docker run --rm -v $(pwd)/test-crates/hello-world:/io pyo3-pack build --no-sdist -b bin pip install hello-world --no-index --find-links test-crates/hello-world/target/wheels/ @@ -20,7 +20,7 @@ if [[ $(python test-crates/hello-world/check_installed/check_installed.py) != 'S exit 1 fi -docker run --rm -v $(pwd)/test-crates/cffi-pure:/io pyo3-pack build -b cffi +docker run --rm -v $(pwd)/test-crates/cffi-pure:/io pyo3-pack build --no-sdist -b cffi pip install cffi-pure --no-index --find-links test-crates/cffi-pure/target/wheels/ @@ -28,7 +28,7 @@ if [[ $(python test-crates/cffi-pure/check_installed/check_installed.py) != 'SUC exit 1 fi -docker run --rm -v $(pwd)/test-crates/cffi-mixed:/io pyo3-pack build -b cffi +docker run --rm -v $(pwd)/test-crates/cffi-mixed:/io pyo3-pack build --no-sdist -b cffi pip install cffi-mixed --no-index --find-links test-crates/cffi-mixed/target/wheels/ @@ -36,7 +36,7 @@ if [[ $(python test-crates/cffi-mixed/check_installed/check_installed.py) != 'SU exit 1 fi -docker run --rm -v $(pwd)/test-crates/pyo3-pure:/io pyo3-pack build -i python3.6 +docker run --rm -v $(pwd)/test-crates/pyo3-pure:/io pyo3-pack build --no-sdist -i python3.6 pip install pyo3-pure --no-index --find-links test-crates/pyo3-pure/target/wheels/ @@ -44,7 +44,7 @@ if [[ $(python test-crates/pyo3-pure/check_installed/check_installed.py) != 'SUC exit 1 fi -docker run --rm -v $(pwd)/test-crates/pyo3-mixed:/io pyo3-pack build -i python3.6 +docker run --rm -v $(pwd)/test-crates/pyo3-mixed:/io pyo3-pack build --no-sdist -i python3.6 pip install pyo3-mixed --no-index --find-links test-crates/pyo3-mixed/target/wheels/