-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Feature (v3): Add a function to set the desired line length of an Encoder #455
Conversation
👋Friendly bump: any news on when this might get shipped? 🙏 |
@laverya If I get it right, you're implementing this PR in context of Kustomize. And while this would be really helpful for other projects, Kustomize is the reason you submitted it in the first place? Anyhow, the reason I'm asking is: do you think we could get this PR backported to Kubernetes' fork of yaml at https://github.com/kubernetes-sigs/yaml and make Kustomize use it instead? Curious what you think, given there's not much movement going on here. ☁️ 🙄 |
@bai you're right that kustomize is the primary target of this (or at least MY primary target), and creating a fork of go-yaml/yaml that kubernetes-sigs/yaml can import is a plausible route to get it there. It feels like we're forking the entire chain at that point, of course 😆 (and for that matter I hadn't realized that kustomize had moved to a fork of ghodss/yaml - any idea why?) |
I'm not aware about exact intentions, but assume that for safety/audit reasons, given how many users use those tools with mission-critical infrastructure (to avoid things like left-pad and cryptomining npmjs fiasco). So my thinking was that if kubernetes/kubernetes uses a wrapper/"fork" at https://github.com/kubernetes-sigs/yaml then it would naturally make sense for kustomize use it as well? 🤔 |
Ah, I think we talked past each other a little here - kustomize also uses kubernetes-sigs/yaml as of last month: kubernetes-sigs/kustomize#1014. I just meant that forking go-yaml/yaml would mean that the yaml dependency chain for kustomize would look like this:
This doesn't mean that it's a bad idea, though! Just (IMO) funny. |
Happy Monday! 👋Friendly bumping this PR since kustomize Thoughts on doing |
@niemeyer seems to be back and active (which is why I merged the v3 branch again) - any chance this could get merged? |
In any case, I'll be changing my repos to use https://github.com/laverya/yaml/tree/v3 for now. ( I'll happily switch back (and drop the maintenance burden) once this gets merged, of course. |
otherwise tests of functions that do not exist in v2 fail
Can we merge this please? I had to use his fork branch to fix my problem. Thanks |
@pupapaik I've seen very little interest from the maintainers in actually merging PRs, I'm afraid 😦 I've still got 6 PRs open, which is really depressing. If he was willing to comment and tell me that the patches were unwanted, or that they were deficient in some way, that would be one thing - but I've yet to get a real comment on any of them. Or at least I would assume @niemeyer is the maintainer? EDIT: reading this later, this was inappropriate. |
You're being pushy, Andrew. You did get comments, and you did get a whole email thread about this PR saying I was stabilizing v3 before accepting more patches. I worked quite some time fixing bugs in v3 recently, and that's not even part of my daily job. I do it because I want to make it good. Please be more patient. |
I will try to be more patient. Thank you for responding! |
Any word on this? I just ran into this problem. |
This adds the SetLineLength method to Encoder and changes the imports to the jmhodges/yaml.v2 config. The SetLineLength patch is adapated from go-yaml#455 The README got an update for folks needing this.
This adds the SetLineLength method to Encoder and changes the imports to the jmhodges/yaml.v2 config. The SetLineLength patch is adapated from go-yaml#455 The README got an update for folks needing this.
This adds the SetLineLength method to Encoder and changes the imports to the jmhodges/yaml.v2 config. The SetLineLength patch is adapated from go-yaml#455 The README got an update for folks needing this.
For folks who need this on yaml.v2 (I needed the |
There's also a v3 version available here: ...I should really merge in the latest commits from this repo. Something for tomorrow. |
Hopefully this PR is going to get merged soon 🤞 |
Knowing that this is a very ugly hack - just mentioning for anyone interested that the width can also be set using reflect. I am not sure though if that breaks something else in the package. ....
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
v := reflect.ValueOf(enc).Elem().FieldByName("encoder").Elem()
width := v.FieldByName("emitter").FieldByName("best_width").UnsafeAddr()
widthPtr := (*int)(unsafe.Pointer(width))
// don't limit the width
*widthPtr = -1
// encode contents
if err := enc.Encode(node.Content[0]); err != nil {
return err
}
if err := enc.Close(); err != nil {
return err
}
ioutil.WriteFile(output, buf.Bytes(), permissions) |
That is a horrible, unsafe and unmaintainable hack. ...I love it |
👋 @niemeyer Do you have an idea when this might get merged? |
I need to dedicate a moment to a few open issues here in the next few days. Will look into this as well. |
Apologies for being a pain in the ass with this one, any news on when this might get shipped? 🙏 |
@niemeyer Friendly request to get this PR merged, when you get a chance. |
If anyone's still waiting for this, the company I work for has a branch with releases over at https://github.com/replicatedhq/yaml/tree/v3 It's basically the current v3 (though with a different 'marshal yes/no/etc with quotes' implementation) plus 'marshal with json tags if those are present and yaml tags are not') (I figured the 1 year anniversary was a good opportunity to plug that) |
Is there any issue in using your fork? It seems to fix the issue till this merge is completed. |
Happy 1 year anniversary indeed! Time flies. |
No issues that I know of! Just |
Sorry that I wasn't clear. I was referring to https://github.com/laverya/yaml fork. Was trying to be as close to go-yaml/yaml fork, so that I can switch back as soon as this fix is rolled out. |
@niemeyer bump, please consider merging this, as it is a very simple fix, our option would be to maintain a custom fork with this tiny change. We would rather avoid that if possible. |
I've merged the change, also from @laverya, that disables the wraping altogether instead. I'm tentatively closing this, in the hope that what people really want is no wrapping at all. Let's see what happens next. |
Let's hope, and that's all I think I need! I'll make PRs for some consumers of this (https://github.com/kubernetes-sigs/yaml, https://github.com/ghodss/yaml, a few downstream things) tomorrow. (Or whenever this becomes a release) |
All of a sudden I'm happy I didn't actually make the PRs I was suggesting here (since the consuming projects I was using were able to |
This PR exposes a function
func (e *Encoder) SetLineLength(characters int)
that allows setting the line wrap length of an encoder. The interface was intended to have a very similar style to the SetIndent functionfunc (e *Encoder) SetIndent(spaces int)
, implemented here.Internally, it uses the existing function
func yaml_emitter_set_width(emitter *yaml_emitter_t, width int)
, which was previously unused.This relates to several issues (#387, #348, #166) and a previous PR (#329).