joeld1 / monkeytype-helpers

Use PyCharm to generate a git patch resulting from running: monkeytype run, monkeytype apply --ignore-existing, isort, pyment, and black

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MonkeyType Helpers

Description

This repo contains a few snippets that allow one to use apply MonkeyType onto modules within PyCharm by using the ExternalTools functionality within PyCharm.

Purpose

This was created in order to quickly be able to perform the following:

  1. Infer and add types/annotations onto methods that are not typed properly
    • Note: I currently don't know how to use stubs to generate patches to apply, if someone knows, please do leave a comment, so I can apply it :)!
  2. Use the recently generated/corrected method return types and signatures to create patches which contain also contain reformatted docstrings

Notes

  • This external tool makes a backup in the same folder of the associated script/module/.py file being imported from the script the external tool is running on.
    • I'm not sure how this external tool reacts to improperly formatted .py files, or folders where one does not have write permissions.
  • Pyment re-formats to reST docstrings, but you can change this and other Pyment settings in monkeytype_run.py to fit your needs.
  • Delete the patches found in the patches folder, and run the test test_monkeytype_run.py if you're interested in testing/stepping through the code.
    • You can also test the pycharm external tool by running it on the modules found in this repo.

Walkthrough of Setup

  1. Clone repo

  2. Install the following dependencies:

    • monkeytype
    • black
    • isort
    • pyment (use the github version since the pypi version isn't updated)
    • pytest
  3. Follow steps in images below

  4. Create a PyCharm External Tool (Might differ for PCs)

    image text

    • Note, you can hard-code to a specific interpreter, but make sure that that interpreter contains all dependencies found on the script you are running the external tool on
    • In this example, the script path is hard-coded image text
  5. Right-Click and Run External Tool on Module of Interest

    image text

  6. Select Project Directory the script is a part of (this will contain your monkeytype.sqlite3 db, and your script/package/module must be found somewhere (nested or not) in this folder)

    image text

    image text

    • Example output shown above

    image text

    • Patch for import dependency shown in red on left panel above
  7. Right-Click on Patch, Select Apply Patch

    image text

  8. Select File to Patch and Click on Show Difference

    image text

  9. Merge Desired Changes =)

    image text

About

Use PyCharm to generate a git patch resulting from running: monkeytype run, monkeytype apply --ignore-existing, isort, pyment, and black


Languages

Language:Python 100.0%