Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/filepatterns.rs @ 42957:7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Differential Revision: https://phab.mercurial-scm.org/D6774
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Sun, 01 Sep 2019 20:53:14 +0200 |
parents | ce6797ef6eab |
children | dc4e74d0ef96 |
rev | line source |
---|---|
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
1 // filepatterns.rs |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
2 // |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
3 // Copyright 2019, Georges Racinet <gracinet@anybox.fr>, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
4 // Raphaël Gomès <rgomes@octobus.net> |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
5 // |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
6 // This software may be used and distributed according to the terms of the |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
7 // GNU General Public License version 2 or any later version. |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
8 |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
9 //! Bindings for the `hg::filepatterns` module provided by the |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
10 //! `hg-core` crate. From Python, this will be seen as `rustext.filepatterns` |
42841
ce6797ef6eab
rust: apply more formatting fixes
Yuya Nishihara <yuya@tcha.org>
parents:
42634
diff
changeset
|
11 //! and can be used as replacement for the the pure `filepatterns` Python |
ce6797ef6eab
rust: apply more formatting fixes
Yuya Nishihara <yuya@tcha.org>
parents:
42634
diff
changeset
|
12 //! module. |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41187
diff
changeset
|
13 //! |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42437
diff
changeset
|
14 use crate::exceptions::{PatternError, PatternFileError}; |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
15 use cpython::{ |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
16 PyBytes, PyDict, PyModule, PyObject, PyResult, PyString, PyTuple, Python, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
17 ToPyObject, |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
18 }; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
19 use hg::{ |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
20 build_single_regex, read_pattern_file, utils::files::get_path_from_bytes, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
21 LineNumber, PatternTuple, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
22 }; |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
23 use std::path::PathBuf; |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
24 |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
25 /// Rust does not like functions with different return signatures. |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
26 /// The 3-tuple version is always returned by the hg-core function, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
27 /// the (potential) conversion is handled at this level since it is not likely |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
28 /// to have any measurable impact on performance. |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
29 /// |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
30 /// The Python implementation passes a function reference for `warn` instead |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
31 /// of a boolean that is used to emit warnings while parsing. The Rust |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
32 /// implementation chooses to accumulate the warnings and propagate them to |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
33 /// Python upon completion. See the `readpatternfile` function in `match.py` |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
34 /// for more details. |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
35 fn read_pattern_file_wrapper( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
36 py: Python, |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
37 file_path: PyObject, |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
38 warn: bool, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
39 source_info: bool, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
40 ) -> PyResult<PyTuple> { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
41 let bytes = file_path.extract::<PyBytes>(py)?; |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
42 let path = get_path_from_bytes(bytes.data(py)); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
43 match read_pattern_file(path, warn) { |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
44 Ok((patterns, warnings)) => { |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
45 if source_info { |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
46 let itemgetter = |x: &PatternTuple| { |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
47 (PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2)) |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
48 }; |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
49 let results: Vec<(PyBytes, LineNumber, PyBytes)> = |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
50 patterns.iter().map(itemgetter).collect(); |
42634
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
51 return Ok((results, warnings_to_py_bytes(py, &warnings)) |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
52 .to_py_object(py)); |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
53 } |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
54 let itemgetter = |x: &PatternTuple| PyBytes::new(py, &x.0); |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
55 let results: Vec<PyBytes> = |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
56 patterns.iter().map(itemgetter).collect(); |
42634
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
57 Ok( |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
58 (results, warnings_to_py_bytes(py, &warnings)) |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
59 .to_py_object(py), |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
60 ) |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
61 } |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
62 Err(e) => Err(PatternFileError::pynew(py, e)), |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
63 } |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
64 } |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
65 |
42634
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
66 fn warnings_to_py_bytes( |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
67 py: Python, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
68 warnings: &[(PathBuf, Vec<u8>)], |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
69 ) -> Vec<(PyString, PyBytes)> { |
42634
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
70 warnings |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
71 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
72 .map(|(path, syn)| { |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
73 ( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
74 PyString::new(py, &path.to_string_lossy()), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
75 PyBytes::new(py, syn), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
76 ) |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42841
diff
changeset
|
77 }) |
42634
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
78 .collect() |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
79 } |
0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Yuya Nishihara <yuya@tcha.org>
parents:
42609
diff
changeset
|
80 |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
81 fn build_single_regex_wrapper( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
82 py: Python, |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
83 kind: PyObject, |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
84 pat: PyObject, |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
85 globsuffix: PyObject, |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
86 ) -> PyResult<PyBytes> { |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
87 match build_single_regex( |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
88 kind.extract::<PyBytes>(py)?.data(py), |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
89 pat.extract::<PyBytes>(py)?.data(py), |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
90 globsuffix.extract::<PyBytes>(py)?.data(py), |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
91 ) { |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
92 Ok(regex) => Ok(PyBytes::new(py, ®ex)), |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
93 Err(e) => Err(PatternError::pynew(py, e)), |
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
94 } |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
95 } |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41187
diff
changeset
|
96 |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
97 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
98 let dotted_name = &format!("{}.filepatterns", package); |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
99 let m = PyModule::new(py, dotted_name)?; |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41187
diff
changeset
|
100 |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
101 m.add(py, "__package__", package)?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
102 m.add( |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
103 py, |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
104 "__doc__", |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
105 "Patterns files parsing - Rust implementation", |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
106 )?; |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
107 m.add( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
108 py, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
109 "build_single_regex", |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
110 py_fn!( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
111 py, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
112 build_single_regex_wrapper( |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
113 kind: PyObject, |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
114 pat: PyObject, |
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
115 globsuffix: PyObject |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
116 ) |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
117 ), |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
118 )?; |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
119 m.add( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
120 py, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
121 "read_pattern_file", |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
122 py_fn!( |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
123 py, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
124 read_pattern_file_wrapper( |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
125 file_path: PyObject, |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
126 warn: bool, |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
127 source_info: bool |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
128 ) |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
129 ), |
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
130 )?; |
42437
9609430d3625
rust-filepatterns: use bytes instead of String
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42328
diff
changeset
|
131 m.add(py, "PatternError", py.get_type::<PatternError>())?; |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
132 let sys = PyModule::import(py, "sys")?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
133 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
134 sys_modules.set_item(py, dotted_name, &m)?; |
42328
94f3a73b6672
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
41693
diff
changeset
|
135 |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
136 Ok(m) |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
137 } |