From 08e9c002a6b80354025a80dca3bf42d49e01a82b Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Fri, 15 Nov 2024 14:08:10 +0000 Subject: [PATCH 1/4] refactor(julia): disable julia startup file for julia package update --- src/steps/generic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/steps/generic.rs b/src/steps/generic.rs index ba3e1a2c..f44b499f 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -910,7 +910,7 @@ pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute(julia) - .args(["-e", "using Pkg; Pkg.update()"]) + .args(["--startup-file=no", "-e", "using Pkg; Pkg.update()"]) .status_checked() } From 75cce2201582456ab60b6985768c2b036b080cce Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Sat, 16 Nov 2024 13:46:56 +0000 Subject: [PATCH 2/4] feat(julia): add configuration option for julia startup file --- config.example.toml | 8 ++++++++ src/config.rs | 16 ++++++++++++++++ src/steps/generic.rs | 13 +++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/config.example.toml b/config.example.toml index 30354f18..4c3dc991 100644 --- a/config.example.toml +++ b/config.example.toml @@ -270,3 +270,11 @@ # and the update will be installed system-wide, i.e., available to all users. # (default: false) # use_sudo = false + +[julia] +# If enabled, Topgrade invokes julia with the --startup-file=yes CLI option. +# +# This may be desirable to avoid loading outdated packages with "using" directives +# in the startup file which would cause the update run to fail. +# (default: true) +# startup_file = true diff --git a/src/config.rs b/src/config.rs index e09c4a0b..04026e9f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -452,6 +452,11 @@ pub struct Lensfun { use_sudo: Option, } +#[derive(Deserialize, Default, Debug, Merge)] +pub struct JuliaConfig { + startup_file: Option, +} + #[derive(Deserialize, Default, Debug, Merge)] #[serde(deny_unknown_fields)] /// Configuration file @@ -518,6 +523,9 @@ pub struct ConfigFile { #[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)] lensfun: Option, + + #[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)] + julia: Option, } fn config_directory() -> PathBuf { @@ -1632,6 +1640,14 @@ impl Config { .and_then(|lensfun| lensfun.use_sudo) .unwrap_or(false) } + + pub fn julia_use_startup_file(&self) -> bool { + self.config_file + .julia + .as_ref() + .and_then(|julia| julia.startup_file) + .unwrap_or(true) + } } #[cfg(test)] diff --git a/src/steps/generic.rs b/src/steps/generic.rs index f44b499f..c4e323dd 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -908,10 +908,15 @@ pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> { print_separator(t!("Julia Packages")); - ctx.run_type() - .execute(julia) - .args(["--startup-file=no", "-e", "using Pkg; Pkg.update()"]) - .status_checked() + let mut executor = ctx.run_type().execute(julia); + + executor.arg(if ctx.config().julia_use_startup_file() { + "--startup-file=yes" + } else { + "--startup-file=no" + }); + + executor.args(["-e", "using Pkg; Pkg.update()"]).status_checked() } pub fn run_helm_repo_update(ctx: &ExecutionContext) -> Result<()> { From 42fd87a96f7a626856c12ce266f2216976f358f0 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 18 Nov 2024 12:09:12 +0000 Subject: [PATCH 3/4] fix: deny unknown fields on JuliaConfig deserialisation Co-authored-by: SteveLauC --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 04026e9f..eab7b336 100644 --- a/src/config.rs +++ b/src/config.rs @@ -453,6 +453,7 @@ pub struct Lensfun { } #[derive(Deserialize, Default, Debug, Merge)] +#[serde(deny_unknown_fields)] pub struct JuliaConfig { startup_file: Option, } From 25957a89781ae5e11809ee4f073d55832fe111a8 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 18 Nov 2024 12:11:28 +0000 Subject: [PATCH 4/4] doc(julia): clarify startup_file option purpose --- config.example.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.example.toml b/config.example.toml index 4c3dc991..080f53ac 100644 --- a/config.example.toml +++ b/config.example.toml @@ -272,9 +272,9 @@ # use_sudo = false [julia] -# If enabled, Topgrade invokes julia with the --startup-file=yes CLI option. +# If disabled, Topgrade invokes julia with the --startup-file=no CLI option. # # This may be desirable to avoid loading outdated packages with "using" directives -# in the startup file which would cause the update run to fail. +# in the startup file, which might cause the update run to fail. # (default: true) # startup_file = true