-
Notifications
You must be signed in to change notification settings - Fork 59
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
Generated go constants for multicodecs #134
Comments
this is something @mvdan was considering doing and maybe has thoughts on this implementation |
Indeed, I've had an implementation in mind for a few weeks :) I started implementing it over the weekend, and I plan to wrap it up and push it later this week. The summary is that the API would be smaller and there would overall be less code; see multiformats/multicodec#199. |
Oh I missed that issue multiformats/multicodec#199 - but I think we had a similar thought process :) Regarding your conclusion:
This is exactly what I've done in dennis-tra/go-multicodec/const.go. The other two files dennis-tra/go-multicodec/codecs.go and dennis-tra/go-multicodec/tags.go are just there to show other possible things one could do with such a generator approach. While I think
If the I'm curious how you approached this and looking forward to see your solution :) I'd appreciate if you left a note here or tagged me so it won't slip through. Edit: I just removed the |
Would you be up for adapting your implementation to the leaner approach I was thinking, so we can reuse your work? The bigger changes would be:
I also wonder if the code generator is a tad over-engineered. You have two directories and five files, between Go code and templates. After the changes above, I bet you could end up with a rather simple generator in under 100 lines of Go in a single file. |
This might not be necessary, there's a ton of prior art of just using upper camel case regardless of acronyms, look no further than https://godoc.org/github.com/ipfs/go-cid for lots of examples. Up to you both but I doubt people will mind if it's not strictly correct. If you end up trying to be correct you could be up for a lot of work figuring out if each new case should be capitalised or not -- are you going to go with |
Maybe. Standard CamelCase would be better than JAVA_CASE anyway :) |
Sure :)
While I'm not the biggest fan of submodules either I see some benefits in using it. Imho there is some added value in knowing which commit in the multicodecs repo induced the change to the list of constants. Just using GET to fetch the table makes the generator result unreproducable for older commits. Having the submodule clearly links the dependency between these repos.
Initially I thought this is good idea, but
At first I haven't had the Java like names but the CamelCase ones (see this commit). Afaik this is also the recommended/idiomatic way of naming constants in Go (found the source). That's why I went for this approach first. For the camel case conversion from the Having the additional dependency of However I just saw that the initialisms guideline also says:
So I'd suggest doing it similarly to the go-cid package and reverting my aforementioned commit. This would result in "blindly" converting the
👍
The generator is already generating deprecated constants and prefixes the doc string with
That will likely be true :) thanks for your input. EDIT: I just updated the |
You can't have truly reproducible unless you simply vendor/copy the table into the git repo. A git clone can fail in the future. If you want to know what commit was used in a past
See
Sounds good to me.
Ah, gotcha, that sounds good. I misread the generator source.
Here's a suggested heuristic: leave underscores untouched, and any dash between two digits must turn into an underscore. That way, |
I just updated the repository and removed the submodule.
Great, I didn't know this was possible 👍
Just tried that and it LGTM 👍 That's the current state: |
Yes; it's just not at the top of my TODO list :) Are you still okay with transferring this code over to https://github.com/multiformats/go-multicodec? My plan is to remove all existing code there, keep the LICENSE and some parts of the README, add the new implementation, and tag v0.2.0 when done. I'd like the new implementation to be a single squashed commit, just for the sake of keeping the history clean. You should remain the author of that single commit, since you wrote the software anyway. It would be best if you could squash all your work in a single commit with a good commit message explaining all that you've done, so that I can then cherry-pick that. The only other detail that comes to mind is having me listed as the maintainer of the repository/module, which I think is fair given that I'm employed to take that kind of responsibility :) You would of course be welcome to open issues and contribute PRs, and I would review them. As for the implementation, here are some more nits to polish the code a little more:
This is all stuff I could do via a PR after we've moved the code to the main repository, though, so it's up to you if you want to do this yourself now or leave it to me to do later. |
Sure thing, I had your fast replies from last week as a reference point ;)
The work I've done here is no rocket science but still having my name somewhere would be nice. Your plan captures that :) 👍
I've covered the first three points and left the last one to you, because of the challenges with having special cases mentioned earlier. You can find the commit in the |
Thanks! Looks good. I think we can leave out I'm also thinking that it would be best to leave the github action out of the first version, because I feel like it's a potential security concern - a third party action has access to write to our repo, and since we follow a tag/branch the upstream could run arbitrary code with those credentials. And it's really not all that necessary; the table should only update every few weeks, and the cost of updating is a simple I'll get to reviving the repo this week, thanks for your help! |
My first attempt is at multiformats/go-multicodec#37, after unarchiving the repository and closing all previous issues and PRs. Let me know what you think. We should probably close this issue and continue over there. |
The above has been merged, thanks @dennis-tra! I'll continue with PRs over there. |
Thanks @mvdan, I may have chimed, if I had seen the conversation there - great to see it merged :) |
Hi everyone,
I saw multiple multicodec constant definitions in e.g. multiformats/go-multihash/multihash.go#L38 and multiformats/go-cid/cid.go#L52. Furthermore the generation of the blake/skein mappings are not obvious.
This motivated me to play around and try to automate the generation based on the "canonical" multicodecs table. The outcome can be found here:
https://github.com/dennis-tra/go-multicodec
The repo contains the multiformats/multicodec repo as a submodule. Every night a GitHub-Action updates the HEAD of the submodule to the most recent
master
commit, runs the constants generator, commits possible changes and creates a pull request. It will update the same pull request if subsequent runs find different changes and it won't create a pull request if no changes were detected (GitHub-Action: peter-evans/create-pull-request@v3).Moving the constants to another repo would obviously be a breaking change for others who depend on this go-multihash repo so I see there are strong forces against a proposal like this.
But anyways, I just wanted to leave this here and ask if this would be something that you could benefit from?
The text was updated successfully, but these errors were encountered: