Skip to content

Black is not properly used on write_cells #1545

@yasirroni

Description

@yasirroni

Provide a minimally reproducible example

Just run nbdev_export with settings.ini we use black_formatting = False. The __all__ that is produced didn't follow black format.

The problem stems from the fact that the code in config and maker regarding write_cells:

    # write out the file
    with (dest/name).open('w',encoding="utf-8") as f:
        f.write(f"# %% auto 0\n__all__ = {exp_funcs}")
        write_cells(cells, f"# %% {fname.relpath(dest)}", f)
        f.write('\n')
    with self.fname.open('w', encoding="utf-8") as f:
        f.write(_retr_mdoc(cells))
        f.write(f"# AUTOGENERATED! DO NOT EDIT! File to edit: {self.dest2nb}.")
        if last_future > 0: write_cells(cells[:last_future], self.hdr, f)
        if self.parse and not self.solo_nb: f.write(f"\n\n# %% auto 0\n__all__ = {all_str}")
        write_cells(cells[last_future:], self.hdr, f, cell_number=get_config().cell_number, solo_nb=self.solo_nb)
        f.write('\n')

We can see that it always use single quote ' ', even when in settings.ini we use black_formatting = False.

Expected behavior is it follows formatting too.


Proposal: change formatter runner to run per-file basis, both the .ipynb and .py files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions