Skip to content

Commit f14a0bb

Browse files
authored
fix: Audit 02/10 (#1825)
* Fix scaffold. * Fix python. * Fix uv. * Bump versions.
1 parent a956c90 commit f14a0bb

File tree

7 files changed

+90
-17
lines changed

7 files changed

+90
-17
lines changed

Diff for: .yarn/versions/1c174b42.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
releases:
2+
"@moonrepo/cli": patch
3+
"@moonrepo/core-linux-arm64-gnu": patch
4+
"@moonrepo/core-linux-arm64-musl": patch
5+
"@moonrepo/core-linux-x64-gnu": patch
6+
"@moonrepo/core-linux-x64-musl": patch
7+
"@moonrepo/core-macos-arm64": patch
8+
"@moonrepo/core-macos-x64": patch
9+
"@moonrepo/core-windows-x64-msvc": patch

Diff for: CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
#### 🐞 Fixes
6+
7+
- Fixed an issue where `moon setup` wouldn't load configuration.
8+
- Fixed an issue where `moon docker scaffold` would unexpectedly install the toolchain languages.
9+
- Fixed an issue where `moon docker scaffold` would not copy `uv.toml` and `uv.lock` files.
10+
- Fixed an issue where changing `python.version` wouldn't regenerate the Python virtual environment.
11+
312
## 1.32.2
413

514
#### 🐞 Fixes

Diff for: crates/actions/src/actions/install_deps.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use moon_platform::{BoxedPlatform, PlatformManager, Runtime};
99
use moon_project::Project;
1010
use moon_time::to_millis;
1111
use moon_workspace_graph::WorkspaceGraph;
12+
use proto_core::UnresolvedVersionSpec;
1213
use starbase_utils::fs;
1314
use std::path::PathBuf;
1415
use std::sync::Arc;
@@ -19,6 +20,7 @@ cache_item!(
1920
pub struct DependenciesCacheState {
2021
pub last_hash: String,
2122
pub last_install_time: u128,
23+
pub last_tool_version: Option<UnresolvedVersionSpec>,
2224
}
2325
);
2426

@@ -103,8 +105,9 @@ pub async fn install_deps(
103105
)
104106
.await?;
105107

106-
// Extract lockfile timestamp
108+
// Extract lockfile timestamp and tool version
107109
let mut lockfile_timestamp = track_lockfile(&app_context, project, &lockfile_name)?;
110+
let tool_version = runtime.requirement.to_spec();
108111

109112
// Only install deps if a cache miss
110113
let mut state = app_context
@@ -123,6 +126,8 @@ pub async fn install_deps(
123126
|| manifests_hash
124127
.as_ref()
125128
.is_some_and(|hash| hash != &state.data.last_hash)
129+
// Toolchain version has changed
130+
|| state.data.last_tool_version != tool_version
126131
{
127132
let working_dir = match project {
128133
Some(proj) => proj.root.clone(),
@@ -155,6 +160,7 @@ pub async fn install_deps(
155160

156161
state.data.last_hash = manifests_hash.unwrap_or_default();
157162
state.data.last_install_time = lockfile_timestamp;
163+
state.data.last_tool_version = tool_version;
158164
state.save()?;
159165

160166
return Ok(ActionStatus::Passed);

Diff for: crates/app/src/session.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::app::{Cli, Commands};
22
use crate::app_error::AppError;
3+
use crate::commands::docker::DockerCommands;
34
use crate::components::*;
45
use crate::systems::*;
56
use async_trait::async_trait;
@@ -201,17 +202,22 @@ impl CliSession {
201202
self.workspace_config.telemetry
202203
}
203204

204-
pub fn requires_workspace_setup(&self) -> bool {
205+
pub fn requires_workspace_configured(&self) -> bool {
205206
!matches!(
206207
self.cli.command,
207-
Commands::Completions(_) | Commands::Init(_) | Commands::Setup
208+
Commands::Completions(_) | Commands::Init(_)
208209
)
209210
}
210211

211212
pub fn requires_toolchain_installed(&self) -> bool {
212213
matches!(
213214
self.cli.command,
214-
Commands::Bin(_) | Commands::Docker { .. } | Commands::Node { .. } | Commands::Teardown
215+
Commands::Bin(_)
216+
| Commands::Docker {
217+
command: DockerCommands::Prune {}
218+
}
219+
| Commands::Node { .. }
220+
| Commands::Teardown
215221
)
216222
}
217223

@@ -238,7 +244,7 @@ impl AppSession for CliSession {
238244

239245
self.working_dir = env::current_dir().map_err(|_| AppError::MissingWorkingDir)?;
240246

241-
self.workspace_root = if self.requires_workspace_setup() {
247+
self.workspace_root = if self.requires_workspace_configured() {
242248
startup::find_workspace_root(&self.working_dir)?
243249
} else {
244250
self.working_dir.clone()
@@ -253,7 +259,7 @@ impl AppSession for CliSession {
253259

254260
// Load configs
255261

256-
if self.requires_workspace_setup() {
262+
if self.requires_workspace_configured() {
257263
let (workspace_config, tasks_config, toolchain_config) = try_join!(
258264
startup::load_workspace_config(self.config_loader.clone(), &self.workspace_root),
259265
startup::load_tasks_configs(self.config_loader.clone(), &self.workspace_root),
@@ -289,7 +295,7 @@ impl AppSession for CliSession {
289295
analyze::validate_version_constraint(constraint, &self.cli_version)?;
290296
}
291297

292-
if self.requires_workspace_setup() {
298+
if self.requires_workspace_configured() {
293299
let cache_engine = self.get_cache_engine()?;
294300

295301
analyze::install_proto(

Diff for: crates/toolchain/src/detect/languages.rs

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub static PYTHON: StaticStringList = &[
4545
// poetry
4646
"poetry.toml",
4747
"poetry.lock",
48+
// uv
49+
"uv.toml",
50+
"uv.lock",
4851
];
4952

5053
pub static RUBY: StaticStringList = &["Gemfile", "Gemfile.lock", ".bundle", ".ruby-version"];

Diff for: legacy/python/platform/src/actions/install_deps.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@ use moon_config::PythonPackageManager;
44
use moon_console::{Checkpoint, Console};
55
use moon_logger::error;
66
use moon_python_tool::PythonTool;
7+
use proto_core::VersionSpec;
8+
use starbase_utils::fs;
79
use std::path::Path;
810

11+
fn is_venv_diff_version(venv_root: &Path, python_version: VersionSpec) -> miette::Result<bool> {
12+
let cfg_path = venv_root.join("pyvenv.cfg");
13+
14+
if !cfg_path.exists() {
15+
return Ok(false);
16+
}
17+
18+
let cfg = fs::read_file(cfg_path)?;
19+
let version_line = format!("version = {python_version}");
20+
21+
Ok(!cfg.contains(&version_line))
22+
}
23+
924
pub async fn install_deps(
1025
python: &PythonTool,
1126
workspace_root: &Path,
@@ -19,18 +34,24 @@ pub async fn install_deps(
1934
workspace_root.join(&python.config.venv_name)
2035
} else {
2136
venv_parent
22-
.as_ref()
23-
.and_then(|vp| vp.parent())
37+
.as_deref()
2438
.unwrap_or(working_dir)
2539
.join(&python.config.venv_name)
2640
};
2741

28-
if !venv_root.exists() && venv_parent.is_some() {
42+
if !venv_root.exists() && venv_parent.is_some()
43+
|| venv_root.exists()
44+
&& is_venv_diff_version(&venv_root, python.tool.get_resolved_version())?
45+
{
2946
let command = match python.config.package_manager {
3047
PythonPackageManager::Pip => "python -m venv",
3148
PythonPackageManager::Uv => "uv venv",
3249
};
3350

51+
// Ensure the venv doesn't exist, otherwise we'll have stale
52+
// artifacts between each activation
53+
fs::remove_dir_all(&venv_root)?;
54+
3455
operations.push(
3556
Operation::task_execution(command)
3657
.track_async(|| async {

Diff for: legacy/python/tool/src/python_tool.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl PythonTool {
109109
args: I,
110110
working_dir: &Path,
111111
workspace_root: &Path,
112+
with_paths: bool,
112113
) -> miette::Result<()>
113114
where
114115
I: IntoIterator<Item = S>,
@@ -118,13 +119,21 @@ impl PythonTool {
118119

119120
cmd.args(args)
120121
.envs(get_proto_env_vars())
121-
.env(
122-
"PATH",
123-
prepend_path_env_var(get_python_tool_paths(self, working_dir, workspace_root)),
124-
)
125122
.cwd(working_dir)
126123
.with_console(self.console.clone());
127124

125+
if with_paths {
126+
cmd.env(
127+
"PATH",
128+
prepend_path_env_var(get_python_tool_paths(self, working_dir, workspace_root)),
129+
);
130+
} else {
131+
cmd.env(
132+
"PATH",
133+
prepend_path_env_var(get_proto_paths(&self.proto_env)),
134+
);
135+
}
136+
128137
if let Some(version) = get_proto_version_env(&self.tool) {
129138
cmd.env("PROTO_PYTHON_VERSION", version);
130139
}
@@ -144,17 +153,27 @@ impl PythonTool {
144153
match self.config.package_manager {
145154
PythonPackageManager::Pip => {
146155
self.exec_python(
147-
["-m", "venv", venv_root.to_str().unwrap_or_default()],
156+
[
157+
"-m",
158+
"venv",
159+
venv_root.to_str().unwrap_or_default(),
160+
"--clear",
161+
],
148162
working_dir,
149163
workspace_root,
164+
false,
150165
)
151166
.await?;
152167
}
153168
PythonPackageManager::Uv => {
154169
let uv = self.get_uv()?;
155170

156-
uv.create_command_with_paths(self, working_dir)?
157-
.args(["venv", venv_root.to_str().unwrap_or_default()])
171+
uv.create_command(self)?
172+
.args([
173+
"venv",
174+
venv_root.to_str().unwrap_or_default(),
175+
"--no-python-downloads",
176+
])
158177
.cwd(working_dir)
159178
.exec_stream_output()
160179
.await?;

0 commit comments

Comments
 (0)