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

Module load paths are relative to the importing file, but they should be relative to the directory from which the command is executed #227

Closed
jbrains opened this issue Nov 9, 2024 · 5 comments

Comments

@jbrains
Copy link

jbrains commented Nov 9, 2024

I'm struggling to use modules with jaq and I've run into a very surprising bit of behavior.

It appears that, when I specify the module load path, jaq applies that load path relative to the file doing the importing. It should apply the load path relative to the directory in which the command is executed, which is how load paths work in every other programming language in which I've used them as well as how jq works.

# module_folder/module.jq
def hello: "Hello, world."
# main_folder/main.jq
import "module" as Module; Module::hello

Notice the difference between jaq and jq.

$ jaq -n -L "../module_folder" -f main_folder/main.jq
"Hello, world."
$ jq -n -L module_folder -f main_folder/main.jq
"Hello, world."
$ jaq -n -L "module_folder" -f main_folder/main.jq
Error: could not load file module: file not found
  ╭─[main_folder/main.jq]
  │
1 │ import "module" as Module; Module::hello
  ┆         ───┬──
  ┆            │
  ┆            ╰───────────────────────────── file not found
──╯

To be clear, module_folder and main_folder are both located in the directory where I run those commands.

It defeats the purpose of a load path if I have to change the load path depending on the location of the "main" file that I run. I expect a load path to stay the same no matter where the source files are that are importing from modules on that load path. It also defeats the purpose of a load path if I have to use absolute paths on it, then I can't move the root of my project without changing all my jaq commands/scripts.

@jbrains jbrains changed the title Module path is relative to the importing file instead of the directory from which the command is executed Module load paths are relative to the importing file, but they should be related to the directory from which the command is executed Nov 9, 2024
@jbrains jbrains changed the title Module load paths are relative to the importing file, but they should be related to the directory from which the command is executed Module load paths are relative to the importing file, but they should be relative to the directory from which the command is executed Nov 9, 2024
01mf02 added a commit that referenced this issue Nov 11, 2024
@01mf02
Copy link
Owner

01mf02 commented Nov 11, 2024

Hi @jbrains, I totally agree with you. I have tried to address your concern in #228, by interpreting the paths given via -L as relative to the current working directory, instead of relative to the path of the including file.

Module path resolution is a rather hairy topic, see #202. I'm very glad that you are testing this functionality more than I did so far. Please let me know if you encounter more issues.

@01mf02
Copy link
Owner

01mf02 commented Nov 11, 2024

Oh, and thanks a lot for your very detailed bug report, by the way!

@jbrains
Copy link
Author

jbrains commented Nov 12, 2024

Oh, and thanks a lot for your very detailed bug report, by the way!

This is one of my particular forms of programmer empathy. I write defect reports that I wish others would write for me.

@jbrains
Copy link
Author

jbrains commented Nov 12, 2024

Hi @jbrains, I totally agree with you. I have tried to address your concern in #228, by interpreting the paths given via -L as relative to the current working directory, instead of relative to the path of the including file.

I will try this out over the next few days, but my very early testing looks promising. I really appreciate the change.

@01mf02
Copy link
Owner

01mf02 commented Nov 26, 2024

I'm closing this issue now. When you encounter another issue with module loading, feel free to open a new issue. Thanks again!

@01mf02 01mf02 closed this as completed Nov 26, 2024
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

2 participants