Skip to content

Commit

Permalink
pyo3-build-config: increased test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jun 26, 2021
1 parent 8fb4ce6 commit b7e192f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 21 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,33 @@ jobs:
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }} ${{ matrix.msrv }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false # If one platform fails, allow the rest to keep testing.
fail-fast: false # If one platform fails, allow the rest to keep testing.
matrix:
rust: [stable]
python-version: [3.6, 3.7, 3.8, 3.9, 3.10-dev, pypy-3.6, pypy-3.7]
platform: [
{ os: "macos-latest", python-architecture: "x64", rust-target: "x86_64-apple-darwin" },
{ os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" },
{ os: "windows-latest", python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc" },
{ os: "windows-latest", python-architecture: "x86", rust-target: "i686-pc-windows-msvc" },
]
platform:
[
{
os: "macos-latest",
python-architecture: "x64",
rust-target: "x86_64-apple-darwin",
},
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
},
{
os: "windows-latest",
python-architecture: "x64",
rust-target: "x86_64-pc-windows-msvc",
},
{
os: "windows-latest",
python-architecture: "x86",
rust-target: "i686-pc-windows-msvc",
},
]
exclude:
# There is no 64-bit pypy on windows for pypy-3.6
- python-version: pypy-3.6
Expand All @@ -63,7 +80,12 @@ jobs:
# Test minimal supported Rust version
- rust: 1.41.1
python-version: 3.9
platform: { os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" }
platform:
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
}
msrv: "MSRV"

steps:
Expand Down Expand Up @@ -146,6 +168,9 @@ jobs:
- name: Test proc-macro code
run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml

- name: Test build config
run: cargo test --manifest-path=pyo3-build-config/Cargo.toml

- name: Install python test dependencies
run: python -m pip install -U pip tox

Expand Down Expand Up @@ -193,8 +218,10 @@ jobs:
override: true
profile: minimal
components: llvm-tools-preview
- run: LLVM_PROFILE_FILE="coverage-%p-%m.profraw" cargo test --no-default-features --no-fail-fast
- run: LLVM_PROFILE_FILE="coverage-features-%p-%m.profraw" cargo test --no-default-features --no-fail-fast --features "macros num-bigint num-complex hashbrown serde multiple-pymethods"
- run: cargo test --no-default-features --no-fail-fast
- run: cargo test --no-default-features --no-fail-fast --features "macros num-bigint num-complex hashbrown serde multiple-pymethods"
- run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml
- run: cargo test --manifest-path=pyo3-build-config/Cargo.toml
# can't yet use actions-rs/grcov with source-based coverage: https://github.com/actions-rs/grcov/issues/105
# - uses: actions-rs/[email protected]
# id: coverage
Expand All @@ -210,3 +237,4 @@ jobs:
CARGO_TERM_VERBOSE: true
RUSTFLAGS: "-Zinstrument-coverage"
RUSTDOCFLAGS: "-Zinstrument-coverage"
LLVM_PROFILE_FILE: "coverage-%p-%m.profraw"
40 changes: 29 additions & 11 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,24 @@ impl InterpreterConfig {

#[doc(hidden)]
pub fn to_writer(&self, mut writer: impl Write) -> Result<()> {
macro_rules! writeln_option {
($writer:expr, $opt:expr) => {
match &$opt {
Some(value) => writeln!($writer, "{}", value),
None => writeln!($writer, "null"),
}
};
}
writeln!(writer, "{}", self.version.major)?;
writeln!(writer, "{}", self.version.minor)?;
writeln!(writer, "{:?}", self.libdir)?;
writeln_option!(writer, self.libdir)?;
writeln!(writer, "{}", self.shared)?;
writeln!(writer, "{}", self.abi3)?;
writeln!(writer, "{:?}", self.ld_version)?;
writeln!(writer, "{:?}", self.base_prefix)?;
writeln!(writer, "{:?}", self.executable)?;
writeln!(writer, "{:?}", self.calcsize_pointer)?;
writeln!(writer, "{:?}", self.implementation)?;
writeln_option!(writer, self.ld_version)?;
writeln_option!(writer, self.base_prefix)?;
writeln_option!(writer, self.executable)?;
writeln_option!(writer, self.calcsize_pointer)?;
writeln!(writer, "{}", self.implementation)?;
for flag in &self.build_flags.0 {
writeln!(writer, "{}", flag)?;
}
Expand All @@ -156,12 +164,10 @@ fn parse_option_string<T: FromStr>(string: String) -> Result<Option<T>>
where
<T as FromStr>::Err: std::error::Error + 'static,
{
if string == "None" {
if string == "null" {
Ok(None)
} else if string.starts_with("Some(") && string.ends_with(')') {
Ok(string[5..(string.len() - 1)].parse().map(Some)?)
} else {
Err("expected None or Some(value)".into())
Ok(string.parse().map(Some)?)
}
}

Expand All @@ -187,6 +193,15 @@ pub enum PythonImplementation {
PyPy,
}

impl Display for PythonImplementation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PythonImplementation::CPython => write!(f, "CPython"),
PythonImplementation::PyPy => write!(f, "PyPy"),
}
}
}

impl FromStr for PythonImplementation {
type Err = Box<dyn std::error::Error>;
fn from_str(s: &str) -> Result<Self> {
Expand Down Expand Up @@ -333,7 +348,10 @@ impl FromStr for BuildFlag {
/// we will pick up and pass to rustc via `--cfg=py_sys_config={varname}`;
/// this allows using them conditional cfg attributes in the .rs files, so
///
/// #[cfg(py_sys_config="{varname}"]
/// ```rust
/// #[cfg(py_sys_config="{varname}")]
/// # struct Foo;
/// ```
///
/// is the equivalent of `#ifdef {varname}` in C.
///
Expand Down

0 comments on commit b7e192f

Please sign in to comment.