Skip to content
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

Support external-dependencies in pyright #9434

Merged
merged 22 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 11 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements-tests.txt
- run: |
pip install tomli pathspec packaging
DEPENDENCIES=$(python tests/get_external_dependencies.py)
if [ -n "$DEPENDENCIES" ]; then
pip install $DEPENDENCIES
fi
- name: Get pyright version
uses: SebRollen/toml-action@v1.0.2
id: pyright_version
Expand Down
16 changes: 16 additions & 0 deletions tests/get_external_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
from __future__ import annotations

import os
import sys

from utils import read_dependencies

distributions = sys.argv[1:]

if not distributions:
distributions = os.listdir("stubs")

for distribution in distributions:
for package in read_dependencies(distribution).external_pkgs:
print(f"{package} ")
2 changes: 1 addition & 1 deletion tests/get_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
for distribution in distributions:
with open(f"stubs/{distribution}/METADATA.toml", "rb") as file:
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []):
print(package)
print(f"{package} ")
32 changes: 20 additions & 12 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@
import subprocess
import sys
import venv
from collections.abc import Mapping
from functools import cache
from pathlib import Path
from typing import NamedTuple
from typing_extensions import Annotated
from typing import TYPE_CHECKING, NamedTuple

import pathspec # type: ignore[import]
import tomli
from packaging.requirements import Requirement

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping
from typing_extensions import Annotated

try:
from termcolor import colored as colored
except ImportError:

def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str:
return text


if sys.version_info >= (3, 9):
from functools import cache
else:
from functools import lru_cache

cache = lru_cache(maxsize=None)

# Used to install system-wide packages for different OS types:
METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}

Expand All @@ -25,14 +41,6 @@ def strip_comments(text: str) -> str:
return text.split("#")[0].strip()


try:
from termcolor import colored as colored
except ImportError:

def colored(s: str, _: str) -> str: # type: ignore[misc]
return s


def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None:
error_split = error.split("\n")
old, new = fix_path
Expand Down