Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/prek-consts/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ impl EnvVars {
// Coursier related
pub const COURSIER_CACHE: &'static str = "COURSIER_CACHE";

// Julia related
pub const JULIA_DEPOT_PATH: &'static str = "JULIA_DEPOT_PATH";

// Ruby related
pub const PREK_RUBY_MIRROR: &'static str = "PREK_RUBY_MIRROR";
pub const GEM_HOME: &'static str = "GEM_HOME";
Expand Down
18 changes: 16 additions & 2 deletions crates/prek/src/languages/julia.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::ffi::OsString;
use std::path::Path;
use std::process::Stdio;
use std::sync::Arc;

use anyhow::{Context, Result};
use prek_consts::env_vars::EnvVars;
use tracing::debug;

use crate::cli::reporter::HookInstallReporter;
Expand All @@ -11,11 +13,17 @@ use crate::hook::{Hook, InstallInfo, InstalledHook};
use crate::languages::LanguageBackend;
use crate::process::Cmd;
use crate::run::run_by_batch;
use crate::store::Store;
use crate::store::{CacheBucket, Store};

#[derive(Debug, Copy, Clone)]
pub(crate) struct Julia;

fn depot_path(store: &Store) -> Result<OsString> {
let depot = store.cache_path(CacheBucket::Julia);
std::env::join_paths([depot.as_path(), Path::new("")])
.context("Failed to join Julia depot path")
}

#[async_trait::async_trait(?Send)]
impl LanguageBackend for Julia {
async fn install(
Expand All @@ -31,6 +39,9 @@ impl LanguageBackend for Julia {
debug!(%hook, target = %info.env_path.display(), "Installing Julia environment");

fs_err::tokio::create_dir_all(&info.env_path).await?;
let depot = store.cache_path(CacheBucket::Julia);
fs_err::tokio::create_dir_all(&depot).await?;
let depot_path = depot_path(store)?;
let search_path = hook.repo_path().unwrap_or_else(|| hook.work_dir());

let find_src = |names: &[&str]| {
Expand Down Expand Up @@ -70,6 +81,7 @@ impl LanguageBackend for Julia {
.arg(julia_code)
.arg("--")
.args(&hook.additional_dependencies)
.env(EnvVars::JULIA_DEPOT_PATH, &depot_path)
.check(true)
.output()
.await
Expand Down Expand Up @@ -97,14 +109,15 @@ impl LanguageBackend for Julia {

async fn run(
&self,
_store: &Store,
store: &Store,
hook: &InstalledHook,
filenames: &[&Path],
reporter: &HookRunReporter,
) -> Result<(i32, Vec<u8>)> {
let progress = reporter.on_run_start(hook, filenames.len());

let env_dir = hook.env_path().expect("Julia must have env path");
let depot_path = depot_path(store)?;

let mut entry = hook.entry.expect_direct().split()?;
if let Some(repo_path) = hook.repo_path() {
Expand All @@ -121,6 +134,7 @@ impl LanguageBackend for Julia {
.arg(format!("--project={}", env_dir.display()))
.args(&entry)
.envs(&hook.env)
.env(EnvVars::JULIA_DEPOT_PATH, &depot_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate old Julia envs before switching depots

When users upgrade with an already-installed Julia hook environment, the install cache still considers it reusable because the persisted metadata/schema did not change and check_health only runs julia --version. Those old environments had their package sources in the user's default depot, but this runtime override points Julia at a new prek depot and excludes the user depot, so hooks that use additional_dependencies or a Project.toml dependency can fail to load packages until the user manually reinstalls. Please make old Julia envs miss the cache or instantiate them into the shared depot before running them with this JULIA_DEPOT_PATH.

Useful? React with 👍 / 👎.

.args(&hook.args)
.file_args(batch)
.check(false)
Expand Down
2 changes: 1 addition & 1 deletion crates/prek/src/languages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl Language {
Self::Coursier => &[CacheBucket::Coursier],
Self::Deno => &[CacheBucket::Deno],
Self::Golang => &[CacheBucket::Go],
Self::Julia => &[CacheBucket::Julia],
Self::Node => &[CacheBucket::Npm],
Self::Python | Self::Pygrep => &[CacheBucket::Uv, CacheBucket::Python],
Self::Rust => &[CacheBucket::Cargo],
Expand All @@ -233,7 +234,6 @@ impl Language {
| Self::Dotnet
| Self::Fail
| Self::Haskell
| Self::Julia
| Self::Lua
| Self::Perl
| Self::Php
Expand Down
1 change: 1 addition & 0 deletions crates/prek/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ pub(crate) enum CacheBucket {
Python,
Cargo,
Deno,
Julia,
Npm,
Coursier,
Prek,
Expand Down
Loading