mkinit icon indicating copy to clipboard operation
mkinit copied to clipboard

Ignore some `__init__.py` files with `--recursive` flag

Open LEv145 opened this issue 4 years ago • 3 comments

I use mkinit with --recursive flag

Can I make to mkinit ignore some __init__.py files? I don't want these files to be generated automatically, I want to control them manually

LEv145 avatar Dec 07 '21 14:12 LEv145

In the current implementation no. In static_mkinit.py line 91 the logic for recursive is:

    if recursive:
        if submodules is not None:
            raise AssertionError("cannot specify submodules in recursive mode")
        all_init_fpaths = list(
            static.package_modpaths(modpath, with_pkg=True, with_mod=False)
        )
        all_init_fpaths = sorted(all_init_fpaths, key=lambda x: x.count(os.sep))
        for fpath in reversed(all_init_fpaths):
            autogen_init(
                fpath,
                submodules=None,
                respect_all=respect_all,
                options=options,
                dry=dry,
                diff=diff,
                recursive=False,
            )

There would need to be some logic that either removed or ignored the init files you want to control from the all_init_fpaths list. Not sure what the best implementation of that feature would be.

Perhaps we could add another user declaration "dunder" flag that tells mkinit to skip that file? Or we could pass in a list of files to skip, that seems unwieldy. I'm open to suggestions / PRs on this topic.

Erotemic avatar Dec 07 '21 16:12 Erotemic

Can to add comments that we add to the __init__.py file so that it is ignored (# pragma: no autogen)

Or can add the --strict parameter, which requires <AUTORUN_INIT>, or ignore it

LEv145 avatar Dec 07 '21 16:12 LEv145

I think the functionality is useful, not in all `init.py ' we need to import everything

LEv145 avatar Dec 17 '21 21:12 LEv145