Drop the hard `Pkg` dependency

未关闭
#446 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@thchr 已经在做这个了。

开始于 2026年11月6日。

  • #449 来自 @thchr —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
冷清
技术栈
julia
领域
tooling

调研方向

读取 src/FileIO.jl 中的依赖声明和 using Pkg,然后检查 src/deprecated.jl:50-67 中已弃用的调用点以及 src/loadsave.jl:203 中实际使用的加载路径。issue 提供了两种方案,因此首先确认 maintainers 希望采用哪种方向。完成的标准是:移除不必要的依赖,同时不破坏受支持的非弃用路径,并根据所选方案处理已弃用的行为。

由索引模型根据 Issue 内容生成。

描述

FileIO declares Pkg in [deps] and does using Pkg in src/FileIO.jl, but no non-deprecated code path uses it. Every Pkg.* call site (src/deprecated.jl:50-67) lives in the legacy add_loader/add_saver methods that are already marked # TODO: delete this method in FileIO v2. Since FileIO sits near the root of a large part of the ecosystem's dependency graph, every downstream package inherits Pkg into its closure and pays for it at using time.

The dependency dates to 0336017 (June 2019, the REQUIRE → Project.toml migration), when Pkg.installed() and Pkg.add were used to detect and install missing backends. Both uses are long gone; the live path loads backends with Base.require in src/loadsave.jl:203, which is pure Base.

The registry fallback is nearly unreachable

The remaining block resolves a package name to a UUID by scanning the installed registries, across three version-dependent branches. It only runs when Base.identify_package returns nothing — i.e. the package isn't a direct dep of the active project — but the PkgId it builds is then handed to Base.require, which needs the package in the load path anyway.

So it can only help when the package is an indirect dep: in the manifest, not a direct dep. Otherwise it either finds nothing or finds a UUID that fails at require later. That's a lot of machinery, plus a stdlib in every downstream closure, for a case callers can handle by passing name => uuid — which the non-deprecated API already asks for.

Option A — lazy load (non-breaking, 1.x)

Drop using Pkg and the [deps] entry; load on demand inside the deprecated method, which has already emitted a depwarn by that point:

const PKG_UUID = UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f")
_load_pkg() = Base.require(Base.PkgId(PKG_UUID, "Pkg"))

and access Pkg.API.Context() etc. through the returned module. Identical behaviour for anyone on the deprecated path; everyone else stops paying.

Option B — delete the lookup (v2)

Resolve via Base.identify_package and Main only, and when both fail throw something actionable:

throw(ArgumentError("could not resolve package \"$pkgname\" from the active environment; " *
                    "pass it as a Module or as `\"$pkgname\" => uuid`"))
主要语言
Julia
星标
228
派生
83
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

JuliaIO/FileIO.jl 的其他 Issue

查看 JuliaIO/FileIO.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。