initrepo: add python binding for Rust repo

Summary: Adds a Python binding for the Rust `repo` crate. For now it only exposes the static `Repo::init` method.

Reviewed By: DurhamG

Differential Revision: D33796094

fbshipit-source-id: 9cf49bcdd24bbabead79902e64a49ec8dc6fac55
This commit is contained in:
Saul Gutierrez 2022-02-02 17:26:10 -08:00 committed by Facebook GitHub Bot
parent 6c9f70da66
commit 56742d0027
4 changed files with 48 additions and 0 deletions

View File

@ -53,6 +53,7 @@ pyprogress = { path = "modules/pyprogress" }
pyrefencode = { path = "modules/pyrefencode" }
pyregex = { path = "modules/pyregex" }
pyrenderdag = { path = "modules/pyrenderdag" }
pyrepo = { path = "modules/pyrepo" }
pyrevisionstore = { path = "modules/pyrevisionstore" }
pyrevlogindex = { path = "modules/pyrevlogindex" }
pysptui = { path = "modules/pysptui" }

View File

@ -0,0 +1,15 @@
[package]
name = "pyrepo"
version = "0.1.0"
edition = "2021"
[dependencies]
cpython_ext = { path = "../../../../lib/cpython-ext", default-features = false }
cpython = { version = "0.7", default-features = false }
repo = { path = "../../../../lib/repo" }
pyconfigparser = { path = "../pyconfigparser" }
[features]
python2 = ["cpython/python27-sys", "cpython_ext/python2"]
python3 = ["cpython/python3-sys", "cpython_ext/python3"]

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use cpython::*;
use cpython_ext::error::ResultPyErrExt;
use cpython_ext::PyNone;
use cpython_ext::PyPathBuf;
use pyconfigparser::config;
extern crate repo as rsrepo;
pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
let name = [package, "repo"].join(".");
let m = PyModule::new(py, &name)?;
m.add_class::<repo>(py)?;
Ok(m)
}
py_class!(pub class repo |py| {
@staticmethod
def initialize(path: PyPathBuf, config: &config) -> PyResult<PyNone> {
let mut config = config.get_cfg(py);
let repopath = path.as_path();
rsrepo::repo::Repo::init(repopath, &mut config).map_pyerr(py)?;
Ok(PyNone)
}
});

View File

@ -53,6 +53,7 @@ pub(crate) fn populate_module(py: Python<'_>, module: &PyModule) -> PyResult<PyN
m.add(py, "refencode", pyrefencode::init_module(py, &name)?)?;
m.add(py, "regex", pyregex::init_module(py, &name)?)?;
m.add(py, "renderdag", pyrenderdag::init_module(py, &name)?)?;
m.add(py, "repo", pyrepo::init_module(py, &name)?)?;
m.add(
py,
"revisionstore",