mypy GHA
This commit is contained in:
parent
961dded20b
commit
8f8b2381df
10 changed files with 151 additions and 10 deletions
33
.github/workflows/mypy.yml
vendored
Normal file
33
.github/workflows/mypy.yml
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
name: Mypy Type Checking for CLI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- 'cli/**'
|
||||
|
||||
jobs:
|
||||
type-check-cli:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12.7'
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: ./cli
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install poetry
|
||||
poetry install
|
||||
|
||||
- name: Run mypy on whitelist
|
||||
working-directory: ./cli
|
||||
run: |
|
||||
mypy --config-file pyproject.toml @mypy_allowlist.txt
|
||||
33
.github/workflows/mypy_aiservice.yml
vendored
Normal file
33
.github/workflows/mypy_aiservice.yml
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
name: Mypy Type Checking for Aiservice
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- 'django/aiservice/**'
|
||||
|
||||
jobs:
|
||||
type-check-aiservice:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12.7'
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: ./django/aiservice
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install poetry
|
||||
poetry install
|
||||
|
||||
- name: Run mypy on whitelist
|
||||
working-directory: ./django/aiservice
|
||||
run: |
|
||||
mypy --config-file pyproject.toml @mypy_allowlist.txt
|
||||
|
|
@ -37,6 +37,20 @@ class AiServiceClient:
|
|||
) -> requests.Response:
|
||||
"""Make an API request to the given endpoint on the AI service.
|
||||
|
||||
Args:
|
||||
endpoint: The endpoint to call, e.g., "/optimize"
|
||||
method: The HTTP method to use ('GET' or 'POST')
|
||||
payload: Optional JSON payload to include in the POST request body
|
||||
timeout: The timeout for the request in seconds
|
||||
|
||||
Returns:
|
||||
The response object from the API
|
||||
|
||||
Raises:
|
||||
requests.exceptions.RequestException: If the request fails
|
||||
"""
|
||||
"""Make an API request to the given endpoint on the AI service.
|
||||
|
||||
:param endpoint: The endpoint to call, e.g., "/optimize".
|
||||
:param method: The HTTP method to use ('GET' or 'POST').
|
||||
:param payload: Optional JSON payload to include in the POST request body.
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ def is_github_app_installed_on_repo(owner: str, repo: str) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def get_blocklisted_functions() -> dict[str, set[str]]:
|
||||
def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
|
||||
"""Retrieve blocklisted functions for the current pull request.
|
||||
|
||||
Returns A dictionary mapping filenames to sets of blocklisted function names.
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ def inquirer_wrapper(func: Callable[..., str | bool], *args: str | bool, **kwarg
|
|||
new_kwargs = {}
|
||||
|
||||
if len(args) == 1:
|
||||
message = args[0]
|
||||
message = str(args[0])
|
||||
else:
|
||||
message = kwargs["message"]
|
||||
message = str(kwargs["message"])
|
||||
new_kwargs = kwargs.copy()
|
||||
split_messages = split_string_to_cli_width(message, is_confirm=func == inquirer.confirm)
|
||||
for split_message in split_messages[:-1]:
|
||||
|
|
@ -58,7 +58,7 @@ def split_string_to_cli_width(string: str, is_confirm: bool = False) -> list[str
|
|||
return lines
|
||||
|
||||
|
||||
def inquirer_wrapper_path(*args: str, **kwargs: str) -> dict[str, str]:
|
||||
def inquirer_wrapper_path(*args: str, **kwargs: str) -> dict[str, str] | None:
|
||||
new_args = []
|
||||
message = kwargs["message"]
|
||||
new_kwargs = kwargs.copy()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from codeflash.code_utils.shell_utils import read_api_key_from_shell_config
|
|||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_codeflash_api_key() -> Optional[str]:
|
||||
def get_codeflash_api_key() -> str:
|
||||
api_key = os.environ.get("CODEFLASH_API_KEY") or read_api_key_from_shell_config()
|
||||
if not api_key:
|
||||
raise OSError(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Union
|
||||
from typing import Union, Dict
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
|
@ -18,7 +18,7 @@ class PrComment:
|
|||
speedup_pct: str
|
||||
winning_test_results: TestResults
|
||||
|
||||
def to_json(self) -> dict[str, Union[str, dict[str, dict[str, int]]]]:
|
||||
def to_json(self) -> Dict[str, Union[str, Dict[str, Dict[str, int]], int, str]]:
|
||||
return {
|
||||
"optimization_explanation": self.optimization_explanation,
|
||||
"best_runtime": humanize_runtime(self.best_runtime),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from codeflash.version import __version__, __version_tuple__
|
|||
_posthog = None
|
||||
|
||||
|
||||
def initialize_posthog(enabled: bool) -> None:
|
||||
def initialize_posthog(enabled: bool = True) -> None:
|
||||
"""Enable or disable PostHog.
|
||||
:param enabled: Whether to enable PostHog.
|
||||
"""
|
||||
|
|
@ -18,7 +18,7 @@ def initialize_posthog(enabled: bool) -> None:
|
|||
return
|
||||
|
||||
global _posthog
|
||||
_posthog = Posthog(project_api_key="phc_aUO790jHd7z1SXwsYCz8dRApxueplZlZWeDSpKc5hol", host="https://us.posthog.com")
|
||||
_posthog = Posthog(project_api_key="phc_aUO790jHd7z1SXwsYCz8dRApxueplZlZWeDSpKc5hol", host="https://us.posthog.com") # type: ignore
|
||||
_posthog.log.setLevel(logging.CRITICAL) # Suppress PostHog logging
|
||||
ph("cli-telemetry-enabled")
|
||||
|
||||
|
|
@ -37,6 +37,6 @@ def ph(event: str, properties: Optional[Dict[str, Any]] = None) -> None:
|
|||
user_id = get_user_id()
|
||||
|
||||
if user_id:
|
||||
_posthog.capture(distinct_id=user_id, event=event, properties=properties)
|
||||
_posthog.capture(distinct_id=user_id, event=event, properties=properties) # type: ignore
|
||||
else:
|
||||
logger.debug("Failed to log event to PostHog: User ID could not be retrieved.")
|
||||
|
|
|
|||
35
cli/mypy_allowlist.txt
Normal file
35
cli/mypy_allowlist.txt
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
codeflash/tracing/tracing_utils.py
|
||||
codeflash/tracing/__init__.py
|
||||
codeflash/result/create_pr.py
|
||||
codeflash/result/__init__.py
|
||||
codeflash/result/explanation.py
|
||||
codeflash/result/critic.py
|
||||
codeflash/version.py
|
||||
codeflash/optimization/__init__.py
|
||||
codeflash/discovery/__init__.py
|
||||
codeflash/__init__.py
|
||||
codeflash/models/ExperimentMetadata.py
|
||||
codeflash/models/__init__.py
|
||||
codeflash/verification/__init__.py
|
||||
codeflash/github/__init__.py
|
||||
codeflash/github/PrComment.py
|
||||
codeflash/api/__init__.py
|
||||
codeflash/api/aiservice.py
|
||||
codeflash/api/cfapi.py
|
||||
codeflash/telemetry/__init__.py
|
||||
codeflash/telemetry/posthog_cf.py
|
||||
codeflash/main.py
|
||||
codeflash/code_utils/formatter.py
|
||||
codeflash/code_utils/compat.py
|
||||
codeflash/code_utils/github_utils.py
|
||||
codeflash/code_utils/__init__.py
|
||||
codeflash/code_utils/time_utils.py
|
||||
codeflash/code_utils/env_utils.py
|
||||
codeflash/code_utils/config_consts.py
|
||||
codeflash/code_utils/static_analysis.py
|
||||
codeflash/code_utils/remove_generated_tests.py
|
||||
codeflash/cli_cmds/console_constants.py
|
||||
codeflash/cli_cmds/logging_config.py
|
||||
codeflash/cli_cmds/__init__.py
|
||||
codeflash/cli_cmds/cli_common.py
|
||||
codeflash/cli_cmds/cli.py
|
||||
26
django/aiservice/mypy_allowlist.txt
Normal file
26
django/aiservice/mypy_allowlist.txt
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
optimizer/tests/postprocess_filter_test_helper.py
|
||||
optimizer/tests/__init__.py
|
||||
optimizer/__init__.py
|
||||
optimizer/code_utils/postprocess_constants.py
|
||||
optimizer/code_utils/__init__.py
|
||||
authapp/__init__.py
|
||||
authapp/tests.py
|
||||
testgen/models.py
|
||||
testgen/tests/test_testgen.py
|
||||
testgen/tests/__init__.py
|
||||
testgen/__init__.py
|
||||
testgen/instrumentation/tests/__init__.py
|
||||
testgen/instrumentation/__init__.py
|
||||
testgen/postprocessing/tests/__init__.py
|
||||
testgen/postprocessing/__init__.py
|
||||
log_features/__init__.py
|
||||
aiservice/middleware/__init__.py
|
||||
aiservice/tests/__init__.py
|
||||
aiservice/management/__init__.py
|
||||
aiservice/management/commands/__init__.py
|
||||
aiservice/__init__.py
|
||||
aiservice/models/__init__.py
|
||||
aiservice/models/functions_to_optimize.py
|
||||
aiservice/models/aimodels.py
|
||||
aiservice/analytics/__init__.py
|
||||
gunicorn.conf.py
|
||||
Loading…
Reference in a new issue