Skip to content

Commit f51af16

Browse files
committed
chore: update to edition 2024
1 parent 52f9b87 commit f51af16

File tree

8 files changed

+106
-37
lines changed

8 files changed

+106
-37
lines changed

src/common/pyproject.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
3+
use std::path::PathBuf;
34

45
#[derive(Serialize, Deserialize, Debug, Clone)]
56
pub struct PyProjectToml {
6-
tool: Option<Tool>,
7+
pub tool: Option<Tool>,
78
}
89

910
#[derive(Serialize, Deserialize, Debug, Clone)]
1011
#[serde(rename_all = "kebab-case")]
1112
pub struct Tool {
12-
uv: Option<ToolUv>,
13-
poetry: Option<ToolPoetry>,
14-
poe: Option<PeoTasks>,
13+
#[serde(rename = "rye")]
14+
pub uv: Option<ToolUv>,
15+
pub poetry: Option<ToolPoetry>,
16+
pub poe: Option<PeoTasks>,
1517
}
1618

1719
#[derive(Serialize, Deserialize, Debug, Clone)]
1820
#[serde(rename_all = "kebab-case")]
1921
pub struct ToolUv {
20-
scripts: Option<HashMap<String, toml::Value>>,
22+
pub scripts: Option<HashMap<String, toml::Value>>,
2123
}
2224

2325
#[derive(Serialize, Deserialize, Debug, Clone)]
2426
#[serde(rename_all = "kebab-case")]
2527
pub struct PeoTasks {
26-
tasks: Option<HashMap<String, toml::Value>>,
28+
pub tasks: Option<HashMap<String, toml::Value>>,
2729
}
2830

2931
impl ToolUv {
@@ -148,6 +150,17 @@ impl PyProjectToml {
148150
.and_then(|uv| uv.get_scripts().clone())
149151
}
150152

153+
pub fn get_uv_script(&self, script_name: &str) -> Option<toml::Value> {
154+
if let Some(tool) = self.tool.as_ref()
155+
&& let Some(uv) = tool.uv.as_ref()
156+
&& let Some(scripts) = uv.scripts.as_ref()
157+
&& let Some(script) = scripts.get(script_name) {
158+
Some(script.clone())
159+
} else {
160+
None
161+
}
162+
}
163+
151164
pub fn get_poetry_scripts(&self) -> Option<HashMap<String, String>> {
152165
self.tool
153166
.as_ref()
@@ -161,6 +174,14 @@ impl PyProjectToml {
161174
.and_then(|tool| tool.poe.as_ref())
162175
.and_then(|peo_tasks| peo_tasks.get_tasks().clone())
163176
}
177+
178+
pub fn venv_bin_path(&self) -> PathBuf {
179+
std::env::current_dir().unwrap().join(".venv").join("bin")
180+
}
181+
182+
pub fn venv_path(&self) -> PathBuf {
183+
std::env::current_dir().unwrap().join(".venv")
184+
}
164185
}
165186

166187
pub fn get_uv_tool_path(tool_name: &str) -> Option<String> {

src/main.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ fn reset_path_env() {
228228
);
229229
}
230230
}
231-
env::set_var("PATH", new_path);
231+
unsafe {
232+
env::set_var("PATH", new_path);
233+
}
232234
}
233235

234236
fn list_tasks(task_runner: Option<&String>) {
@@ -421,7 +423,10 @@ fn diagnose() {
421423
if runners::makefiletoml::is_available() {
422424
if !runners::makefiletoml::is_command_available() {
423425
problems_count += 1;
424-
println!("{} cargo-make(https://github.com/sagiegurari/cargo-make) command not available for Makefile.toml", "Warning:".bold().yellow());
426+
println!(
427+
"{} cargo-make(https://github.com/sagiegurari/cargo-make) command not available for Makefile.toml",
428+
"Warning:".bold().yellow()
429+
);
425430
}
426431
}
427432
if runners::bun_shell::is_available() {
@@ -472,7 +477,10 @@ fn diagnose() {
472477
if runners::poe::is_available() {
473478
if !runners::poe::is_command_available() {
474479
problems_count += 1;
475-
println!("{} poe(https://github.com/nat-n/poethepoet) command not available for pyproject.toml, please use `uv tool install --python 3.11 poethepoet` to install.", "Warning:".bold().yellow());
480+
println!(
481+
"{} poe(https://github.com/nat-n/poethepoet) command not available for pyproject.toml, please use `uv tool install --python 3.11 poethepoet` to install.",
482+
"Warning:".bold().yellow()
483+
);
476484
}
477485
}
478486
if runners::argcfile::is_available() {
@@ -520,15 +528,22 @@ fn diagnose() {
520528
.join("plugins.gradle")
521529
.exists()
522530
{
523-
println!("{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#gradle",
524-
"Suggestion:".bold().yellow(), "plugins.gradle".bold().blue(), "dependencyUpdates".bold().blue());
531+
println!(
532+
"{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#gradle",
533+
"Suggestion:".bold().yellow(),
534+
"plugins.gradle".bold().blue(),
535+
"dependencyUpdates".bold().blue()
536+
);
525537
}
526538
}
527539
}
528540
if managers::amper::is_available() {
529541
if !managers::amper::is_command_available() {
530542
problems_count += 1;
531-
println!("{} amper(https://github.com/JetBrains/amper) command not available for module.yaml", "Warning:".bold().yellow());
543+
println!(
544+
"{} amper(https://github.com/JetBrains/amper) command not available for module.yaml",
545+
"Warning:".bold().yellow()
546+
);
532547
}
533548
}
534549
if managers::sbt::is_available() {
@@ -548,8 +563,12 @@ fn diagnose() {
548563
.join("plugins.sbt")
549564
.exists()
550565
{
551-
println!("{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#sbt",
552-
"Suggestion:".bold().yellow(), "plugins.sbt".bold().blue(), "dependencyUpdates".bold().blue());
566+
println!(
567+
"{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#sbt",
568+
"Suggestion:".bold().yellow(),
569+
"plugins.sbt".bold().blue(),
570+
"dependencyUpdates".bold().blue()
571+
);
553572
}
554573
}
555574
}
@@ -568,8 +587,12 @@ fn diagnose() {
568587
.join("profiles.clj")
569588
.exists()
570589
{
571-
println!("{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#lein",
572-
"Suggestion:".bold().yellow(), "profiles.clj".bold().blue(), "outdated".bold().blue());
590+
println!(
591+
"{} global {} not available for {} task, please check https://github.com/linux-china/task-keeper#lein",
592+
"Suggestion:".bold().yellow(),
593+
"profiles.clj".bold().blue(),
594+
"outdated".bold().blue()
595+
);
573596
}
574597
}
575598
}
@@ -621,7 +644,10 @@ fn diagnose() {
621644
if managers::cmakeconan::is_available() {
622645
if !managers::cmakeconan::is_command_available() {
623646
problems_count += 1;
624-
println!("{} cmake and conan(https://github.com/conan-io/cmake-conan/) command not available for CMakeLists.txt and conanfile.txt", "Warning:".bold().yellow());
647+
println!(
648+
"{} cmake and conan(https://github.com/conan-io/cmake-conan/) command not available for CMakeLists.txt and conanfile.txt",
649+
"Warning:".bold().yellow()
650+
);
625651
}
626652
}
627653
if managers::meson::is_available() {

src/polyglot/java.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ pub fn init_env() {
9090

9191
fn reset_java_home(java_home_path: &PathBuf) {
9292
let java_home = java_home_path.to_string_lossy().to_string();
93-
env::set_var("JAVA_HOME", &java_home);
93+
unsafe {
94+
env::set_var("JAVA_HOME", &java_home);
95+
}
9496
if java_home.contains("-grl") {
95-
env::set_var("GRAALVM_HOME", &java_home);
97+
unsafe {
98+
env::set_var("GRAALVM_HOME", &java_home);
99+
}
96100
}
97101
if let Ok(path) = env::var("PATH") {
98102
let java_bin_path = java_home_path.join("bin").to_string_lossy().to_string();
99-
env::set_var("PATH", format!("{}{}{}", java_bin_path, PATH_SEPARATOR, path));
103+
unsafe {
104+
env::set_var("PATH", format!("{}{}{}", java_bin_path, PATH_SEPARATOR, path));
105+
}
100106
}
101107
}
102108

src/polyglot/node.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::polyglot::PATH_SEPARATOR;
12
use std::env;
23
use std::path::PathBuf;
3-
use crate::polyglot::PATH_SEPARATOR;
44

55
pub fn is_available() -> bool {
66
env::current_dir()
@@ -16,16 +16,12 @@ pub fn find_sdk_home() -> Option<PathBuf> {
1616
if let Ok(text) = get_default_version() {
1717
let node_version = text.trim();
1818
// find version from nvm
19-
let node_candidates_path = dirs::home_dir()
20-
.map(|dir| {
21-
dir.join(".nvm").join("versions").join("node")
22-
});
19+
let node_candidates_path =
20+
dirs::home_dir().map(|dir| dir.join(".nvm").join("versions").join("node"));
2321
let mut node_home_path = find_node_home(node_version, &node_candidates_path);
2422
if node_home_path.is_none() {
2523
let node_candidates_path = dirs::home_dir()
26-
.map(|dir| {
27-
dir.join(".volta").join("tools").join("image").join("node")
28-
});
24+
.map(|dir| dir.join(".volta").join("tools").join("image").join("node"));
2925
node_home_path = find_node_home(node_version, &node_candidates_path);
3026
}
3127
return node_home_path;
@@ -62,10 +58,17 @@ fn find_node_home(node_version: &str, node_candidates_path: &Option<PathBuf>) ->
6258

6359
fn reset_node_home(node_home_path: &PathBuf) {
6460
let node_home = node_home_path.to_string_lossy().to_string();
65-
env::set_var("NODE_HOME", &node_home);
61+
unsafe {
62+
env::set_var("NODE_HOME", &node_home);
63+
}
6664
if let Ok(path) = env::var("PATH") {
6765
let node_bin_path = node_home_path.join("bin").to_string_lossy().to_string();
68-
env::set_var("PATH", format!("{}{}{}", node_bin_path, PATH_SEPARATOR, path));
66+
unsafe {
67+
env::set_var(
68+
"PATH",
69+
format!("{}{}{}", node_bin_path, PATH_SEPARATOR, path),
70+
);
71+
}
6972
}
7073
}
7174

src/polyglot/python.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ pub fn init_env() {
5858
fn reset_python_home(python_home_path: &PathBuf) {
5959
if let Ok(path) = env::var("PATH") {
6060
let node_bin_path = python_home_path.join("bin").to_string_lossy().to_string();
61-
env::set_var(
62-
"PATH",
63-
format!("{}{}{}", node_bin_path, PATH_SEPARATOR, path),
64-
);
61+
unsafe {
62+
env::set_var(
63+
"PATH",
64+
format!("{}{}{}", node_bin_path, PATH_SEPARATOR, path),
65+
);
66+
}
6567
}
6668
}
6769

src/polyglot/sdkman.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ pub fn init_env() {
2121
let candidate_home_path = candidates_home.join(key).join(value);
2222
if candidate_home_path.exists() {
2323
// set candidate home env variable
24-
env::set_var(&candidate_home_name, &candidate_home_path.to_string_lossy().to_string());
24+
unsafe {
25+
env::set_var(&candidate_home_name, &candidate_home_path.to_string_lossy().to_string());
26+
}
2527
// Add candidate bin path to PATH env variable on first position
2628
let candidate_bin_path = candidates_home.join(key).join(value).join("bin");
2729
let bin_path = if candidate_bin_path.exists() {
@@ -30,7 +32,9 @@ pub fn init_env() {
3032
candidate_home_path.to_string_lossy().to_string()
3133
};
3234
if let Ok(path) = env::var("PATH") {
33-
env::set_var("PATH", format!("{}{}{}", bin_path, PATH_SEPARATOR, path));
35+
unsafe {
36+
env::set_var("PATH", format!("{}{}{}", bin_path, PATH_SEPARATOR, path));
37+
}
3438
}
3539
}
3640
}

src/runners/denojson.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub fn run_task(
5252
args.push("task");
5353
args.push(task);
5454
args.extend(task_args);
55-
std::env::set_var("DENO_FUTURE", "1");
55+
unsafe {
56+
std::env::set_var("DENO_FUTURE", "1");
57+
}
5658
run_command("deno", &args, verbose)
5759
}
5860

src/runners/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod zed;
2626
pub mod jakefile;
2727
pub mod gulpfile;
2828
pub mod gruntfile;
29+
pub mod uv_scripts;
2930

3031
use crate::command_utils::CommandOutput;
3132
use crate::errors::KeeperError;
@@ -60,6 +61,7 @@ pub const RUNNERS: &'static [&'static str] = &[
6061
"xtask",
6162
"xtask-go",
6263
"nur",
64+
"uvs"
6365
];
6466

6567
pub fn run_task(
@@ -100,6 +102,7 @@ pub fn run_task(
100102
"poetry" => poetry::run_task(task_name, task_args, global_args, verbose),
101103
"argc" => argcfile::run_task(task_name, task_args, global_args, verbose),
102104
"nur" => nurfile::run_task(task_name, task_args, global_args, verbose),
105+
"uvs" => uv_scripts::run_task(task_name, task_args, global_args, verbose),
103106
"bun-shell" => bun_shell::run_task(task_name, task_args, global_args, verbose),
104107
"xtask" => xtask::run_task(task_name, task_args, global_args, verbose),
105108
"xtask-go" => xtask_go::run_task(task_name, task_args, global_args, verbose),
@@ -137,6 +140,7 @@ pub fn get_runner_file_name(runner: &str) -> &'static str {
137140
"bun-shell" => "Taskfile.ts",
138141
"argc" => "Argcfile.sh",
139142
"nur" => "nurfile",
143+
"uvs" => "pyproject.toml",
140144
"xtask" => "xtask/",
141145
"xtask-go" => "xtask/main.go",
142146
_ => "unknown",
@@ -170,6 +174,7 @@ pub fn get_runner_web_url(runner: &str) -> &'static str {
170174
"bun-shell" => "https://bun.sh/docs/runtime/shell",
171175
"argc" => "https://github.com/sigoden/argc",
172176
"nur" => "https://github.com/ddanier/nur",
177+
"uvs" => "https://rye.astral.sh/guide/pyproject/#toolryescripts",
173178
"xtask" => "https://github.com/matklad/cargo-xtask",
174179
"xtask-go" => "https://github.com/linux-china/xtask-go-demo",
175180
_ => "unknown",

0 commit comments

Comments
 (0)