Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Executing recipes from imported justfile is done in working dir of imported file #1813

Closed
michaelCTS opened this issue Jan 3, 2024 · 5 comments

Comments

@michaelCTS
Copy link

just version: 1.21.0

This bug seems like a regressions, as in 1.16.0 the !include statement didn't work this way and my just files were executing fine.

Example

/tmp/justtest/justfile

upper:
  echo upper
  pwd

/tmp/justtest/sub/justfile

import "../justfile"

default: upper
  echo sub
  pwd
$ cd /tmp/justtest/sub
$ just
upper
pwd
/tmp/justest
sub
pwd
/tmp/justest/sub
@casey
Copy link
Owner

casey commented Jan 3, 2024

Good catch! This is indeed a bug. I opened #1817, which contains tests with no fix yet.

Another potential issue is that the path of nested imports, i.e., imports within imports, are resolved relative to the directory containing the nested import source file. I think this is also a bug, and that, by the logic that imports are treated as being part of the importing justfile, they should be resolved relative to the importing justfile. Does that sound right to you?

@laniakea64
Copy link
Contributor

by the logic that imports are treated as being part of the importing justfile, they should be resolved relative to the importing justfile. Does that sound right to you?

That behavior would seem counter-intuitive and would hinder usability when:

  • a single shared justfile containing nested imports is imported in multiple projects; or
  • a justfile that imports other justfiles is both used standalone and is itself imported.

Currently, all imports in these situations can be relative paths. Because the paths relative to each primary justfile are different, the suggested behavior change would effectively force nested imports to be specified as absolute paths, breaking portability.

Hope this bug can be fixed while preserving the existing relative path resolution basis, would be ideal if so. Thanks 🙂

@casey
Copy link
Owner

casey commented Jan 4, 2024

Hope this bug can be fixed while preserving the existing relative path resolution basis, would be ideal if so. Thanks 🙂

Definitely, they're two issues, and I only mention it here because I thought about it while fixing this, and doing both invovles a similar change. I think you're right that import and modules paths should be relative to the source file, even if there's an argument that import paths are different, since they semantically are as if the contents were inserted into the importing justfile. I'm just going to leave it as is.

@casey
Copy link
Owner

casey commented Jan 12, 2024

Fixed in #1817! Imported recipes now run in the working directory of the importer, which works for nested imports, i.e., if you have a -> b -> c, and b and c are both imports, recipes in b and c will run in the working directory for a.

@casey casey closed this as completed Jan 12, 2024
@michaelCTS
Copy link
Author

Awesome! Thank you very much. Looking for ward to the next release 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants