Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit b7c09ca

Browse files
committed
Skeleton for python_compiler using cpython
1 parent a750171 commit b7c09ca

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

python_compiler/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "python_compiler"
3+
version = "0.1.0"
4+
authors = ["Shing Lyu <shing.lyu@gmail.com>"]
5+
6+
[dependencies]
7+
cpython = { git = "https://github.com/dgrunwald/rust-cpython.git" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern crate python_compiler;
2+
3+
use python_compiler::python_compiler::compile;
4+
5+
fn main() {
6+
println!("{:?}", compile());
7+
}

python_compiler/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern crate cpython;
2+
3+
pub mod python_compiler;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate cpython;
2+
3+
use self::cpython::Python;
4+
use self::cpython::ObjectProtocol; //for call method
5+
6+
pub fn compile() -> String{
7+
let gil = Python::acquire_gil();
8+
let py = gil.python();
9+
10+
let sys = py.import("sys").unwrap();
11+
let version: String = sys.get(py, "version").unwrap().extract(py).unwrap();
12+
13+
let os = py.import("os").unwrap();
14+
let getenv = os.get(py, "getenv").unwrap();
15+
let user: String = getenv.call(py, ("USER",), None).unwrap().extract(py).unwrap();
16+
17+
version
18+
19+
}

0 commit comments

Comments
 (0)