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

How to configure within pre-commit #2

Open
Borda opened this issue Aug 2, 2021 · 5 comments
Open

How to configure within pre-commit #2

Borda opened this issue Aug 2, 2021 · 5 comments

Comments

@Borda
Copy link

Borda commented Aug 2, 2021

Hello,
I was testing this extension and it seems that it does not follow the Black configuration from pyproject.toml which is

[tool.black]
line-length = 120
skip-magic-trailing-comma = true

the pre-commit configuration is:

  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.7
    hooks:
      - id: mdformat
        additional_dependencies:
          - mdformat-gfm
          - mdformat-black
          - mdformat_frontmatter

see sample here: Lightning-AI/pytorch-lightning#8673 (comment)

@hukkin
Copy link
Owner

hukkin commented Aug 2, 2021

Hey!

You're correct that this plugin (or more accurately Black used by this plugin) is currently not configurable. It always runs using whatever defaults Black's API has.

I'm currently not sure if we should change this or not. It may not be a great idea for mdformat to read another tools configuration file. Also I don't think Black provides API to do that. Of course it'd be possible to invoke Black CLI tool directly...

There could also be use cases where reading the configuration for docs is not preferable.

These are just my initial thougts, not exactly sure what to do here.

@Borda
Copy link
Author

Borda commented Aug 2, 2021

well I think it would be nice to be able to specify the Black version which is used by this plugin (or write to readme how t do it) and ideally, load config the same way as Black does - loading config file if it exists otherwise use defaults... that it is kind of more predictable... at least you have the same Black formatting in your codebase as well as the markdown files... 🐰

@Borda
Copy link
Author

Borda commented Aug 3, 2021

how about using this one? https://github.com/asottile/blacken-docs

@hukkin
Copy link
Owner

hukkin commented Aug 3, 2021

Integrating blacken-docs doesn't make much sense IMO. It's a tool that does more or less the same thing as mdformat-black with just a few differences:

  • mdformat-black is obviously tightly coupled with mdformat
  • blacken-docs supports other doc formats besides Markdown
  • mdformat-black should be better at finding code blocks in Markdown as it uses a proper Markdown parser instead of a regex like blacken-docs

blacken-docs formats using Black's API exactly the same way as mdformat-black and also does not read Black's config for similar reasons.

@hukkin
Copy link
Owner

hukkin commented Aug 3, 2021

well I think it would be nice to be able to specify the Black version which is used by this plugin

This you can do simply by installing the Black version that you want to use. To configure with pre-commit, use additional_dependencies:

  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.8
    hooks:
      - id: mdformat
        additional_dependencies:
          - mdformat-black
          - black==21.7b0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants