Julia 的 r-here 或 py-here 的类似物

问题描述 投票:0回答:3

背景
R 中可重复工作的非常有用的工具之一是“here”库。

我被第一个链接中他们所说的部分所吸引:

“here”库在 Anaconda 中编码为“r-here

我不确定哪个先出现,但 Python 也有一个“here”库。

“这里”使相对路径变得微不足道,这对于可重复的数据科学和分析工作非常有用。

问题
干净处理文件相对路径的 Julia 等效项是什么? 是否有一种干净的方法将其与项目打包集成,就像 RStudio 那样?

path package julia project reproducible-research
3个回答
3
投票

根据描述,听起来 DrWatson.jl 可以满足您的要求。来自网站

[DrWatson] 是一个 Julia 包,旨在帮助人们提高科学项目的一致性,更快更轻松地导航和共享它们,管理脚本、现有模拟以及项目源代码。 DrWatson 有助于建立可重复性,总的来说,它使管理科学项目成为一项简单的工作。

就像描述所暗示的那样,它比

here
看起来更雄心勃勃,还具有管理数据、模拟运行等功能。但它们是可选的,如果需要,您可以仅使用目录处理部分。

导航项目描述了

projectdir
功能,其工作方式与
here
类似。
projectdir("foo", "bar")
解析为当前项目根目录下的
foo/bar
,就像
here
一样。

还有

datadir()
srcdir()
等可以直接处理项目下的公共子目录,例如。
datadir("foo", "test.jld2")
解析为项目根目录下的
data/foo/test.jld2


0
投票

据我所知,它不存在(

Here.jl
不会返回任何谷歌点击),但似乎它对于某人来说足够简单来实现。也许是你!


0
投票

我提出了这个解决方案,它在我的情况下效果很好,即通过 REPL(将项目根目录作为工作目录)或通过调用脚本的命令行以交互方式运行代码。

using FilePathsBase

# Return the root of the project
function project_root(current_dir = @__DIR__)
  while current_dir != "/"
    if isdir(joinpath(current_dir, ".git")) ||
       isfile(joinpath(current_dir, "Project.toml"))
      return current_dir
    end
    current_dir = dirname(current_dir)
  end
  error("Project root not found")
end

# Construct paths relative to the project root
here(args...) = joinpath(project_root(), args...)

像这样使用:

here("data", "my_data_file.json")

我确信可以对其进行改进,以处理 git 和 julia 项目以外的更多设置。

© www.soinside.com 2019 - 2024. All rights reserved.