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/issue 414: vim plugin respects pyproject.toml config #589
Conversation
Creates two separate functions: 1) abspath_pyproject_toml: find the absolute path to pyproject.toml 2) parse_pyproject_toml: finds black-specific toml config
I thought `pwd` would be sufficient, but needed fnamemodify(getcwd(), ':t') to get the full cwd path
Pull Request Test Coverage Report for Build 787
💛 - Coveralls |
1 similar comment
Pull Request Test Coverage Report for Build 787
💛 - Coveralls |
would be good to reach a conclusion, one way or the other, on #416 before making very much change to the Vim plugin. |
Super excited to get this merged in! I have to stop using the plugin for now because I have project-specific configs which differ from the defaults. I feel like a pleb having to run the command from the CLI. . . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in reviewing this! I left a few comments.
@@ -138,6 +138,23 @@ def from_configuration( | |||
return mode | |||
|
|||
|
|||
def abspath_pyproject_toml(path_search_start: str) -> Optional[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like find_pyproject_toml
would be a better name for this function. Also, why does it return a str instead of a Path?
except Exception as exc: | ||
config_pyproject_toml = {} | ||
|
||
toml_line_length = config_pyproject_toml.get("line_length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not great that we have to hardcode all of these options here. Is there any way to avoid having separate code for each option? (Relatedly, #618 will change a few of these.)
path_pyproject_toml = black.abspath_pyproject_toml(vim.eval("fnamemodify(getcwd(), ':t')")) | ||
try: | ||
config_pyproject_toml = black.parse_pyproject_toml(path_pyproject_toml) | ||
except Exception as exc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching any Exception is bad practice. What errors is this looking for specifically?
@JelleZijlstra no worries! Unfortunately, given the lack of configuration options for black, I've stopped using it. Additionally, given the amount of time I spent looking elsewhere for something that respects the pyproject.toml, I ended up writing my own vim formatting plugin that does everything I want for every language. Feel free to close this pull request, or use it as a jumping off point in case you're interested in its content. Totally agree with your comments regarding exception handling, and with hardcoding options... see my plugin for a well-functioning alternative on POSIX-like systems and apologies for the rush job. |
it looks like this PR is now stale.. any plans to add support for respecting pyproject.toml in the official black.vim plugin? |
@anthrotype if you are on a Unix-like system, my auto-formatting plugin has worked well for me. To use black for Python, just use the string "black -q -" when configuring. |
Several suggestions in this comment, in which I propose that it doesn't make a lot of sense to maintain a vim plugin in this repository. Personally I just use |
Thanks both, I’ll have a look! |
@ambv, @JelleZijlstra, @pappasam, #1273 has been merged in stead of this one. |
This pull request makes the Vim plugin respect pyproject.toml without changing any public interfaces (resolves #414)
I pulled some functionality out of read_pyproject_toml and put it into 2 separate functions: abspath_pyproject_toml and parse_pyproject_toml. These are used by the vim plugin to find and read a relevant pyproject.toml according the the already-established rules of the project.
Regarding tests
I did not yet add tests for this modification; the original function (read_pyproject_toml) was not explicitly tested and I'm unsure what the preferred testing location would be for a bunch of pyproject.toml files.
I did run the tests using the technique recommended in the contributing guidelines and no existing tests break.