Skip to content

Commit

Permalink
Merge pull request #7 from Secrus/restore-project
Browse files Browse the repository at this point in the history
Refresh project
  • Loading branch information
sdispater authored Jul 27, 2022
2 parents de4bfbf + 6a8fa0d commit b17e3ef
Show file tree
Hide file tree
Showing 22 changed files with 485 additions and 572 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

14 changes: 12 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
[flake8]
min_python_version = 3.7.0
max-line-length = 88
ignore = E501, E203, W503
per-file-ignores = __init__.py:F401
ban-relative-imports = true
format-greedy = 1
inline-quotes = double
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E203: Whitespace before ':'
E203
per-file-ignores =
__init__.py:F401
exclude =
.git
__pycache__
Expand Down
68 changes: 26 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,58 @@ on:
- '**'

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7
architecture: x64
- uses: actions/checkout@master
- name: Install flake8
run: pip install flake8
- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: 'flake8'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run Black
uses: lgeiger/black-action@master
with:
args: --check crashtest/ tests/

tests:
runs-on: ubuntu-latest
name: ${{ matrix.os }} / ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
os: [Ubuntu, MacOS, Windows]
python-version: [3.7, 3.8, 3.9, "3.10"]

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
shell: bash
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
run: |
echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
- name: Install poetry
shell: bash
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py
python get-poetry.py -y
echo "::set-env name=PATH::$HOME/.poetry/bin:$PATH"
curl -sL https://install.python-poetry.org | python - -y
- name: Update PATH
if: ${{ matrix.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update PATH for Windows
if: ${{ matrix.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH

- name: Configure poetry
shell: bash
run: poetry config virtualenvs.in-project true
run: |
poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v2
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
run: imeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
shell: bash
Expand Down
52 changes: 45 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
repos:
- repo: https://github.com/psf/black
rev: stable
rev: 22.6.0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa
additional_dependencies: &flake8_deps
- flake8-broken-line==0.4.0
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10.0
- flake8-eradicate==1.2.1
- flake8-quotes==3.3.1
- flake8-simplify==0.19.2
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.0.3
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.3
- pep8-naming==0.13.0

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: *flake8_deps

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
exclude: ^.*/?setup\.py$
args: [--add-import, from __future__ import annotations]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
Expand All @@ -24,3 +41,24 @@ repos:
- id: end-of-file-fixer
exclude: ^tests/.*/fixtures/.*
- id: debug-statements

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: mypy
pass_filenames: false
additional_dependencies:
- pytest>=7.1.2

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.2
hooks:
- id: pyupgrade
args:
- --py37-plus

- repo: https://github.com/hadialqattan/pycln
rev: v2.0.4
hooks:
- id: pycln
args: [--all]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Crashtest

[![Tests](https://github.com/sdispater/crashtest/actions/workflows/tests.yml/badge.svg)](https://github.com/sdispater/crashtest/actions/workflows/tests.yml)
[![PyPI version](https://img.shields.io/pypi/v/crashtest)](https://pypi.org/project/crashtest/)

Crashtest is a Python library that makes exceptions handling and inspection easier.
3 changes: 3 additions & 0 deletions crashtest/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


__version__ = "0.3.1"
10 changes: 5 additions & 5 deletions crashtest/contracts/base_solution.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import List
from __future__ import annotations

from .solution import Solution
from crashtest.contracts.solution import Solution


class BaseSolution(Solution):
def __init__(self, title: str = None, description: str = None) -> None:
def __init__(self, title: str = "", description: str = "") -> None:
self._title = title
self._description = description
self._links = []
self._links: list[str] = []

@property
def solution_title(self) -> str:
Expand All @@ -18,5 +18,5 @@ def solution_description(self) -> str:
return self._description

@property
def documentation_links(self) -> List[str]:
def documentation_links(self) -> list[str]:
return self._links
10 changes: 7 additions & 3 deletions crashtest/contracts/has_solutions_for_exception.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from typing import List
from __future__ import annotations

from .solution import Solution
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from crashtest.contracts.solution import Solution


class HasSolutionsForException:
def can_solve(self, exception: Exception) -> bool:
raise NotImplementedError()

def get_solutions(self, exception: Exception) -> List[Solution]:
def get_solutions(self, exception: Exception) -> list[Solution]:
raise NotImplementedError()
8 changes: 7 additions & 1 deletion crashtest/contracts/provides_solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .solution import Solution
from __future__ import annotations

from typing import TYPE_CHECKING


if TYPE_CHECKING:
from crashtest.contracts.solution import Solution


class ProvidesSolution:
Expand Down
4 changes: 2 additions & 2 deletions crashtest/contracts/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations


class Solution:
Expand All @@ -11,5 +11,5 @@ def solution_description(self) -> str:
raise NotImplementedError()

@property
def documentation_links(self) -> List[str]:
def documentation_links(self) -> list[str]:
raise NotImplementedError()
19 changes: 11 additions & 8 deletions crashtest/contracts/solution_provider_repository.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from typing import List
from typing import Type
from __future__ import annotations

from .solution import Solution
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from crashtest.contracts.solution import Solution


class SolutionProviderRepository:
def register_solution_provider(
self, solution_provider_class: Type
) -> "SolutionProviderRepository":
self, solution_provider_class: type
) -> SolutionProviderRepository:
raise NotImplementedError()

def register_solution_providers(
self, solution_provider_classes: List[Type]
) -> "SolutionProviderRepository":
self, solution_provider_classes: list[type]
) -> SolutionProviderRepository:
raise NotImplementedError()

def get_solutions_for_exception(self, exception: Exception) -> List[Solution]:
def get_solutions_for_exception(self, exception: Exception) -> list[Solution]:
raise NotImplementedError()
21 changes: 14 additions & 7 deletions crashtest/frame.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import inspect
from __future__ import annotations

from types import FrameType
from typing import Dict
from typing import TYPE_CHECKING


if TYPE_CHECKING:
import inspect

from types import FrameType


class Frame:
_content_cache: Dict[str, str] = {}
_content_cache: dict[str, str] = {}

def __init__(self, frame_info: inspect.FrameInfo) -> None:
self._frame = frame_info.frame
Expand All @@ -14,7 +19,7 @@ def __init__(self, frame_info: inspect.FrameInfo) -> None:
self._filename = frame_info.filename
self._function = frame_info.function
self._lines = None
self._file_content = None
self._file_content: str | None = None

@property
def frame(self) -> FrameType:
Expand Down Expand Up @@ -47,7 +52,7 @@ def file_content(self) -> str:
else:
if self._filename not in self.__class__._content_cache:
try:
with open(self._filename) as f:
with open(self._filename, encoding="utf-8") as f:
file_content = f.read()
except OSError:
file_content = ""
Expand All @@ -63,7 +68,9 @@ def file_content(self) -> str:
def __hash__(self) -> int:
return hash(self._filename) ^ hash(self._function) ^ hash(self._lineno)

def __eq__(self, other: "Frame") -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Frame):
raise NotImplementedError
return (
self._filename == other.filename
and self._function == other.function
Expand Down
17 changes: 11 additions & 6 deletions crashtest/frame_collection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any
from typing import List
from typing import Optional

from .frame import Frame

if TYPE_CHECKING:
from crashtest.frame import Frame


class FrameCollection(list):
def __init__(self, frames: Optional[List[Frame]] = None, count: int = 0) -> None:
class FrameCollection(List[Any]):
def __init__(self, frames: list[Frame] | None = None, count: int = 0) -> None:
if frames is None:
frames = []

Expand All @@ -20,12 +25,12 @@ def repetitions(self) -> int:
def is_repeated(self) -> bool:
return self._count > 1

def increment_count(self, increment: int = 1) -> "FrameCollection":
def increment_count(self, increment: int = 1) -> FrameCollection:
self._count += increment

return self

def compact(self) -> List["FrameCollection"]:
def compact(self) -> list[FrameCollection]:
"""
Compacts the frames to deduplicate recursive calls.
"""
Expand Down
Loading

0 comments on commit b17e3ef

Please sign in to comment.