:wave: What are best practices for making aliases ...
# general
b
đź‘‹ What are best practices for making aliases under
[cli.alias]
agnostic to their PWD? For example, if my repo has a
widgets/doodad
subdir, and in
widgets/doodad/BUILD
I have
run_shell_command(name="frizzle", command="./scripts/frizzle.sh")
, and I want to alias this to
doodad-frizzle = "run widgets/doodad:frizzle"
… That works correctly from the repo root dir. But if I
cd widgets/doodad; pants doodad-frizzle
it errors,
directory widgets/doodad/widgets/doodad does not exist
, because the path is relative. How can I define the alias so this works the same way no matter what directory I run the command from? Thank you!
Ah, it looks like
//
might work in some cases…
Copy code
[cli.alias]
doodad-frizzle = "run //widgets/doodad:frizzle"
seems to be doing the right thing…
That works for a
run
alias. What about for a `check`… like
Copy code
[python.resolves.add]
doodad = "widgets/doodad/pants-resolve.lock"

[cli.alias]
doodad-mypy = "check --mypy-install-from-resolve=doodad --mypy-config=widgets/doodad/mypy.ini widgets/doodad/::"
👀 …
The
//
syntax in
python.resolves.add
seems to error,
Copy code
native_engine.IntrinsicError: Absolute paths not supported: "//widgets/doodad/BUILD"
and it also doesn’t work for the flag value (
--mypy-config
), perhaps reasonably. Is there another way to make
check
aliases PWD-agnostic? Thanks
Maybe this is actually working just as
Copy code
doodad-mypy = "check --mypy-install-from-resolve=doodad --mypy-config=widgets/doodadcli/mypy.ini //widgets/doodad/::"
Somehow the flag value seems to be resolved from the root, regardless of PWD. Mysterious!
c
yea, support for running pants not from project root has a number of rough edges still..
c
I think it's because
[python.resolves]
uses the value as a hint for generating the (synthetic) lockfile targets. It uses it as a filepath, which is taken as from the root of the repo. the
//
is used for the root of the repo for _target_ addresses , which is why it works for the target of
check
and
run
but not outside of the context of a Pants target. The reason the path from the repo root works for
--mypy-config
is because Pants uses a filepath (similar to the resolves) to pull in the file. These filepaths are taken from the root of the repo. I'm not sure that's helpful. The way I think about it is that Pants will try to reference filepaths in configs from the source roots, and targets can be either relative or absolute