Code Monkey home page Code Monkey logo

monkeytype-helpers's Introduction

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

monkeytype-helpers's People

Contributors

joeld1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.