Skip to content

Commit

Permalink
move to pyproject.toml, ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-iv committed Oct 29, 2024
1 parent a8b1df8 commit 49f25f2
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 120 deletions.
32 changes: 13 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@ repos:
hooks:
# - id: check-yaml
- id: end-of-file-fixer
stages: [commit]
- id: trailing-whitespace
stages: [commit]
- id: debug-statements
stages: [push]

## Isort
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort
stages: [pre-commit]

## Black
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- id: trailing-whitespace
stages: [pre-commit]
- id: debug-statements
stages: [pre-push]

## Ruff
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.260
rev: v0.5.0
hooks:
- id: ruff
args: [--fix]
stages: [pre-commit]
- id: ruff-format
stages: [pre-commit]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-merge-conflict
args: [--assume-in-merge]
4 changes: 2 additions & 2 deletions ckanext/relationship/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_helpers():


def relationship_get_entity_list(entity, entity_type, include_private=True):
"""Return ids list of specified entity (entity, entity_type)"""
"""Return ids list of specified entity (entity, entity_type)."""
context = {}
if entity == "package":
entity_list = tk.get_action("package_search")(
Expand Down Expand Up @@ -87,7 +87,7 @@ def relationship_get_selected_json(selected_ids: list | None = None) -> str:
try:
pkg_dict = tk.get_action("package_show")({}, {"id": pkg_id})
selected_pkgs.append({"name": pkg_dict["id"], "title": pkg_dict["title"]})
except Exception:
except (tk.ObjectNotFound, tk.NotAuthorized):
continue
return json.dumps(selected_pkgs)

Expand Down
8 changes: 5 additions & 3 deletions ckanext/relationship/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def get_actions():
@validate(schema.relation_create)
def relationship_relation_create(context, data_dict) -> list[dict[str, str]]:
"""Create relation with specified type (relation_type) between two entities
specified by ids (subject_id, object_id). Also create reverse relation."""
specified by ids (subject_id, object_id). Also create reverse relation.
"""
tk.check_access("relationship_relation_create", context, data_dict)

subject_id = data_dict["subject_id"]
Expand Down Expand Up @@ -65,7 +66,8 @@ def relationship_relation_create(context, data_dict) -> list[dict[str, str]]:
@validate(schema.relation_delete)
def relationship_relation_delete(context, data_dict) -> list[dict[str, str]]:
"""Delete relation with specified type (relation_type) between two entities
specified by ids (subject_id, object_id). Also delete reverse relation."""
specified by ids (subject_id, object_id). Also delete reverse relation.
"""
tk.check_access("relationship_relation_delete", context, data_dict)

subject_id = data_dict["subject_id"]
Expand Down Expand Up @@ -165,7 +167,7 @@ def relationship_relations_ids_list(context, data_dict) -> list[str]:

@validate(schema.get_entity_list)
def relationship_get_entity_list(context, data_dict) -> list[str]:
"""Return ids list of specified entity (entity, entity_type)"""
"""Return ids list of specified entity (entity, entity_type)."""
tk.check_access("relationship_get_entity_list", context, data_dict)

model = context["model"]
Expand Down
18 changes: 12 additions & 6 deletions ckanext/relationship/logic/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

from typing import Any

from ckan import types
from ckan.plugins import toolkit as tk


Expand All @@ -15,29 +18,32 @@ def get_auth_functions():
return {f.__name__: f for f in auth_functions}


def relationship_relation_create(context, data_dict):
def relationship_relation_create(context: types.Context, data_dict: dict[str, Any]):
return {"success": True}


def relationship_relation_delete(context, data_dict):
def relationship_relation_delete(context: types.Context, data_dict: dict[str, Any]):
return {"success": True}


@tk.auth_allow_anonymous_access
def relationship_relations_list(context, data_dict):
def relationship_relations_list(context: types.Context, data_dict: dict[str, Any]):
return {"success": True}


@tk.auth_allow_anonymous_access
def relationship_relations_ids_list(context, data_dict):
def relationship_relations_ids_list(context: types.Context, data_dict: dict[str, Any]):
return {"success": True}


@tk.auth_allow_anonymous_access
def relationship_get_entity_list(context, data_dict):
def relationship_get_entity_list(context: types.Context, data_dict: dict[str, Any]):
return {"success": True}


@tk.auth_allow_anonymous_access
def relationship_relationship_autocomplete(context, data_dict):
def relationship_relationship_autocomplete(
context: types.Context,
data_dict: dict[str, Any],
):
return {"success": True}
5 changes: 2 additions & 3 deletions ckanext/relationship/logic/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def validator(key, data, errors, context):
)

selected_relations = get_selected_relations(data[key])

data[key] = json.dumps([value for value in selected_relations])
data[key] = json.dumps(list(selected_relations))

add_relations = selected_relations - current_relations
del_relations = current_relations - selected_relations
Expand Down Expand Up @@ -76,7 +75,7 @@ def get_current_relations(
return set(current_relations)


def get_selected_relations(selected_relations):
def get_selected_relations(selected_relations: list | str | None) -> set[str]:
if isinstance(selected_relations, string_types) and "," in selected_relations:
selected_relations = selected_relations.split(",")

Expand Down
1 change: 0 additions & 1 deletion ckanext/relationship/migration/relationship/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def run_migrations_offline():
script output.
"""

url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Create relationship table
"""Create relationship table.
Revision ID: aca2ff1d3ce4
Revises:
Expand Down
5 changes: 1 addition & 4 deletions ckanext/relationship/model/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def by_subject_id(


def _entity_name_by_id(entity_id):
"""
Returns entity (package or organization or group) name by its id
"""

"""Returns entity (package or organization or group) name by its id."""
pkg = (
model.Session.query(model.Package)
.filter(model.Package.id == entity_id)
Expand Down
4 changes: 2 additions & 2 deletions ckanext/relationship/plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ckan.plugins.toolkit as tk
from ckan import plugins
from ckan.common import CKANConfig
from ckan.lib.search import rebuild
from ckan.logic import NotFound

import ckanext.scheming.helpers as sch

from ckanext.relationship import helpers, utils, views
from ckanext.relationship.logic import action, auth, validators

Expand All @@ -19,7 +19,7 @@ class RelationshipPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IPackageController, inherit=True)

# IConfigurer
def update_config(self, config_):
def update_config(self, config_: CKANConfig):
tk.add_template_directory(config_, "templates")
tk.add_public_directory(config_, "public")
tk.add_resource("assets", "relationship")
Expand Down
3 changes: 1 addition & 2 deletions ckanext/relationship/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Tests for plugin.py.
"""Tests for plugin.py.
Tests are written using the pytest library (https://docs.pytest.org), and you
should read the testing guidelines in the CKAN docs:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
ckanext-scheming
77 changes: 1 addition & 76 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,6 @@
# Always prefer setuptools over distutils
from codecs import open # To use a consistent encoding
from os import path

from setuptools import find_packages, setup

here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file
with open(path.join(here, "README.md"), encoding="utf-8") as f:
long_description = f.read()
from setuptools import setup

setup(
name="""ckanext-relationship""",
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version="0.2.9",
description="""""",
long_description=long_description,
long_description_content_type="text/markdown",
# The project's main homepage.
url="https://github.com/DataShades/ckanext-relationship",
# Author details
author="""Oleksandr Ivaniuk""",
author_email="""[email protected]""",
# Choose your license
license="AGPL",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
"Development Status :: 4 - Beta",
# Pick your license as you wish (should match "license" above)
(
"License :: OSI Approved :: GNU Affero General Public License v3"
" or later (AGPLv3+)"
),
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
"Programming Language :: Python :: 2.7",
],
# What does your project relate to?
keywords="""CKAN""",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(exclude=["contrib", "docs", "tests*"]),
namespace_packages=["ckanext"],
install_requires=[
# CKAN extensions should not list dependencies here, but in a separate
# ``requirements.txt`` file.
#
# http://docs.ckan.org/en/latest/extensions/best-practices.html
# add-third-party-libraries-to-requirements-txt
],
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in MANIFEST.in as well.
include_package_data=True,
package_data={},
# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages.
# see http://docs.python.org/3.4/distutils/setupscript.html
# installing-additional-files
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
data_files=[],
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points="""
[ckan.plugins]
relationship=ckanext.relationship.plugin:RelationshipPlugin
[babel.extractors]
ckan = ckan.lib.extract:extract_ckan
""",
# If you are changing from the default layout of your extension, you may
# have to change the message extractors, you can read more about babel
# message extraction at
Expand Down

0 comments on commit 49f25f2

Please sign in to comment.