conda-forge / conda-smithy

The tool for managing conda-forge feedstocks.
https://conda-forge.org/
BSD 3-Clause "New" or "Revised" License
146 stars 169 forks source link

Implement typings in conda-smithy #1957

Open ninetteadhikari opened 2 weeks ago

ninetteadhikari commented 2 weeks ago

Introduction

This work is done according to "Milestone 2: Implement typings in conda-smithy" as stated in the Scope of Work with Sovereign Tech Fund (STF) (https://www.sovereigntechfund.de/).

This PR addresses the typing request from this issue

Setup

Setup details are here: https://github.com/neighbourhoodie/conda-smithy/wiki

Steps followed to add type

As suggested in the ticket in the conda-smithy repo, MonkeyType is used to generate type hints for the python code.

Generate type hints

  1. Install MonkeyType

    pip install MonkeyType
  2. Run tests using MonkeyType. This will dump call traces into a SQLite database in the file monkeytype.sqlite3 in the current working directory.

    monkeytype run -m pytest
  3. Make a separate folder called stubs to save the type hint files

    mkdir stubs
  4. Generate stub files for each of the modules found in the SQLite database

    monkeytype list-modules | xargs -n1 -I{} sh -c 'monkeytype stub {} > stubs/{}.pyi'

    The above command will create stub files in the stubs folder. Here's an example of what the content of a stub file will look like. It gives suggestions for types.

    def rotate_anaconda_token(
    user: str,
    project: str,
    feedstock_config_path: Optional[str],
    drone: bool = ...,
    circle: bool = ...,
    travis: bool = ...,
    azure: bool = ...,
    appveyor: bool = ...,
    github_actions: bool = ...,
    token_name: str = ...,
    drone_endpoints: List[str] = ...
    ): ...
  5. The suggestions generated in the stub file were used make changes to the actual python code.

Checklist