Skip to content

Commit

Permalink
feat: wrap Evaluator::{enable_profile, coverage}
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n committed Jul 3, 2024
1 parent 0f257bf commit 28a110d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/eval.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use anyhow::anyhow;
use pyo3::exceptions::PyRuntimeError;
use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyTuple};
use starlark::codemap::ResolvedFileSpan;
use starlark::environment::{FrozenModule, Module};
use starlark::errors::Frame;
use starlark::eval::{CallStack, Evaluator, FileLoader, ProfileMode};
use starlark::PrintHandler;

use crate::codemap::PyFileSpan;
use crate::codemap::{PyFileSpan, PyResolvedFileSpan};
use crate::environment::{PyFrozenModule, PyGlobals, PyModule};
use crate::errors::PyFrame;
use crate::syntax::PyAstModule;
Expand Down Expand Up @@ -134,10 +135,22 @@ impl PyEvaluator {
Ok(())
}

// TODO: enable_profile
fn enable_profile(&mut self, py: Python, mode: PyProfileMode) -> PyResult<()> {
self.ensure_module_available(py)?;
self.0.enable_profile(&mode.into())?;
Ok(())
}

// TODO: write_profile
// TODO: gen_profile
// TODO: coverage

fn coverage(&self, py: Python) -> PyResult<HashSet<PyResolvedFileSpan>> {
self.ensure_module_available(py)?;
Ok(self
.0
.coverage()
.map(|x| x.into_iter().map(ResolvedFileSpan::into).collect())?)
}

fn enable_terminal_breakpoint_console(&mut self, py: Python) -> PyResult<()> {
self.ensure_module_available(py)?;
Expand Down
4 changes: 2 additions & 2 deletions xingque.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ class Evaluator:
def verbose_gc(self) -> None: ...
def enable_static_typechecking(self, enable: bool) -> None: ...
def set_loader(self, loader: _FileLoader) -> None: ...
# TODO: enable_profile
def enable_profile(self, mode: ProfileMode) -> None: ...
# TODO: write_profile
# TODO: gen_profile
# TODO: coverage
def coverage(self) -> set[ResolvedFileSpan]: ...
def enable_terminal_breakpoint_console(self) -> None: ...
def call_stack(self) -> CallStack: ...
def call_stack_top_frame(self) -> Frame | None: ...
Expand Down

0 comments on commit 28a110d

Please sign in to comment.