Skip to content

Commit 5a8f503

Browse files
committed
Fix make test
This is a follow-up to #147
1 parent e3b7449 commit 5a8f503

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Cargo.lock
55
build/
66
__pycache__/
77
.cache
8+
.pytest_cache/
9+
dist/
810

911
*.so
1012
*.out

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ log = "0.4"
2323
libc = "0.2"
2424
spin = "0.4.6"
2525
num-traits = "0.2"
26-
pyo3cls = { version = "^0.2.1" }
26+
pyo3cls = { path = "pyo3cls", version = "^0.2.1" }
2727

2828
[build-dependencies]
2929
regex = "0.2"

pyo3cls/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn mod2init(attr: TokenStream, input: TokenStream) -> TokenStream {
3434
let mut ast = syn::parse_item(&source).unwrap();
3535

3636
// Build the output
37-
let init = module::build_py2_module_init(&mut ast, attr.to_string());
37+
let init = module::build_py2_module_init(&mut ast, utils::attr_with_parentheses(attr));
3838

3939
// Return the generated impl as a TokenStream
4040
let mut tokens = Tokens::new();
@@ -53,7 +53,7 @@ pub fn mod3init(attr: TokenStream, input: TokenStream) -> TokenStream {
5353
let mut ast = syn::parse_item(&source).unwrap();
5454

5555
// Build the output
56-
let init = module::build_py3_module_init(&mut ast, attr.to_string());
56+
let init = module::build_py3_module_init(&mut ast, utils::attr_with_parentheses(attr));
5757

5858
// Return the generated impl as a TokenStream
5959
let mut tokens = Tokens::new();
@@ -91,7 +91,7 @@ pub fn class(attr: TokenStream, input: TokenStream) -> TokenStream {
9191
let mut ast = syn::parse_derive_input(&source).unwrap();
9292

9393
// Build the output
94-
let expanded = py_class::build_py_class(&mut ast, attr.to_string());
94+
let expanded = py_class::build_py_class(&mut ast, utils::attr_with_parentheses(attr));
9595

9696
// Return the generated impl as a TokenStream
9797
let mut tokens = Tokens::new();

pyo3cls/src/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use utils;
1010

1111

1212
pub fn build_py3_module_init(ast: &mut syn::Item, attr: String) -> Tokens {
13-
let modname = &attr.to_string()[1..attr.to_string().len()-1].to_string();
13+
let modname = &attr[1..attr.len()-1].to_string();
1414

1515
match ast.node {
1616
syn::ItemKind::Fn(_, _, _, _, _, ref mut block) => {
@@ -86,7 +86,7 @@ pub fn py3_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
8686
}
8787

8888
pub fn build_py2_module_init(ast: &mut syn::Item, attr: String) -> Tokens {
89-
let modname = &attr.to_string()[1..attr.to_string().len()-1].to_string();
89+
let modname = &attr[1..attr.len()-1].to_string();
9090

9191
match ast.node {
9292
syn::ItemKind::Fn(_, _, _, _, _, ref mut block) => {

pyo3cls/src/utils.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
// Copyright (c) 2017-present PyO3 Project and Contributors
22
use syn;
33
use quote::{Tokens, ToTokens};
4+
use proc_macro::TokenStream;
45

56

7+
/// https://github.com/rust-lang/rust/pull/50120 removed the parantheses from
8+
/// the attr TokenStream, so we need to re-add them manually.
9+
///
10+
/// nightly-2018-04-05: ( name=CustomName )
11+
/// nightly-2018-04-28: name=CustomName
12+
pub fn attr_with_parentheses(attr: TokenStream) -> String {
13+
let attr = attr.to_string();
14+
if attr.len() > 0 && !attr.starts_with("(") {
15+
return format!("({})", attr);
16+
} else {
17+
return attr;
18+
}
19+
}
20+
621
pub fn print_err(msg: String, t: Tokens) {
722
println!("Error: {} in '{}'", msg, t.to_string());
823
}

tests/test_module.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn init_mod(py: Python, m: &PyModule) -> PyResult<()> {
3636
}
3737

3838
#[test]
39+
#[cfg(Py_3)]
3940
fn test_module_with_functions() {
4041
let gil = Python::acquire_gil();
4142
let py = gil.python();

0 commit comments

Comments
 (0)