Skip to content

Add changes for numpy into report #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
typecheck:
runs-on: ubuntu-latest

steps:
# Check out the repository
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Set up Python 3.12
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.12'

# Install Python dependencies and run tests
- name: Install dependencies and run pytest
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
# Install your dependencies; adjust the following lines as needed
pip install -r requirements.txt
Expand All @@ -43,3 +45,7 @@ jobs:
# Run Pyright type checking
- name: Run Pyright
run: pyright

# Run Pyrefly type checking
- name: Typecheck with Pyrefly
run: .venv/bin/pyrefly check
11 changes: 11 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- id: pyrefly-typecheck
name: pyrefly check
entry: pyrefly check
skip_install: true
types_or: [python, pyi]
language: system
pass_filenames: false # Pyrefly reads config & project roots itself
args: []
require_serial: true
additional_dependencies: []
minimum_pre_commit_version: "2.9.2"
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ Run daily command for prioritized list:

### Type check the project (of course!)

Pyright
We use [Pyrefly](https://pyrefly.org/) to check the project. You can also use the accompanying IDE extension in [VSCode](https://marketplace.visualstudio.com/items?itemName=meta.pyrefly).

`$ node node_modules/pyright/index.js`
`$ pyrefly check`

Or simply install globally

`$ npm i -g pyright`
`$ pyright`
1 change: 1 addition & 0 deletions analyzer/coverage_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def calculate_parameter_coverage(files: list[str]) -> tuple[int, int, int]:

# Exclude 'self' and 'cls' from parameters
params = [
# pyrefly: ignore # missing-attribute
arg for arg in node.args.args if arg.arg not in ('self', 'cls')]
param_count = len(params)
annotation_count = sum(
Expand Down
4 changes: 2 additions & 2 deletions badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def check_typed_classifier(package_name: str) -> tuple[bool, bool]:
badge_total = 0
stubs_only_total = 0

non_badge: defaultdict[tuple[bool, bool, bool, bool, bool], list[str]] = defaultdict(list)
badge: defaultdict[tuple[bool, bool, bool, bool, bool], list[str]] = defaultdict(list)
non_badge = defaultdict[tuple[bool, bool, bool, bool, bool], list[str]](list)
badge = defaultdict[tuple[bool, bool, bool, bool, bool], list[str]](list)
for package, package_info in package_report.items():
has_typed_classifier, has_stubs_only_classifier = check_typed_classifier(package)
key = (package_info["HasPyTypedFile"], package_info["HasTypeShed"], package_info["HasStubsPackage"], package.startswith("types-") or package.endswith("-stubs"), has_stubs_only_classifier)
Expand Down
21 changes: 18 additions & 3 deletions coverage_sources/get_pyright_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import os
import subprocess
from typing import Any, Dict, Union
from fnmatch import fnmatch

EXCLUDE_LIKE: Dict[str, str] = {
'numpy': '*.tests.*',
}


def create_output_directory(output_dir: str) -> None:
Expand Down Expand Up @@ -66,13 +71,23 @@ def run_pyright(venv_name: str, package: str, output_file: str) -> None:
print(f"Output: {e.output}")


def parse_output_json(output_file: str) -> Dict[str, Union[int, float]]:
def parse_output_json(output_file: str, exclude_like: str | None = None) -> Dict[str, Union[int, float]]:
try:
with open(output_file, "r") as f:
output_data = json.load(f)
pyright_data: Dict[str, Union[int, float]] = {}

symbol_count = output_data["typeCompleteness"]["exportedSymbolCounts"]
coverage: float = output_data["typeCompleteness"]["completenessScore"] * 100.0
if exclude_like is None:
coverage: float = output_data["typeCompleteness"]["completenessScore"] * 100.0
else:
matched_symbols = [
x for x in output_data["typeCompleteness"]["symbols"] if not fnmatch(x["name"], exclude_like)
and x['isExported']
]
coverage = (
sum(x["isTypeKnown"] for x in matched_symbols) / len(matched_symbols) * 100
)

pyright_data = symbol_count
pyright_data["coverage"] = coverage
Expand Down Expand Up @@ -133,7 +148,7 @@ def main(packages: list[dict[str, Any]]) -> Dict[str, Any]:

output_file = f"{output_dir}/{package}_output.json"
run_pyright(venv_name, package, output_file)
pyright_data = parse_output_json(output_file)
pyright_data = parse_output_json(output_file, EXCLUDE_LIKE.get(package, None))

stats[package] = pyright_data

Expand Down
18 changes: 18 additions & 0 deletions pyrefly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pyrefly.toml

# Let's include everything so commenting out
# project_includes = ["./**/*.py"]

project_excludes = [
"**/node_modules/**",
"**/__pycache__/**",
"**/.git/**",
"**/venv/**",
"**/.venv/**",
"typeshed/**",
"tests/test_files/**"
]

site_package_path = [
".venv/lib/python3.12/site-packages/"
]
2 changes: 0 additions & 2 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"typeshed",
"tests/test_files/*"
],
"reportMissingTypeStubs": true,
"reportMissingImports": true,
"typeCheckingMode": "strict",
"venv": ".venv",
"venvPath": "."
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ requests>=2.25.1
jinja2
pyright>=1.1.387
tabulate
pyrefly
2 changes: 1 addition & 1 deletion tests/test_get_pyright_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ def test_main(tmp_path: Path) -> None:
mock_activate_install.assert_called_once_with(expected_venv, "test_package")
mock_create_py_typed.assert_called_once_with(expected_py_typed)
mock_run_pyright.assert_called_once_with(expected_venv, "test_package", expected_output_file)
mock_parse_json.assert_called_once_with(expected_output_file)
mock_parse_json.assert_called_once_with(expected_output_file, None)
mock_subprocess_run.assert_called()
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tempfile
import os
import sys
import requests
import requests.exceptions
from typing import Any, Optional

# Add the directory containing main.py to sys.path
Expand Down