Skip to content

Commit

Permalink
Fix docker test
Browse files Browse the repository at this point in the history
Apparent there's still something wrong with relative vs. absolute paths in the source distribution function
  • Loading branch information
konstin committed Jun 24, 2019
1 parent 03e6514 commit b521ada
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
8 changes: 1 addition & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
53 changes: 34 additions & 19 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> Result<(), io::Error>;
fn add_directory(&mut self, path: impl AsRef<Path>) -> 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<Path>, bytes: &[u8]) -> Result<(), io::Error> {
fn add_bytes(&mut self, target: impl AsRef<Path>, bytes: &[u8]) -> Result<(), Error> {
// 0o644 is the default from the zip crate
self.add_bytes_with_permissions(target, bytes, 0o644)
}
Expand All @@ -42,18 +42,19 @@ pub trait ModuleWriter {
target: impl AsRef<Path>,
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<Path>,
source: impl AsRef<Path>,
) -> 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(())
}
}

Expand Down Expand Up @@ -106,16 +107,17 @@ impl PathWriter {
}

impl ModuleWriter for PathWriter {
fn add_directory(&mut self, path: impl AsRef<Path>) -> Result<(), io::Error> {
fs::create_dir_all(self.base_path.join(path))
fn add_directory(&mut self, path: impl AsRef<Path>) -> Result<(), Error> {
fs::create_dir_all(self.base_path.join(path))?;
Ok(())
}

fn add_bytes_with_permissions(
&mut self,
target: impl AsRef<Path>,
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
Expand All @@ -134,7 +136,8 @@ impl ModuleWriter for PathWriter {
}
};

file.write_all(bytes)
file.write_all(bytes)?;
Ok(())
}
}

Expand All @@ -147,7 +150,7 @@ pub struct WheelWriter {
}

impl ModuleWriter for WheelWriter {
fn add_directory(&mut self, _path: impl AsRef<Path>) -> Result<(), io::Error> {
fn add_directory(&mut self, _path: impl AsRef<Path>) -> Result<(), Error> {
Ok(()) // We don't need to create directories in zip archives
}

Expand All @@ -156,7 +159,7 @@ impl ModuleWriter for WheelWriter {
target: impl AsRef<Path>,
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("\\", "/");
Expand All @@ -183,7 +186,7 @@ impl WheelWriter {
metadata21: &Metadata21,
scripts: &HashMap<String, String>,
tags: &[String],
) -> Result<WheelWriter, io::Error> {
) -> Result<WheelWriter, Error> {
let wheel_path = wheel_dir.join(format!(
"{}-{}-{}.whl",
metadata21.get_distribution_escaped(),
Expand Down Expand Up @@ -230,7 +233,7 @@ pub struct SDistWriter {
}

impl ModuleWriter for SDistWriter {
fn add_directory(&mut self, _path: impl AsRef<Path>) -> Result<(), io::Error> {
fn add_directory(&mut self, _path: impl AsRef<Path>) -> Result<(), Error> {
Ok(())
}

Expand All @@ -239,21 +242,33 @@ impl ModuleWriter for SDistWriter {
target: impl AsRef<Path>,
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(())
}

fn add_file(
&mut self,
target: impl AsRef<Path>,
source: impl AsRef<Path>,
) -> 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(())
}
}
Expand Down Expand Up @@ -518,7 +533,7 @@ pub fn write_dist_info(
metadata21: &Metadata21,
scripts: &HashMap<String, String, impl std::hash::BuildHasher>,
tags: &[String],
) -> Result<(), io::Error> {
) -> Result<(), Error> {
let dist_info_dir = metadata21.get_dist_info_dir();

writer.add_directory(&dist_info_dir)?;
Expand Down
10 changes: 5 additions & 5 deletions test-dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ 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/

if [[ $(python test-crates/hello-world/check_installed/check_installed.py) != 'SUCCESS' ]]; then
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/

if [[ $(python test-crates/cffi-pure/check_installed/check_installed.py) != 'SUCCESS' ]]; then
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/

if [[ $(python test-crates/cffi-mixed/check_installed/check_installed.py) != 'SUCCESS' ]]; then
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/

if [[ $(python test-crates/pyo3-pure/check_installed/check_installed.py) != 'SUCCESS' ]]; then
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/

Expand Down

0 comments on commit b521ada

Please sign in to comment.