Comments (6)
~/.jq
can be a directory with .jq
files in it instead of a file.
from jq.
~/.jq
can be a directory with.jq
files in it instead of a file.
My apologies for not being explicit with my meaning.
~/.jq
is BOTH an "on-startup-macro-file" and an "on-demand-module-directory". Having a single name for two entirely different use cases is a problem.
I would like a number of macros autoloaded on startup (hence ~/.jq
the file), and a number of modules available "on demand" when they are needed (hence ~/.jq
the directory).
Unless I'm mistaken, I cannot create a file and a directory of the same name, so I'm suggesting adding ~/.jq.d
to the module search path so both features can be made available. (~/.jq as a directory should continue working if its used)
Sorry for not simply saying that in the beginning.
from jq.
~/.jq
can be a directory with.jq
files in it instead of a file.
Sure it should work? i can't manage to get it working. Also tried main.jq
which seem to be a thing but with no success. Looking at the code around here
Lines 178 to 203 in 5029328
~/.jq
is a directory stat
will succeed and not end up trying main.jq
and .jq
. I'm also confused by the comments Try ${search_dir}/$(dirname ${rel_path})/jq/main.jq
and Try ${search_dir}/${rel_path}/$(basename ${rel_path}).jq
but don't see any dirname
-ish call?
Get a feeling all this could be clarified a bit in the documentation also :)
from jq.
Hmm, you are right; having .jq
files in ~/.jq
is different from having a ~/.jq
that is a file.
Only if ~/.jq
is a file, its content is sourced:
Lines 423 to 431 in 5029328
~/.jq
as a directory is just a directory that happens to be in the default search path, it has no other special behaviour.
I don't know what the main.jq
thing is, it looks like a change a made after jq 1.6 was released, and never documented.
It was actually introduced in 1.6, but never documented.
from jq.
Also tried
main.jq
which seem to be a thing but with no success. Looking at the code around here
100% if the ~/.jq
directory could contain an autoloading "main" module I would be very happy.
The main.jq
business is to support loading ./MODULE/jq/main.jq
when you call include "MODULE"
. This allows main.jq
to import more files and have them sourced locally.
EDIT: I take that back. A quick test shows when module "X" calls include "Y"
, Y is sourced locally (relative to my currect directory) instead of locally to "X". This is a bug, but its tangential to this thread.
from jq.
This is a bug, but its tangential to this thread.
To clarify what I mean by this..
As a test, I created the file ~/.jq/test/jq/main.jq
which simply contains include "second";
This is the result of some linuxy magic show how "second" is located.
$ strace -f jq -n 'include "test"; .'|&grep -E 'test|second'
newfstatat(AT_FDCWD, "./test.jq", 0x7ffc384aa420, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./test/jq/main.jq", 0x7ffc384aa420, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./test/test.jq", 0x7ffc384aa420, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/user/.jq/test.jq", 0x7ffc384aa420, 0) = -1 ENOENT (No such file or directory)
readlink("/home/user/.jq/test", 0x7ffc384a9ab0, 1023) = -1 EINVAL (Invalid argument)
readlink("/home/user/.jq/test/jq", 0x7ffc384a9ab0, 1023) = -1 EINVAL (Invalid argument)
readlink("/home/user/.jq/test/jq/main.jq", 0x7ffc384a9ab0, 1023) = -1 EINVAL (Invalid argument)
newfstatat(AT_FDCWD, "/home/user/.jq/test/jq/main.jq", {st_mode=S_IFREG|0644, st_size=19, ...}, 0) = 0
openat(AT_FDCWD, "/home/user/.jq/test/jq/main.jq", O_RDONLY) = 3
read(3, "\ninclude \"second\";\n", 4096) = 19
newfstatat(AT_FDCWD, "./second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./second/jq/main.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./second/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/user/.jq/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/user/.jq/second/jq/main.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/user/.jq/second/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/jq/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/jq/second/jq/main.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/jq/second/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/second/jq/main.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "./../lib/second/second.jq", 0x7ffc384aa250, 0) = -1 ENOENT (No such file or directory)
write(2, "jq: error: module not found: sec"..., 37jq: error: module not found: second
Note that it will search for ./second
instead of ~/.jq/test/jq/second.jq
...
Since it is being included by "test/jq/main.jq" is should be sourced there first.
This will help ensure any package containing multiple files can get sourced correctly without namespacing issues.
from jq.
Related Issues (20)
- Windows jq version 1.7 has a "dirty" suffix when downloading AMD64 version from https://jqlang.github.io/jq/download/ HOT 2
- OT: What versions of arm require `armel`? HOT 3
- We should add an info that release files are bare executables. HOT 1
- strftime produces corrupted characters in windows HOT 7
- Wrong math for big integers HOT 9
- Python bindings HOT 1
- Running `jqtest` triggers UBSAN errors HOT 1
- jq_fuzz_fixed: count-down loop times out if the input is a big number HOT 10
- Strange jq performance problem HOT 14
- heap-buffer-overflow in jq1.7 at decNumber.c HOT 3
- CVE-2023-49355 status ? HOT 2
- Tests don't work in non-decnumber builds
- Feature Request - Full Path Json output HOT 5
- Broken non-Latin output HOT 14
- Version 1.7.1 not working well on XcodeCloud HOT 4
- 1 test fails on WSL Debian HOT 14
- Version number pattern
- Base64d filter is not working as expected. HOT 2
- Allow user to control colors of int/bool/number HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.