Skip to content

Commit 3a08376

Browse files
committed
POC stable rust (2 tests failing)
1 parent fc3fa70 commit 3a08376

File tree

11 files changed

+62
-47
lines changed

11 files changed

+62
-47
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Install Rust
2626
uses: actions-rs/toolchain@v1
2727
with:
28-
toolchain: nightly
28+
toolchain: stable
2929
default: true
3030
- run: rustup set default-host ${{ matrix.platform.rust-target }}
3131
- name: Build without default features

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
env:
3333
global:
34-
- TRAVIS_RUST_VERSION=nightly
34+
- TRAVIS_RUST_VERSION=stable
3535
- RUST_BACKTRACE=1
3636

3737
before_install:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9+
- stable rust support
910
- Add FFI definition `PyObject_AsFileDescriptor` [#938](https://github.com/PyO3/pyo3/pull/938)
1011

1112
### Changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ unindent = { version = "0.1.4", optional = true }
3434
assert_approx_eq = "1.1.0"
3535
trybuild = "1.0.23"
3636

37-
[build-dependencies]
38-
version_check = "0.9.1"
39-
4037
[features]
4138
default = ["macros"]
4239
macros = ["ctor", "indoc", "inventory", "paste", "pyo3cls", "unindent"]
40+
nightly = []
4341

4442
# this is no longer needed internally, but setuptools-rust assumes this feature
4543
python3 = []

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste
1616

1717
## Usage
1818

19-
PyO3 supports Python 3.5 and up. The minimum required Rust version is 1.42.0-nightly 2020-01-21.
20-
21-
If you have never used nightly Rust, the official guide has
22-
[a great section](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#rustup-and-the-role-of-rust-nightly)
23-
about installing it.
19+
PyO3 supports Python 3.5 and up. The minimum required Rust version is 1.44.
2420

2521
PyPy is also supported (via cpyext) for Python 3.5 only, targeted PyPy version is 7.0.0.
2622
Please refer to the [pypy section in the guide](https://pyo3.rs/master/pypy.html).

build.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ use std::{
88
process::{Command, Stdio},
99
str::FromStr,
1010
};
11-
use version_check::{Channel, Date, Version};
12-
13-
/// Specifies the minimum nightly version needed to compile pyo3.
14-
/// Keep this synced up with the travis ci config,
15-
/// But note that this is the rustc version which can be lower than the nightly version
16-
const MIN_DATE: &str = "2020-01-20";
17-
const MIN_VERSION: &str = "1.42.0-nightly";
1811

1912
const PY3_MIN_MINOR: u8 = 5;
2013
const CFG_KEY: &str = "py_sys_config";
@@ -567,34 +560,7 @@ fn check_target_architecture(interpreter_config: &InterpreterConfig) -> Result<(
567560
Ok(())
568561
}
569562

570-
fn check_rustc_version() -> Result<()> {
571-
let channel = Channel::read().ok_or("Failed to determine rustc channel")?;
572-
if !channel.supports_features() {
573-
bail!("PyO3 requires a nightly or dev version of Rust.");
574-
}
575-
576-
let actual_version = Version::read().ok_or("Failed to determine the rustc version")?;
577-
if !actual_version.at_least(MIN_VERSION) {
578-
bail!(
579-
"PyO3 requires at least rustc {}, while the current version is {}",
580-
MIN_VERSION,
581-
actual_version
582-
)
583-
}
584-
585-
let actual_date = Date::read().ok_or("Failed to determine the rustc date")?;
586-
if !actual_date.at_least(MIN_DATE) {
587-
bail!(
588-
"PyO3 requires at least rustc {}, while the current rustc date is {}",
589-
MIN_DATE,
590-
actual_date
591-
)
592-
}
593-
Ok(())
594-
}
595-
596563
fn main() -> Result<()> {
597-
check_rustc_version()?;
598564
// 1. Setup cfg variables so we can do conditional compilation in this library based on the
599565
// python interpeter's compilation flags. This is necessary for e.g. matching the right unicode
600566
// and threading interfaces. First check if we're cross compiling, if so, we cannot run the

guide/src/rust_cpython.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This chapter is based on the discussion in [PyO3/pyo3#55](https://github.com/PyO
66

77
## Macros
88

9-
While rust-cpython has a macro based dsl for declaring modules and classes, PyO3 uses proc macros and specialization. PyO3 also doesn't change your struct and functions so you can still use them as normal Rust functions. The disadvantage is that specialization currently only works on nightly.
9+
While rust-cpython has a macro based dsl for declaring modules and classes, PyO3 uses proc macros and specialization. PyO3 also doesn't change your struct and functions so you can still use them as normal Rust functions.
1010

1111
**rust-cpython**
1212

src/conversion.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub trait ToBorrowedObject: ToPyObject {
9898
F: FnOnce(*mut ffi::PyObject) -> R;
9999
}
100100

101+
#[cfg(feature = "nightly")]
101102
impl<T> ToBorrowedObject for T
102103
where
103104
T: ToPyObject,
@@ -115,6 +116,25 @@ where
115116
}
116117
}
117118

119+
#[cfg(not(feature = "nightly"))]
120+
impl<T> ToBorrowedObject for T
121+
where
122+
T: ToPyObject,
123+
{
124+
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
125+
where
126+
F: FnOnce(*mut ffi::PyObject) -> R,
127+
{
128+
let ptr = self.to_object(py).into_ptr();
129+
let result = f(ptr);
130+
unsafe {
131+
ffi::Py_XDECREF(ptr);
132+
}
133+
result
134+
}
135+
}
136+
137+
#[cfg(feature = "nightly")]
118138
impl<T> ToBorrowedObject for T
119139
where
120140
T: ToPyObject + AsPyPointer,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(specialization)]
1+
#![cfg_attr(nightly, feature(specialization))]
22
#![allow(clippy::missing_safety_doc)] // FIXME (#698)
33

44
//! Rust bindings to the Python interpreter.

src/types/sequence.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2017-present PyO3 Project and Contributors
22

3+
#[cfg(feature = "nightly")]
34
use crate::buffer;
45
use crate::err::{self, PyDowncastError, PyErr, PyResult};
56
use crate::exceptions;
@@ -261,6 +262,7 @@ impl PySequence {
261262
macro_rules! array_impls {
262263
($($N:expr),+) => {
263264
$(
265+
#[cfg(feature = "nightly")]
264266
impl<'a, T> FromPyObject<'a> for [T; $N]
265267
where
266268
T: Copy + Default + FromPyObject<'a>,
@@ -272,6 +274,19 @@ macro_rules! array_impls {
272274
}
273275
}
274276

277+
#[cfg(not(feature = "nightly"))]
278+
impl<'a, T> FromPyObject<'a> for [T; $N]
279+
where
280+
T: Copy + Default + FromPyObject<'a>,
281+
{
282+
fn extract(obj: &'a PyAny) -> PyResult<Self> {
283+
let mut array = [T::default(); $N];
284+
extract_sequence_into_slice(obj, &mut array)?;
285+
Ok(array)
286+
}
287+
}
288+
289+
#[cfg(feature = "nightly")]
275290
impl<'source, T> FromPyObject<'source> for [T; $N]
276291
where
277292
for<'a> T: Copy + Default + FromPyObject<'a> + buffer::Element,
@@ -300,6 +315,17 @@ array_impls!(
300315
26, 27, 28, 29, 30, 31, 32
301316
);
302317

318+
#[cfg(not(feature = "nightly"))]
319+
impl<'a, T> FromPyObject<'a> for Vec<T>
320+
where
321+
T: FromPyObject<'a>,
322+
{
323+
fn extract(obj: &'a PyAny) -> PyResult<Self> {
324+
extract_sequence(obj)
325+
}
326+
}
327+
328+
#[cfg(feature = "nightly")]
303329
impl<'a, T> FromPyObject<'a> for Vec<T>
304330
where
305331
T: FromPyObject<'a>,
@@ -309,6 +335,7 @@ where
309335
}
310336
}
311337

338+
#[cfg(feature = "nightly")]
312339
impl<'source, T> FromPyObject<'source> for Vec<T>
313340
where
314341
for<'a> T: FromPyObject<'a> + buffer::Element + Copy,

tests/test_datetime.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![feature(concat_idents)]
1+
#![cfg_attr(nightly, feature(concat_idents))]
22

3+
#[cfg(feature = "nightly")]
34
use pyo3::ffi::*;
45
use pyo3::prelude::*;
56
use pyo3::types::IntoPyDict;
@@ -34,6 +35,7 @@ fn _get_subclasses<'p>(
3435
Ok((obj, sub_obj, sub_sub_obj))
3536
}
3637

38+
#[cfg(feature = "nightly")]
3739
macro_rules! assert_check_exact {
3840
($check_func:ident, $obj: expr) => {
3941
unsafe {
@@ -44,6 +46,7 @@ macro_rules! assert_check_exact {
4446
};
4547
}
4648

49+
#[cfg(feature = "nightly")]
4750
macro_rules! assert_check_only {
4851
($check_func:ident, $obj: expr) => {
4952
unsafe {
@@ -54,6 +57,7 @@ macro_rules! assert_check_only {
5457
};
5558
}
5659

60+
#[cfg(feature = "nightly")]
5761
#[test]
5862
fn test_date_check() {
5963
let gil = Python::acquire_gil();
@@ -65,6 +69,7 @@ fn test_date_check() {
6569
assert_check_only!(PyDate_Check, sub_sub_obj);
6670
}
6771

72+
#[cfg(feature = "nightly")]
6873
#[test]
6974
fn test_time_check() {
7075
let gil = Python::acquire_gil();
@@ -76,6 +81,7 @@ fn test_time_check() {
7681
assert_check_only!(PyTime_Check, sub_sub_obj);
7782
}
7883

84+
#[cfg(feature = "nightly")]
7985
#[test]
8086
fn test_datetime_check() {
8187
let gil = Python::acquire_gil();
@@ -90,6 +96,7 @@ fn test_datetime_check() {
9096
assert_check_only!(PyDateTime_Check, sub_sub_obj);
9197
}
9298

99+
#[cfg(feature = "nightly")]
93100
#[test]
94101
fn test_delta_check() {
95102
let gil = Python::acquire_gil();

0 commit comments

Comments
 (0)