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

Passing "pyproject.toml" when calling black using the API #3177

Closed
khrynczenko opened this issue Jul 18, 2022 · 2 comments
Closed

Passing "pyproject.toml" when calling black using the API #3177

khrynczenko opened this issue Jul 18, 2022 · 2 comments
Labels
C: api One day Black will have an API ... C: configuration CLI and configuration

Comments

@khrynczenko
Copy link

Hello,
I am trying to use black as a library and so far so good. It is easy to just call black.format_str(code_block, mode=Mode()) but I would like to pass a configuration as an argument as well. Is there any way I can create Mode object from a pyproject.toml file? Preferably I would like not to parse the file myself and create Mode object manually. So far I could find anything related to such thing inside the source code.

TLDR: I would like to call black.format_str in a way that it uses a pyproject.toml configuration specified by myself.

@khrynczenko
Copy link
Author

After digging more I found the parse_pyproject_toml function inside black which returns a dictionary but this will just return a dictionary with all key-values under [tool.black] section. I would still need to filter that dictionary for keys/values that Node constructor accepts but I guess it is feasible. Maybe there are some other better alternatives?

BTW.
black has a great documentation for its CLI api but I could not find much when it comes to library API. I only found the Contributing section. Is there something else?

@JelleZijlstra
Copy link
Collaborator

We don't currently have a documented API; #779 is tracking that. Closing as you've solved your immediate problem and #779 tracks the bigger enhancement request.

@ichard26 ichard26 added C: configuration CLI and configuration C: api One day Black will have an API ... labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: api One day Black will have an API ... C: configuration CLI and configuration
Projects
None yet
Development

No branches or pull requests

3 participants