Skip to content

Commit

Permalink
Merge pull request #74 from Indicio-tech/feature/ruff
Browse files Browse the repository at this point in the history
feat: use ruff instead of flake8
  • Loading branch information
dbluhm authored Sep 5, 2023
2 parents cbcc523 + 1ecf685 commit 2aa157f
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 572 deletions.
27 changes: 4 additions & 23 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@ on:

jobs:
format:
name: Formatting
name: Format and Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Cache python environment
id: cache-env
uses: actions/cache@v3
- uses: psf/black@stable
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-formatting-black-23.7.0
- name: Install black
if: steps.cache-env.outputs.cache-hit != 'true'
run: |
pip install black==23.7.0
- name: Black Format Check
run: |
black --check pydid
src: "./pydid"
- uses: chartboost/ruff-action@v1

test:
name: Tests
Expand All @@ -48,11 +35,5 @@ jobs:
cache: poetry
- name: Install dependencies
run: poetry install
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run pytest
run: poetry run pytest
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ repos:
hooks:
- id: black
stages: [commit]
- repo: https://github.com/pycqa/flake8
rev: 3.9.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
hooks:
- id: flake8
- id: ruff
stages: [commit]
args: [--fix, --exit-non-zero-on-fix]
871 changes: 343 additions & 528 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pydid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""PyDID"""
"""PyDID."""

import logging
from typing import Callable, List, Optional, Type
Expand Down
3 changes: 3 additions & 0 deletions pydid/doc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
id_base: str = None,
methods: Optional[List[VerificationMethod]] = None
):
"""Initialize builder."""
self._did = did
self.methods = methods or []
self._id_base = id_base or "key"
Expand Down Expand Up @@ -65,6 +66,7 @@ def __init__(
*,
methods: Optional[List[Union[VerificationMethod, DIDUrl]]] = None
):
"""Initialize builder."""
super().__init__(did, id_base=id_base)
self.methods = methods or []

Expand Down Expand Up @@ -101,6 +103,7 @@ class ServiceBuilder:
"""Builder for services."""

def __init__(self, did: DID, *, services: Optional[List[Service]] = None):
"""Initialize builder."""
self._did = did
self.services = services or []
self._id_generator = _default_id_generator("service", start=len(self.services))
Expand Down
3 changes: 1 addition & 2 deletions pydid/doc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def dereference(self, reference: Union[str, DIDUrl]) -> Resource:


class DIDDocument(BasicDIDDocument):
"""
DID Document for DID Spec version 1.0.
"""DID Document for DID Spec version 1.0.
Registered verification method and service types are parsed into specific objects.
"""
Expand Down
1 change: 1 addition & 0 deletions pydid/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class IndexedResource(Resource, ABC):
_index: dict = {}

def __init__(self, **data):
"""Initialize Resource."""
super().__init__(**data)
self._index_resources()

Expand Down
2 changes: 1 addition & 1 deletion pydid/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ServiceEndpoint(Resource):
"""List of Service Endpoints"""
"""List of Service Endpoints."""

uri: Union[DIDUrl, AnyUrl]

Expand Down
7 changes: 4 additions & 3 deletions pydid/verification_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class VerificationMethod(Resource):
_material_prop: Optional[str] = None

def __init__(self, **data):
"""Initialize a VerificationMethod."""
super().__init__(**data)
self._material_prop = self._material_prop or self._infer_material_prop()

Expand Down Expand Up @@ -136,9 +137,9 @@ def _no_more_than_one_material_prop(cls, values: dict):
return values

def _infer_material_prop(self) -> Optional[str]:
"""
Guess the property that appears to be the verification material based
on known material property names.
"""Guess the property that appears to be the verification material.
Guess is based on known material property names.
"""

for prop, value in self:
Expand Down
20 changes: 17 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
homepage = "https://github.com/Indicio-tech/pydid"
repository = "https://github.com/Indicio-tech/pydid"
keywords = [
"decentralized", "identity", "ssi"
"decentralized", "identity", "ssi", "DID", "DID Document"
]

[build-system]
Expand All @@ -26,7 +26,7 @@ pytest = "^7.4.0"
black = "^23.7.0"
poetry = "^1.5.0"
pre-commit = "^3.3.0"
flake8 = "^6.0.0"
ruff = "^0.0.287"
pytest-coverage = "^0.0"
aiohttp = "^3.8.0"
pytest-asyncio = "^0.21.0"
Expand All @@ -44,4 +44,18 @@ exclude_lines = [
precision = 2
show_missing = true

[tool.flake8]
[tool.ruff]
select = ["E", "F", "C", "D"]

ignore = [
# Google Python Doc Style
"D203", "D204", "D213", "D215", "D400", "D401", "D404", "D406", "D407",
"D408", "D409", "D413",
"D202", # Allow blank line after docstring
"D104", # Don't require docstring in public package
]

line-length = 90

[tool.ruff.per-file-ignores]
"**/{tests}/*" = ["F841", "D", "E501"]
6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/doc/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def test_default_context_should_not_mutate():

doc_builder = DIDDocumentBuilder("did:example:123")
# save a copy of the default context before mutating the document's contexts
original_default_context = [context for context in doc_builder.context]
original_default_context = list(doc_builder.context)

# when

Expand Down
2 changes: 1 addition & 1 deletion tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import parse_obj_as
import pytest

from pydid import Service, DIDCommService
from pydid import Service
from pydid.service import DIDCommV1Service, DIDCommV2Service

SERVICES = [
Expand Down

0 comments on commit 2aa157f

Please sign in to comment.