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

Allow to pass the FileMode options in the vim plugin #1319

Merged
merged 11 commits into from Sep 29, 2021

Conversation

shaoran
Copy link
Contributor

@shaoran shaoran commented Mar 27, 2020

The vim plugin takes now into consideration the target-version value of
the pyproject.toml file.

You can also specify a default target version with the configuration
variable g:black_target_version.

Vim's :Black command accepts now the following optional arguments:

  • line_length
  • string_normalization
  • black_target_version

Those allow you to override any settings that come either from vim's
configuration or the pyproject.toml file.

It also supports supports a simple tab completion to allow to pass the
arguments quicky.

The vim plugin takes now into consideration the `target-version` value of
the `pyproject.toml` file.

You can also specify a default target version with the configuration
variable `g:black_target_version`.

Vim's `:Black` command accepts now the following optional arguments:

- `line_length`
- `string_normalization`
- `black_target_version`

Those allow you to override any settings that come either from vim's
configuration or the `pyproject.toml` file.

It also supports supports a simple tab completion to allow to pass the
arguments quicky.
I didn't realize that it was a boolan value.
@autophagy autophagy added the C: vim Vim plugin label May 8, 2020
@JelleZijlstra
Copy link
Collaborator

Sorry for leaving this waiting for so long! There are a few merge conflicts now. Do we still need this change?

@shaoran
Copy link
Contributor Author

shaoran commented Apr 12, 2021

Hi

Sorry for leaving this waiting for so long! There are a few merge conflicts now. Do we still need this change?

I'd say yes, because :Black has no options and if you need to pass some command line option like setting python's target version or the line length, you cannot do it directly from vim, you have to do that from the console. In my eyes, that defeats the purpose of having black inside vim, if I have to open a console anyway.

This PR would allow you to do the following in vim: :Black target_version="py27". And because it's something I need all the time, I have this in my vim config:

Plug 'shaoran/black', { 'branch': 'allow_override_args_19.10b0' }

It's so long since I've created this PR that my changes might now work anymore, I'd have to check them, but I'll have time to do it at the weekend.

@felix-hilden
Copy link
Collaborator

If I may, I'll provide a review posted on our Discord in these messages: 1, 2 by Godlygeek:

The core issue seems to be whether or not we'd like to be able to pass arguments as comma-separated key=value pairs. Some concerns were that:

  • The format is unusual: ordinarily the arguments look more like CLI flags, being space-separated
  • Passing varying configuration is an odd design choice since Black is all about consistent formatting, which can be achieved with file configuration or setting g_* variables in Vim

Without knowing too much about the plugin system, I do share these concerns. Target version is of course one argument whose value is naturally varied. Could you comment a bit on your view on the matter, @shaoran? Much appreciated!

@shaoran
Copy link
Contributor Author

shaoran commented Jun 26, 2021

@felix-hilden I'm sorry, I have been very busy this week and was not able to reply. I cannot at the moment, but soon I will answer your questions.

@ichard26 ichard26 added the S: awaiting response Waiting for futher information from OP label Jul 16, 2021
@felix-hilden
Copy link
Collaborator

Hi @shaoran, any updates on this? It'd be nice to bring this issue closer to the finish!

@shaoran
Copy link
Contributor Author

shaoran commented Sep 12, 2021

@felix-hilden I'm so sorry, I've forgotten about this. I'll try to take a look tomorrow or during the next week.

@shaoran
Copy link
Contributor Author

shaoran commented Sep 14, 2021

@felix-hilden I tried merging upstream/main in my branch and I got a conflict in README.md. Back in 19.10b0 (from which
I originally branched of) the documentation was directly in the README.md
file. Now it's been moved to https://black.readthedocs.io

Is the documentation source code for readthedocs still in the repository?

@shaoran
Copy link
Contributor Author

shaoran commented Sep 14, 2021

It changed a lot, I basically would have to rewrite the whole thing again. OK, I'll try that.

@felix-hilden
Copy link
Collaborator

Yep, the documentation source is in the docs/ folder, particularly docs/integrations might be good for this.

@shaoran
Copy link
Contributor Author

shaoran commented Sep 14, 2021

Ok. this will take me a little bit longer. Since there are so many changes since I created the pull request, all my changes are useless and basically have to write them again. I hope, tomorrow I can push a new version.

@felix-hilden
Copy link
Collaborator

No worries! And I'd also like to remind you about the review points I left above 😃

@shaoran
Copy link
Contributor Author

shaoran commented Sep 22, 2021

@felix-hilden sorry that it took a while, but I've been very busy at work.

I try to address the concerns here

  • The format is unusual: ordinarily the arguments look more like CLI flags, being space-separated

I made a change so that arguments are space-separated.

  • Passing varying configuration is an odd design choice since Black is all about consistent formatting, which can be achieved with file configuration or setting g_* variables in Vim

Yes, that is true, that's why I removed passing the other options like fast, linelength, etc. The only option remaining is target_version and that because of convenience.

I maintain a python library that targets multiple python version, some modules only work with Py27, some with Py36, etc. Very often I have those files open at the same time and I'd like to format one with py27 as target and the other with py36 as target without having to set up variables and special rules in my config. So that's why it is for me more convenient to just pass target_version=py27 directly to :Black when I need it. And thanks to tab completion, I don't even have to type it, just press TAB.

Like I said before, I already use this on my environment and has been a huge time saver.

CI seems to be failing because of changelog / Changelog Entry Check (pull_request). Clicking on Details reveals that I should add Please add '(#1319)' change line to CHANGES.md but I'm not sure I should be the one adding this line, besides I don't even know under which release this pull request would be merged (if accepted). So do I have to add that line, or do you do that?

Copy link
Collaborator

@felix-hilden felix-hilden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Having target_version as an argument makes total sense to me as well 👍 I had a look at the code and it looks reasonable, although I don't know vim plugins.

Our changelog is currently at the release, so a new heading needs to be added to the top. So please add a new ## Unreleased heading and place the change under ### Integrations. I left one comment as well. Since we're short on vim wizards, I'm willing to take your word on this working just fine 😄

autoload/black.vim Show resolved Hide resolved
@@ -116,6 +116,8 @@ Wing supports black via the OS Commands tool, as explained in the Wing documenta
Commands and shortcuts:

- `:Black` to format the entire file (ranges not supported);
- you can optionally pass `target_version=<version>` where `<version>` is one of
`[py27, py36, py37, py38, py39]` to set the target version.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: we should probably not advertise specific versions here. I mean it's fine, but seems like another place to eventually get stale as we add support and drop support for older versions. Should be fine just to mention that it's the same argument as in the CLI, right? It would be a bit of an indirection though. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine just to mention that it's the same argument as in the CLI, right?

Yes, that would be better, and because of TAB completion, you get the correct list anyway. I'll change that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 👌

@felix-hilden felix-hilden removed the S: awaiting response Waiting for futher information from OP label Sep 23, 2021
@shaoran
Copy link
Contributor Author

shaoran commented Sep 27, 2021

So, what is the status of this merge request? Is it going to be merged?

@felix-hilden
Copy link
Collaborator

I'd say yes, but sadly I don't have commit access to the repo. I think if you agree that the conversation is resolved it's only a matter of time 👌

@shaoran
Copy link
Contributor Author

shaoran commented Sep 28, 2021

I'd say yes, but sadly I don't have commit access to the repo. I think if you agree that the conversation is resolved it's only a matter of time ok_hand

I hope so. Yesterday I had to merge it again with upstream because it was showing once again conflicts with upstream (luckily on the changelog). I'm afraid, that if it takes again weeks or even months (like when I created the pull request), my changes will be once again completely outdated and I would have to do it from scratch again.

@felix-hilden
Copy link
Collaborator

I feel you, sadly sometimes we're busy doing other things. But I'll try to push this to get resolved, and since it is pretty much done and big overhauls aren't planned, I think we're good 👍

@JelleZijlstra JelleZijlstra merged commit 09915f4 into psf:main Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: vim Vim plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants