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