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

use format parsing libraries instead of custom line based parsing #32

Closed
keewis opened this issue Jun 25, 2020 · 3 comments
Closed

use format parsing libraries instead of custom line based parsing #32

keewis opened this issue Jun 25, 2020 · 3 comments

Comments

@keewis
Copy link
Owner

keewis commented Jun 25, 2020

Right now blackdoc goes through the lines one by one, tries to extract code, format the code using black, then put everything back together. While this does work, extending to different file formats becomes difficult, especially when trying to extend to jupyter notebooks (json files).

There are a lot of libraries for parsing the currently supported formats (or the planned formats):

this might come with the disadvantage of slower reading since e.g. docutils does more than just reading code blocks, but using those might make the tool a bit more robust and easier to extend to new formats. Another disadvantage is that right now we're reading the files only once but we might have to read at least docstrings more often (that is if we don't restrict python files to doctest -- should be possible, rst in docstrings is rare).

@keewis
Copy link
Owner Author

keewis commented Nov 4, 2020

thinking about this again, maybe we don't have to do that? There's lots of utilities that apply black to notebooks, so we don't have to add that. markdown support would be nice, but that should be somewhat similar to rst support. We're also reading files only once: every line is classified and the appropriate extraction / reformatting functions are called, in sequence.

@keewis
Copy link
Owner Author

keewis commented Aug 8, 2021

since those libraries are fundamentally different from how the tool currently works (especially docutils), using those would require a rewrite, which I'm not prepared to do (and the main motivation, notebook support, can be done using other tools, e.g. nbQA).

Instead, markdown support will have to be implemented in a new blackdoc.formats module.

@keewis keewis closed this as completed Aug 8, 2021
@MarcoGorelli
Copy link

MarcoGorelli commented Aug 8, 2021

the main motivation, notebook support, can be done using other tools, e.g. nbQA

Just FYI - hopefully, soon, this won't even require extra tools psf/black#2357

The black.format_cell function may even help here in blackdoc

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