JelleZijlstra / autotyping

Automatically add simple type annotations to your code
238 stars 20 forks source link

Improve CLI #55

Closed JelleZijlstra closed 7 months ago

JelleZijlstra commented 1 year ago

I would like users to be able to run just python -m autotyping --safe path/to/dir/ without having to go through setting up a LibCST config. Unfortunately libcst.tool is fairly rigid and I don't see a good way to do this while preserving the ability to pass other kinds of arguments that LibCST accepts directly. Perhaps there can be a simple mode that is just python -m autotyping and an advanced mode that allows more flexibility.

I'd be interested in user feedback about what kind of interface would be helpful.

TylerYep commented 1 year ago

Adding this to a pre-commit config would be fantastic. When adding types, it often helps to only auto-add types to affected files, and pre-commit makes it easy to choose those files only. Adding the .libcst.codemod.yaml file is the most painful part of using this tool.

JelleZijlstra commented 1 year ago

Definitely agree that would be useful. I don't think I'll have time to work on this soon but I'd accept a PR.

mstaczek commented 1 year ago

Integration with precommit does work, although a seemingly unnecessary .libcst.codemod.yaml is required:

generated_code_marker: '@generated'
modules:
- 'libcst.codemod.commands'
- 'autotyping'
repo_root: '.'

The following precommit hook does work for me:

repos:
-   repo: local
    hooks:
    - id: autotype_init
      name: autotype_init
      entry: python
      language: system
      types: [python]
      args: ["-m", "libcst.tool", "codemod", "--hide-progress",
             "autotyping.AutotypeCommand", "--annotate-magics"]
      require_serial: true

Current setup is not bad except my autotyping parameters are inside precommit yaml instead in the config file of newly added LibCST.

JelleZijlstra commented 7 months ago

@hauntsaninja fixed this in #65, thanks!