Skip to content

Commit

Permalink
Merge pull request #399 from fizyk/ruff
Browse files Browse the repository at this point in the history
Replace pydocstyle and pycodestyle with ruff - closes #361
  • Loading branch information
fizyk authored Oct 11, 2023
2 parents 9708387 + a11dabd commit 3f8d814
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 126 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ updates:
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
time: "04:10"
open-pull-requests-limit: 1
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
time: "04:00"
time: "04:11"
open-pull-requests-limit: 2
3 changes: 1 addition & 2 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ jobs:
uses: fizyk/actions-reuse/.github/workflows/[email protected]
with:
black: true
pycodestyle: true
pydocstyle: true
ruff: true
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ coverage = "==7.3.2"
mock = "==5.1.0"
requests-mock = "==1.11.0"
black = "==23.9.1"
pycodestyle = "==2.11.0"
tbump = "==6.11.0"
pydocstyle = {version = "==6.3.0", extras = ["toml"]}
ruff = "==0.0.292"
1 change: 1 addition & 0 deletions newsfragments/361.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace pycodestyle and pydocstyle with ruff linter.
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,21 @@ showcontent = true
[tool.pytest.ini_options]
xfail_strict=true

[tool.pydocstyle]
ignore = "D203,D212"

[tool.black]
line-length = 120
target-version = ['py39']
include = '.*\.pyi?$'

[tool.ruff]
line-length = 120
select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"D", # pydocstyle
]


[tool.tbump]
# Uncomment this if your project is hosted on GitHub:
# github_url = "https://github.com/<user or organization>/<project>/"
Expand Down
28 changes: 10 additions & 18 deletions pyramid_basemodel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""
Main pyramid_basemodel module.
"""Main pyramid_basemodel module.
Provides global scoped ``Session`` and declarative ``Base``, ``BaseMixin``
class and ``bind_engine`` function.
Expand Down Expand Up @@ -30,18 +29,15 @@ class and ``bind_engine`` function.
"bind_engine",
]

import inflect
from datetime import datetime

from zope.interface import classImplements
from zope.sqlalchemy import register

from sqlalchemy import engine_from_config
from sqlalchemy import Column, DateTime, Integer
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker

import inflect
from pyramid.path import DottedNameResolver
from pyramid.settings import asbool
from sqlalchemy import Column, DateTime, Integer, engine_from_config
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker
from zope.interface import classImplements
from zope.sqlalchemy import register

from pyramid_basemodel.interfaces import IDeclarativeBase

Expand All @@ -62,8 +58,7 @@ def __get__(self, instance, owner):


class BaseMixin:
"""
Default Base Model Mixin.
"""Default Base Model Mixin.
Provides an int ``id`` as primary key, ``version``, ``created`` and
``modified`` columns and a scoped ``self.query`` property.
Expand All @@ -85,8 +80,7 @@ class BaseMixin:

@classproperty
def class_name(cls):
"""
Determine class name based on the _class_name or the __tablename__.
"""Determine class name based on the _class_name or the __tablename__.
If provided, defaults to ``cls._class_name``, otherwise default to
``cls.plural_class_name``, which is derived from the cls.__tablename__.
Expand Down Expand Up @@ -140,8 +134,7 @@ def plural_class_name(cls):


def save(instance_or_instances, session=Session):
"""
Save model instance(s) to the db.
"""Save model instance(s) to the db.
Both single and multiple instances can be saved.
"""
Expand All @@ -153,8 +146,7 @@ def save(instance_or_instances, session=Session):


def bind_engine(engine, session=Session, base=Base, should_create=False, should_drop=False):
"""
Bind the ``session`` and ``base`` to the ``engine``.
"""Bind the ``session`` and ``base`` to the ``engine``.
:param should_create: Triggers create tables on all models
:param should_drop: Triggers drop on all tables
Expand Down
22 changes: 6 additions & 16 deletions pyramid_basemodel/blob.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

"""
Provide a generic model class for storing large binary objects.
"""Provide a generic model class for storing large binary objects.
To store a bytestring::
Expand Down Expand Up @@ -36,26 +35,19 @@

import logging
from http import HTTPStatus
from io import StringIO

from gzip import GzipFile
from tempfile import NamedTemporaryFile

import requests

from sqlalchemy.schema import Column
from sqlalchemy.types import Unicode
from sqlalchemy.types import LargeBinary
from sqlalchemy.types import LargeBinary, Unicode

from pyramid_basemodel import Base
from pyramid_basemodel import BaseMixin
from pyramid_basemodel import Base, BaseMixin

logger = logging.getLogger(__name__)


class Blob(Base, BaseMixin):
"""
Encapsulates a large binary file.
"""Encapsulates a large binary file.
Instances must have a unique ``self.name``, which has a maximum length
of 64 characters.
Expand Down Expand Up @@ -84,8 +76,7 @@ def factory(cls, name, file_like_object=None):
return instance

def update(self, name, file_like_object=None):
"""
Update value from file like object.
"""Update value from file like object.
Update properties, reading the ``file_like_object`` into
``self.value`` if provided.
Expand All @@ -95,8 +86,7 @@ def update(self, name, file_like_object=None):
self.value = file_like_object.read()

def update_from_url(self, url):
"""
Update value from url's content.
"""Update value from url's content.
Update ``self.value`` to be the contents of the file downloaded
from the ``url`` provided.
Expand Down
19 changes: 6 additions & 13 deletions pyramid_basemodel/container.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

"""
Base model container.
"""Base model container.
Provides a base model container, used by the Pyramid traversal
machinery and a mixin to aid with traversal from an instance
Expand All @@ -13,18 +12,13 @@
"InstanceTraversalMixin",
]

import re
import logging

from zope.interface import implementer
from zope.interface import alsoProvides

from sqlalchemy.exc import InvalidRequestError
import re

from pyramid.interfaces import ILocation
from pyramid.security import ALL_PERMISSIONS
from pyramid.security import Allow, Deny
from pyramid.security import Authenticated, Everyone
from pyramid.security import ALL_PERMISSIONS, Allow, Authenticated, Deny, Everyone
from sqlalchemy.exc import InvalidRequestError
from zope.interface import alsoProvides, implementer

from pyramid_basemodel import Session
from pyramid_basemodel.interfaces import IModelContainer
Expand All @@ -35,8 +29,7 @@


def slug_validator(node, value, regexp=valid_slug):
"""
Validate slug.
"""Validate slug.
Defaults to using a slug regexp.
"""
Expand Down
13 changes: 4 additions & 9 deletions pyramid_basemodel/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
]

import logging

from datetime import datetime

from sqlalchemy import Column
from sqlalchemy import Unicode
from sqlalchemy import Column, Unicode
from sqlalchemy.ext.declarative import declared_attr

from pyramid_basemodel import save as save_to_db
Expand All @@ -22,8 +20,7 @@


class PolymorphicBaseMixin:
"""
PolymorphicMixin streamline inheritance.
"""PolymorphicMixin streamline inheritance.
Provides a dynamically generated ``__mapper_args__`` property for
[single table inherited][] ORM classes::
Expand All @@ -40,8 +37,7 @@ def __mapper_args__(self):


class PolymorphicMixin:
"""
PolymorphicMixin streamline inheritance.
"""PolymorphicMixin streamline inheritance.
Provides a dynamically generated ``__mapper_args__`` property for
[single table inherited][] ORM classes::
Expand All @@ -59,8 +55,7 @@ class TouchMixin:
"""Provides ``touch`` and ``propagate_touch`` methods."""

def propagate_touch(self):
"""
Override to propagate touch events to relations.
"""Override to propagate touch events to relations.
Note that this event *should not* be called in response to an
SQLAlchemy ORM attribute modified event, as you can't reliably
Expand Down
7 changes: 2 additions & 5 deletions pyramid_basemodel/root.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

"""
Base traversal root and a mixin class for objects in the Pyramid traversal hierarchy.
"""Base traversal root and a mixin class for objects in the Pyramid traversal hierarchy.
Provides a base traversal root and a mixin class for objects in the Pyramid traversal hierarchy.
Expand All @@ -14,10 +13,8 @@

import logging

from zope.interface import implementer
from zope.interface import alsoProvides

from pyramid.interfaces import ILocation
from zope.interface import alsoProvides, implementer

logger = logging.getLogger(__name__)

Expand Down
11 changes: 3 additions & 8 deletions pyramid_basemodel/slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@
import logging

import slugify

from sqlalchemy import exc as sa_exc
from sqlalchemy import inspect as sa_inspect
from sqlalchemy.ext import declarative
from sqlalchemy.schema import Column
from sqlalchemy.types import Unicode

from pyramid_basemodel.util import ensure_unique
from pyramid_basemodel.util import generate_random_digest

from pyramid_basemodel import Session
from pyramid_basemodel.util import ensure_unique, generate_random_digest

logger = logging.getLogger(__name__)


class BaseSlugNameMixin:
"""
Base mixin delivering a slug functionality.
"""Base mixin delivering a slug functionality.
ORM mixin class that provides ``slug`` and ``name`` properties, with a
``set_slug`` method to set the slug value from the name and a default
Expand Down Expand Up @@ -60,8 +56,7 @@ def set_slug(
to_slug=slugify.slugify,
unique=ensure_unique,
):
"""
Generate and set a unique ``self.slug`` from ``self.name``.
"""Generate and set a unique ``self.slug`` from ``self.name``.
:param get_digest: function to generate random digest. Used of there's no name set.
:param inspect:
Expand Down
10 changes: 3 additions & 7 deletions pyramid_basemodel/tree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

"""
`BaseContentRoot`` traversal root.
"""`BaseContentRoot`` traversal root.
Provide a ``BaseContentRoot`` traversal root for looking up instances
via their containers.
Expand All @@ -13,8 +12,7 @@

import logging

from zope.interface import Interface
from zope.interface import alsoProvides
from zope.interface import Interface, alsoProvides

from pyramid_basemodel.container import BaseModelContainer
from pyramid_basemodel.root import BaseRoot
Expand All @@ -40,7 +38,6 @@ def container_factory(
is_interface = issubclass(container_cls_or_interface, interface_cls)
if is_interface:
container_cls = default_cls
container_interface = container_cls_or_interface
else:
container_cls = container_cls_or_interface

Expand All @@ -55,8 +52,7 @@ def container_factory(
return container

def __getitem__(self, key):
"""
Get model from mapping.
"""Get model from mapping.
First see if the key is in ``self.mapping``. If it is, return
a content container configured to look up that model class.
Expand Down
Loading

0 comments on commit 3f8d814

Please sign in to comment.