Skip to content

Commit f26f733

Browse files
committed
[IMP] server: python path as arg in cli mode
1 parent 73bfbc0 commit f26f733

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

server/src/cli_backend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::{error, info};
55

66
use crate::core::config::ConfigEntry;
77
use crate::threads::SessionInfo;
8-
use crate::utils::PathSanitizer;
8+
use crate::utils::{get_python_command, PathSanitizer};
99
use crate::args::Cli;
1010
use std::io::Write;
1111
use std::path::PathBuf;
@@ -60,6 +60,7 @@ impl CliBackend {
6060
config.no_typeshed = self.cli.no_typeshed;
6161
config.additional_stubs = self.cli.stubs.clone().unwrap_or(vec![]).into_iter().map(|p| fs::canonicalize(p).unwrap_or_else(|_| PathBuf::from(S!(""))).sanitize()).collect();
6262
config.stdlib = self.cli.stdlib.clone().map(|p| fs::canonicalize(p).unwrap_or_else(|_| PathBuf::from(S!(""))).sanitize()).unwrap_or(S!(""));
63+
config.python_path = self.cli.python.clone().unwrap_or(get_python_command().unwrap_or(S!("")));
6364
SyncOdoo::init(&mut session, config);
6465

6566
let output_path = self.cli.output.clone().unwrap_or(S!("output.json"));

server/src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ macro_rules! Sy {
2525
};
2626
}
2727

28+
pub fn get_python_command() -> Option<String> {
29+
for cmd in &["python3", "python"] {
30+
if let Ok(output) = Command::new(cmd).arg("--version").output() {
31+
if output.status.success() {
32+
return Some(S!(*cmd));
33+
}
34+
}
35+
}
36+
None
37+
}
38+
2839
#[cfg(target_os = "windows")]
2940
pub fn is_file_cs(path: String) -> bool {
3041
let mut p = Path::new(&path);

server/tests/setup/setup.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@ use std::path::PathBuf;
66

77

88
use lsp_types::TextDocumentContentChangeEvent;
9+
use odoo_ls_server::utils::get_python_command;
910
use odoo_ls_server::{core::{config::{ConfigEntry, DiagMissingImportsMode}, entry_point::EntryPointMgr, odoo::SyncOdoo}, threads::SessionInfo, utils::PathSanitizer as _};
1011

1112
use odoo_ls_server::S;
1213
use tracing::{info, level_filters::LevelFilter};
1314
use tracing_appender::rolling::RollingFileAppender;
1415
use tracing_subscriber::{fmt, layer::SubscriberExt, FmtSubscriber};
1516

16-
fn get_python_command() -> Option<String> {
17-
for cmd in &["python3", "python"] {
18-
if let Ok(output) = Command::new(cmd).arg("--version").output() {
19-
if output.status.success() {
20-
return Some(S!(*cmd));
21-
}
22-
}
23-
}
24-
None
25-
}
26-
2717
pub fn setup_server(with_odoo: bool) -> SyncOdoo {
2818

2919
let file_appender = RollingFileAppender::builder()

0 commit comments

Comments
 (0)