mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-07-18 09:55:02 +00:00
add packaging module to djls-python (#2)
This commit is contained in:
parent
931c0bc9fb
commit
4c67f6a90d
3 changed files with 183 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::packaging::{Packages, PackagingError};
|
||||
use pyo3::prelude::*;
|
||||
use serde::Deserialize;
|
||||
use std::fmt;
|
||||
|
@ -135,6 +136,7 @@ pub struct Interpreter {
|
|||
sys_base_prefix: PathBuf,
|
||||
sys_executable: PathBuf,
|
||||
sys_path: Vec<PathBuf>,
|
||||
packages: Packages,
|
||||
}
|
||||
|
||||
impl Interpreter {
|
||||
|
@ -145,6 +147,7 @@ impl Interpreter {
|
|||
sys_base_prefix: PathBuf,
|
||||
sys_executable: PathBuf,
|
||||
sys_path: Vec<PathBuf>,
|
||||
packages: Packages,
|
||||
) -> Self {
|
||||
Self {
|
||||
version_info,
|
||||
|
@ -153,6 +156,7 @@ impl Interpreter {
|
|||
sys_base_prefix,
|
||||
sys_executable,
|
||||
sys_path,
|
||||
packages,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,6 +184,10 @@ impl Interpreter {
|
|||
&self.sys_path
|
||||
}
|
||||
|
||||
pub fn packages(&self) -> &Packages {
|
||||
&self.packages
|
||||
}
|
||||
|
||||
pub fn for_build(py: Python) -> PyResult<Self> {
|
||||
let sys = py.import("sys")?;
|
||||
|
||||
|
@ -194,6 +202,7 @@ impl Interpreter {
|
|||
.into_iter()
|
||||
.map(PathBuf::from)
|
||||
.collect(),
|
||||
Packages::from_python(py)?,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -228,6 +237,7 @@ print(json.dumps({
|
|||
.iter()
|
||||
.map(|p| PathBuf::from(p.as_str().unwrap()))
|
||||
.collect(),
|
||||
Packages::from_executable(executable)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -243,7 +253,9 @@ impl fmt::Display for Interpreter {
|
|||
writeln!(f, "{}", path.display())?;
|
||||
}
|
||||
writeln!(f, "Sysconfig Paths:")?;
|
||||
write!(f, "{}", self.sysconfig_paths)
|
||||
write!(f, "{}", self.sysconfig_paths)?;
|
||||
writeln!(f, "\nInstalled Packages:")?;
|
||||
write!(f, "{}", self.packages)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,6 +270,9 @@ pub enum PythonError {
|
|||
#[error("JSON parsing error: {0}")]
|
||||
Json(#[from] serde_json::Error),
|
||||
|
||||
#[error("Packaging error: {0}")]
|
||||
Packaging(#[from] PackagingError),
|
||||
|
||||
#[error("Integer parsing error: {0}")]
|
||||
Parse(#[from] std::num::ParseIntError),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue