-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
List of publicly released modules? #535
Comments
There aren't any yet. We probably need a package manager first. A few weeks from now we might have one. |
@joelpurra askd:
jq's concepts of "module" and "package" are still evolving, but there are plenty of jq snippets. A few are at the jq Cookbook. Some useful snippets are scattered throughout these trouble tickets. Perhaps some of them should be salvaged by adding them to the Cookbook or somewhere else, e.g. as a "gist". To get the ball rolling, I created one such snippet: https://gist.github.com/37c1311075d2993982be.git It would be easy enough to add a Resources or Snippets page to the wiki, or should we leave them for google to find? |
Fixed links (for browser usage) Thanks! |
Started writing my own library/package/module/modules: jq-hopkok. I'll try and dump more stuff there later on. Since I'm currently writing my code straight into |
Unfortunately I haven't been able to find any examples of a module which I can actually get working.
Any suggestions on getting this to work? In any case, I think the docs need to be clearer on how modules work. |
The docs most definitely need improvement regarding the module system, but since the system's not been part of a major release (1.5 isn't yet out), we've put the documentation off in favor of other things we felt were more pressing. At any rate, what you're missing is the import statement.
If you put your library in For some reason, the default behavior for I'm adding a docs tag to this and flagging it for 1.5 to make sure we get the docs updated. |
When adding the path, the example works fine. However, I expected that using |
You are treating ~/.jq as a folder, right? You have ~/.jq/combine.jq? That being said, I'm still confused as to why combine:: isn't needed. It
|
@wtlangford wrote:
@nicowilliams can elaborate but essentially it's because combine.jq does not declare itself to be a module. More specifically, Nico did not want to introduce a special syntax for the "import" statement to mean "import into the current namespace". I think that's a perfectly fine approach -- so long as you think of "import FOO" in the sense of "require FOO" rather than "import this file and force it to be encapsulated into a module named FOO". |
I just went to play with this to better understand it. The interesting thing I've noticed is that even if the imported file declares itself as a module, it does not get encapsulated when we go to use it. @nicowilliams Is this a bug or is this intentional? |
@wtlangford Yes, |
@michaelmior it is worth noting that I got quite busy towards the end of the development for the module system and wasn't part of the final stages, so what I said may have been off the mark entirely. I had intended for something like
But things seem to have changed after I was away. |
@wtlangford Just speaking from a user perspective without any knowledge of jq internals or how the module system was developed, what would be most convenient for me would be able to |
@wtlangford wrote:
It seems to me that that is a bug: the "hoisting" should only occur if there is no declaration (module statement) in the file. That is:
|
@wtlangford wrote:
I believe that is the plan, but at present, unfortunately, that is not the case (using "master"), presumably because ~/.jq has long been assumed to be a file. In fact, currently "master" does not have a default at all! |
That's interesting. I wonder why we haven't yet done that. Well, I suppose it is time I stop making statements from memory without checking them wrt the module system. @michaelmior I'm not seeing a way to do that without being particularly hacky. We definitely intended for you to have to say |
@michaelmior - Please note that you don't have to use the "import" statement at all to load a file like combine.jq. Assuming a sufficiently modern shell, you can write something like this:
That won't save any typing, but using this approach, you can use regular old jq 1.4, and you can also use curl:
|
@pkoppstein My main hope for using the module system was to save typing. If an explicit import is required, I would probably just fall back to writing shell scripts which is a little unfortunate. I think implicit import of modules would be necessary for my use case (reducing keystrokes). I'm sure this has already been well-considered, but I'm curious what the complications are for doing automatic imports. My expectation is that this would only happen when a module is explicitly referenced (identified by |
@michaelmior - I'll let others speak to any implementation issues there may with respect to your proposal, but I would like to point out that what you're asking for (triggering of an "import") might not achieve what you expect! Here's why: Since combine.jq is not a module, importing it into the main namespace will result in "demo" being defined, but not "combine::demo". Thus, according to your basic proposal, the incantation "combine::demo" would result in "demo" being defined, but not "combine::demo", so the incantation would fail. Of course I realize the entire system could be designed differently, but design is, alas, more difficult than tinkering. As for reducing keystrokes -- the key to big savings is writing scripts. In this regard, did you know that you can use jq as the shebang processor? See https://github.com/stedolan/jq/wiki/FAQ The other key to keystroke convenience is being able to open a shell window within your editor, but that's a topic beyond the scope of this webspace. |
@pkoppstein You're right that I forgot |
Wow, I've a lot to catch up with... |
On Wed, Oct 08, 2014 at 11:27:53AM -0700, William Langford wrote:
It was either that or provide some syntax for it. I'm fine with either |
On Wed, Aug 06, 2014 at 03:25:09PM -0700, pkoppstein wrote:
For 1.5 I've only one more thing to do w.r.t. modules:
This will allow us to leave all versioning to an external pkg manager. |
@nicowilliams Can you confirm that the intended behavior for a basic import (no Or, alternatively: a.jq
b.jq
The current behavior is that things always get brought into the current namespace, regardless of the file that gets imported. If that's the case, why do we have the module statement? |
@nicowilliams - Just to be clear - I think we're all agreed that if the imported file declares itself to be a module, then that should be respected in the absence of an "as" specification. Also -- could you please let us know what the plans for ~/.jq are? I believe the plan was that for 1.5, a file named ~/.jq would not be read in (by default), and that a directory named ~/.jq would have a special status. I'm hoping that ~/.jq will (by default) be included as if by -L ~/.jq. Thanks. |
I'll repeat my opinion: no See #566 Semantic version utility where I've stated similar things. There's also #491 Enhancement request: integrated package manager. |
@joelpurra wrote:
In the absence of a different "import" mechanism, the module keyword is necessary to distinguish "file inclusion" from "module importation". More importantly, the module keyword is necessary for the module system to be declarative. Of course I realize there are different conceptions of modules and modularity, and perhaps Joel would rather that jq's namespace system should not have any of the trappings of a module system, but I note that F# for example has both "namespace" and "module" keywords for declaring namespaces and modules. |
@pkoppstein If ~/.jq is a file, it gets imported, otherwise if it's a |
I'm open to suggestions. I see three options:
Each has something to recommend for and against it. Several folks have
|
On Monday, October 13, 2014, Joel Purra notifications@github.com wrote:
For the time being it's only use should be for metadata that jq doesn't use |
Just released three small packages. Wanted to show the kind of granularity I'd like to see in packages - the smaller and focused the package, the easier it is to re-use it. Try them with Any |
Released four new packages:
Because copy-pasting is bad, I also made a project template/generator a part of
Code goes in |
Three more packages today!
Using |
And another one: I also found Nevertheless we'd better manage the list in the wiki or on a dedicated git repository as list of repository URLs to automatically fetch metadata from. |
I also started a jq module to process Wikidata dumps. Listing new modules in this thread does not scale so let's collect links to existing modules at https://github.com/stedolan/jq/wiki/Modules instead! |
Thanks @nichtich! |
Longer term we could have a repository... I'm not sure I want to get to deal with the problems that come with that... -- think NPM... |
🕶️ + just found this : https://github.com/fiatjaf/awesome-jq |
Is there a list of modules yet? Until there's a package system, I'd love to see people drop a line here for whatever they have released.
At some point I will clean up the shell scripts in har-heedless and har-dulcify, which downloads/creates, transforms and analyzes data based on HAR files.
The text was updated successfully, but these errors were encountered: