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

Use Ruff, fix various tests #92

Merged
merged 7 commits into from
Feb 13, 2024
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
48 changes: 24 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ jobs:
name: Build and publish Python distributions to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
26 changes: 13 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
38 changes: 28 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
language_version: python3.9

ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: false
language_version: python3.12

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies:
- types-requests
- aiohttp
exclude: ^(typeshed_client/typeshed|tests/(site-packages|typeshed))/

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ call ``resolver.get_fully_qualified_name('collections.Set')`` to retrieve the
Changelog
---------

Unreleased

- Drop support for Python 3.7
- ``typeshed_client.finder.get_search_path()`` is now deprecated, as it is no longer useful

Version 2.4.0 (September 29, 2023)

- Update bundled typeshed
Expand Down
40 changes: 39 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target_version = ['py37', 'py38', 'py39', 'py310', 'py311']
target_version = ['py38', 'py39', 'py310', 'py311', 'py312']
include = '\.pyi?$'
skip-magic-trailing-comma = true
preview = true
Expand Down Expand Up @@ -50,7 +50,45 @@ disallow_any_decorated = true

exclude = [
"typeshed_client/typeshed",
"tests/site-packages",
"tests/typeshed",
"build/",
"thirdparty",
".tox/",
]

[tool.ruff]

line-length = 100
target-version = "py38"
preview = true
unsafe-fixes = true

exclude = [
"typeshed_client/typeshed",
"tests/typeshed",
"build/",
".tox/",
]

[tool.ruff.lint]
select = [
"F",
"E",
"I", # import sorting
"ANN", # enforce type annotations
"C4", # flake8-comprehensions
"B", # bugbear
"SIM", # simplify
"UP", # pyupgrade
"PIE",
"PERF",
"RUF", # Ruff's own rules
]

ignore = [
"ANN101", # missing type annotation for self in method
"ANN102", # missing type annotation for cls in classmethod
"SIM105", # I don't like contextlib.suppress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always ignore UP038 because of astral-sh/ruff#7871, though it doesn't make much of a difference here since the rule only does things if your lowest supported version is Python 3.10

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree with you there, adding support for isinstance() with UnionType was a questionable design choice in the first place. I'll add it to the exclude list and see if I still agree in two years' time when 3.9 goes EOL :)

"UP038", # astral-sh/ruff#7871
]
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ast
import os
from pathlib import Path
import re
from pathlib import Path
from typing import Iterable
from setuptools import setup

from setuptools import setup

current_dir = Path(__file__).parent.resolve()
ts_client_dir = current_dir / "typeshed_client"
Expand Down Expand Up @@ -46,7 +46,7 @@ def find_bundled_files() -> Iterable[str]:
},
license="MIT",
packages=["typeshed_client"],
install_requires=["importlib_resources >= 1.4.0"],
install_requires=["importlib_resources >= 1.4.0", "typing-extensions>=4.5.0"],
package_data={"typeshed_client": list(find_bundled_files())},
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
22 changes: 14 additions & 8 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from pathlib import Path
import ast
import unittest
from pathlib import Path
from typing import Any, Optional, Set, Type
from unittest import mock

import typeshed_client
from typeshed_client.finder import (
get_search_context,
ModulePath,
PythonVersion,
get_stub_file,
SearchContext,
ModulePath,
get_search_context,
get_stub_file,
)
from typeshed_client.parser import get_stub_names
from typing import Any, Set, Type, Optional
from unittest import mock
import unittest

TEST_TYPESHED = Path(__file__).parent / "typeshed"
PACKAGES = Path(__file__).parent / "site-packages"
Expand Down Expand Up @@ -334,7 +335,12 @@ def test(self) -> None:
ctx = get_search_context(raise_on_warnings=True)
for module_name, module_path in typeshed_client.get_all_stub_files(ctx):
with self.subTest(path=module_name):
ast = typeshed_client.get_stub_ast(module_name, search_context=ctx)
try:
ast = typeshed_client.get_stub_ast(module_name, search_context=ctx)
except SyntaxError:
# idlelib for some reason ships an example stub file with a syntax error.
# typeshed-client should also throw a SyntaxError in this case.
continue
assert ast is not None
is_init = module_path.name == "__init__.pyi"
typeshed_client.parser.parse_ast(
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ commands =

[testenv:black]
deps =
black == 24.1.1
black == 24.2.0
commands =
black --check .

Expand All @@ -22,9 +22,8 @@ commands =

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311, black, mypy
3.12: py312
3.11: py311
3.12: py312, black, mypy
37 changes: 16 additions & 21 deletions typeshed_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
"""Package for retrieving data from typeshed."""

from . import finder
from . import parser
from . import resolver

# Exported names
from .finder import (
get_stub_ast,
get_stub_file,
ModulePath,
SearchContext,
get_all_stub_files,
get_search_context,
SearchContext,
ModulePath,
get_stub_ast,
get_stub_file,
)
from .parser import (
get_stub_names,
parse_ast,
ImportedName,
NameDict,
NameInfo,
OverloadedName,
get_stub_names,
parse_ast,
)
from .resolver import ImportedInfo, Resolver


__version__ = "2.4.0"


__all__ = [
"__version__",
"get_stub_ast",
"get_stub_file",
"get_all_stub_files",
"get_search_context",
"SearchContext",
"ModulePath",
"get_stub_names",
"parse_ast",
"ImportedInfo",
"ImportedName",
"ModulePath",
"NameDict",
"NameInfo",
"OverloadedName",
"ImportedInfo",
"Resolver",
"SearchContext",
"__version__",
"get_all_stub_files",
"get_search_context",
"get_stub_ast",
"get_stub_file",
"get_stub_names",
"parse_ast",
]
Loading
Loading