##// END OF EJS Templates
rust-utils: introduce a debug util to print the python stack trace...
Raphaël Gomès -
r43545:97097897 default
parent child Browse files
Show More
@@ -0,0 +1,13
1 use cpython::{PyDict, PyObject, PyResult, PyTuple, Python};
2
3 #[allow(unused)]
4 pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
5 eprintln!("===============================");
6 eprintln!("Printing Python stack from Rust");
7 eprintln!("===============================");
8 let traceback = py.import("traceback")?;
9 let sys = py.import("sys")?;
10 let kwargs = PyDict::new(py);
11 kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
12 traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
13 }
@@ -1,73 +1,74
1 // lib.rs
1 // lib.rs
2 //
2 //
3 // Copyright 2018 Georges Racinet <gracinet@anybox.fr>
3 // Copyright 2018 Georges Racinet <gracinet@anybox.fr>
4 //
4 //
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 //! Python bindings of `hg-core` objects using the `cpython` crate.
8 //! Python bindings of `hg-core` objects using the `cpython` crate.
9 //! Once compiled, the resulting single shared library object can be placed in
9 //! Once compiled, the resulting single shared library object can be placed in
10 //! the `mercurial` package directly as `rustext.so` or `rustext.dll`.
10 //! the `mercurial` package directly as `rustext.so` or `rustext.dll`.
11 //! It holds several modules, so that from the point of view of Python,
11 //! It holds several modules, so that from the point of view of Python,
12 //! it behaves as the `cext` package.
12 //! it behaves as the `cext` package.
13 //!
13 //!
14 //! Example:
14 //! Example:
15 //!
15 //!
16 //! ```text
16 //! ```text
17 //! >>> from mercurial.rustext import ancestor
17 //! >>> from mercurial.rustext import ancestor
18 //! >>> ancestor.__doc__
18 //! >>> ancestor.__doc__
19 //! 'Generic DAG ancestor algorithms - Rust implementation'
19 //! 'Generic DAG ancestor algorithms - Rust implementation'
20 //! ```
20 //! ```
21
21
22 /// This crate uses nested private macros, `extern crate` is still needed in
22 /// This crate uses nested private macros, `extern crate` is still needed in
23 /// 2018 edition.
23 /// 2018 edition.
24 #[macro_use]
24 #[macro_use]
25 extern crate cpython;
25 extern crate cpython;
26
26
27 pub mod ancestors;
27 pub mod ancestors;
28 mod cindex;
28 mod cindex;
29 mod conversion;
29 mod conversion;
30 #[macro_use]
30 #[macro_use]
31 pub mod ref_sharing;
31 pub mod ref_sharing;
32 pub mod dagops;
32 pub mod dagops;
33 pub mod dirstate;
33 pub mod dirstate;
34 pub mod discovery;
34 pub mod discovery;
35 pub mod exceptions;
35 pub mod exceptions;
36 pub mod filepatterns;
36 pub mod filepatterns;
37 pub mod parsers;
37 pub mod parsers;
38 pub mod utils;
38
39
39 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
40 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
40 m.add(
41 m.add(
41 py,
42 py,
42 "__doc__",
43 "__doc__",
43 "Mercurial core concepts - Rust implementation",
44 "Mercurial core concepts - Rust implementation",
44 )?;
45 )?;
45
46
46 let dotted_name: String = m.get(py, "__name__")?.extract(py)?;
47 let dotted_name: String = m.get(py, "__name__")?.extract(py)?;
47 m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?;
48 m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?;
48 m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?;
49 m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?;
49 m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?;
50 m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?;
50 m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?;
51 m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?;
51 m.add(
52 m.add(
52 py,
53 py,
53 "filepatterns",
54 "filepatterns",
54 filepatterns::init_module(py, &dotted_name)?,
55 filepatterns::init_module(py, &dotted_name)?,
55 )?;
56 )?;
56 m.add(
57 m.add(
57 py,
58 py,
58 "parsers",
59 "parsers",
59 parsers::init_parsers_module(py, &dotted_name)?,
60 parsers::init_parsers_module(py, &dotted_name)?,
60 )?;
61 )?;
61 m.add(py, "GraphError", py.get_type::<exceptions::GraphError>())?;
62 m.add(py, "GraphError", py.get_type::<exceptions::GraphError>())?;
62 m.add(
63 m.add(
63 py,
64 py,
64 "PatternFileError",
65 "PatternFileError",
65 py.get_type::<exceptions::PatternFileError>(),
66 py.get_type::<exceptions::PatternFileError>(),
66 )?;
67 )?;
67 m.add(
68 m.add(
68 py,
69 py,
69 "PatternError",
70 "PatternError",
70 py.get_type::<exceptions::PatternError>(),
71 py.get_type::<exceptions::PatternError>(),
71 )?;
72 )?;
72 Ok(())
73 Ok(())
73 });
74 });
General Comments 0
You need to be logged in to leave comments. Login now