Support globbing in imports
Implements shell-style globs in import statements using the Rust glob crate. Addresses https://github.com/casey/just/issues/1641
Alright, I gated glob imports behind unstable, went back to using the glob crate, and explicitly error out if conversion to a utf-8 native rust string doesn't work.
I keep coming back to this. I have these worries:
-
I worry about delegating glob parsing to a dependency we don't control, and thus may not understand the syntax.
-
I worry about the backwards compatibility impact on existing justfiles. Since although it is crazy to use
*/?/**in a path name, it does happen, and maybe especially on windows or GUI systems. This might also be extra confusing because the globbing character wouldn't appear in the path literal in thejustfile. -
I worry about the restriction that it doesn't work with non-unicode paths.
I wonder if maybe it would be better if there was some syntax to enable the glob at the import, and it was that syntax which was experimental, instead of a setting which turns it on for all imports
Something like:
glob import '*/mod.just'
looking forward to see something like this merged.
@neunenak What are you thinking about this? I think we should do this, and I think the combination of both making it unstable, and opting into explicitly for each import (syntax tbd, but glob import "foo" or import glob "foo" both seem fine), make me much more comfortable about dealing with the shortcomings later.
@neunenak Still working on this?
:(
I worry about the backwards compatibility impact on existing justfiles. Since although it is crazy to use /?/* in a path name, it does happen, and maybe especially on windows or GUI systems. This might also be extra confusing because the globbing character wouldn't appear in the path literal in the justfile. I worry about the restriction that it doesn't work with non-unicode paths.
This is my simple use-case I have dozens of toplevel justfiles that load project-specific justfiles from a .just-subdirectory
her is an example toplevel file:
# Just is a crossplatform task-runner, similar to make.
# And justfiles are equivalent to makefiles.
#
# Official docs:
# - https://just.systems/man/en
# - installation: https://just.systems/man/en/pre-built-binaries.html
#
# Usage:
# > just # configured to display all available tasks
# > just --help
# > just <taskname>
#
# Notes:
# - Comments immediately preceding a recipe will appear in just --list
# load environment variables from .env file
set dotenv-filename := ".env"
set dotenv-load := true
# search for justfiles in parent directories
set fallback
# set tempdir := "var/tmp"
# enable experimental features
set unstable
# set shell to powershell on Windows
set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"]
set shell := ["bash", "-uc"]
# waiting for glob-support, see
# - https://github.com/casey/just/issues/1885
# - https://github.com/casey/just/pull/2376
import '.just/bandit.justfile'
import '.just/dir-structure.justfile'
import '.just/dotenv.justfile'
import '.just/ipython.justfile'
import '.just/just.justfile'
import '.just/mypy.justfile'
import '.just/pre-commit.justfile'
import '.just/project.justfile'
import '.just/pylint.justfile'
import '.just/pyroma.justfile'
import '.just/pytest.justfile'
import '.just/readthedocs.justfile'
import '.just/ruff.justfile'
import '.just/safety.justfile'
import '.just/sshx.justfile'
import '.just/ty.justfile'
import '.just/ubuntu.justfile'
import '.just/uv.justfile'
# Display all canonical tasks (default recipe)
list:
@ just --list --unsorted --no-aliases
@neunenak Still working on this?
ngl I've totally let this PR slip, and I've got other stuff going on, but yeah I would like to try to get this merged at some point. I would have to refresh myself with respect to what the bottlenecks were to getting this PR merged earlier, and it's been open long enough that I'd probably have to change a decent amount of stuff to get it mergeable. OTOH it's also been open so long that AI has gotten meaningfully better at coding since I opened it, so there's a positive I suppose :) (We live in an exciting time in human history).
Anyway I'll see what I can do here, definitely feel free to ping me in the future about this or any other issue I have open. Or if someone else wants to take this code and run with it, feel free.