Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rshunim committed Nov 19, 2024
1 parent c70a611 commit 2d0a880
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions demisto_sdk/scripts/monkeytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@


def monkeytype(path: Path):
"""
This function runs monkeytype on the Python files in the path's folder.
It knows how to identify variable types and recommends adding typing according to the tests.
"""
if path.is_file():
path = path.parent
runner_path = path / "runner.py" # a temporary file, generated at runtime, solving an issue where MonkeyType can't run on files outside of python packages
runner_path = path / "runner.py" # a temporary file, generated at runtime,
# solving an issue where MonkeyType can't run on files outside of python packages
python_path = ":".join(str(path_) for path_ in PYTHONPATH + [path])
env = os.environ.copy() | {"PYTHONPATH": os.environ["PYTHONPATH"] + ":" + python_path}
env = os.environ.copy() | {
"PYTHONPATH": os.environ["PYTHONPATH"] + ":" + python_path
}
subprocess.run(
[
"pytest",
Expand All @@ -22,26 +29,29 @@ def monkeytype(path: Path):
env=env,
cwd=path,
)
modules = subprocess.run( # list the python files to run on (usually `<integration>.py` and `test_<integration>.py`)
modules = subprocess.run(
# list the python files to run on (usually `<integration>.py` and `test_<integration>.py`)
["monkeytype", "list-modules"],
text=True,
check=True,
capture_output=True,
cwd=path,
env=env,
).stdout.splitlines()
filtered_modules = set(modules).difference(("demistomock", "CommonServerPython")) # we don't want to run monkeytype on these
filtered_modules = set(modules).difference(
("demistomock", "CommonServerPython")
) # we don't want to run monkeytype on these
runner_path.write_text(
"\n".join(f"import {module}\n{module}.main()" for module in filtered_modules)
)
for module in filtered_modules: # actually run monkeytype on each module
for module in filtered_modules: # actually run monkeytype on each module
subprocess.run(
["monkeytype", "-v", "stub", module], check=True, cwd=path, env=env
)
subprocess.run(
["monkeytype", "-v", "apply", module], check=True, cwd=path, env=env
)
runner_path.unlink() # that was a temporary file we no longer need
runner_path.unlink() # that was a temporary file we no longer need


def main():
Expand Down

0 comments on commit 2d0a880

Please sign in to comment.