Skip to content

Commit

Permalink
style: automatic reformat
Browse files Browse the repository at this point in the history
auto reformat with ruff/docformatter/prettier after config changes
  • Loading branch information
alycejenni committed Oct 30, 2024
1 parent 448ae8c commit 4046e4d
Show file tree
Hide file tree
Showing 75 changed files with 703 additions and 667 deletions.
6 changes: 3 additions & 3 deletions ckanext/versioned_datastore/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import click

from ckan.plugins import toolkit

from .model.details import datastore_resource_details_table
from .model.downloads import (
datastore_downloads_requests_table,
datastore_downloads_derivative_files_table,
datastore_downloads_core_files_table,
datastore_downloads_derivative_files_table,
datastore_downloads_requests_table,
)
from .model.slugs import datastore_slugs_table, navigational_slugs_table
from .model.stats import import_stats_table
Expand Down
6 changes: 4 additions & 2 deletions ckanext/versioned_datastore/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from ckan.plugins import toolkit
from datetime import date

from ckan.plugins import toolkit

from .lib.common import ALL_FORMATS
from .lib.importing import stats
from .lib.query.slugs import create_nav_slug
Expand Down Expand Up @@ -138,7 +139,8 @@ def latest_item_version(resource_id, record_id=None):
:param resource_id: the id of the resource to search in
:param record_id: optional; a record id to search for instead
:return: if record id is provided, the latest record version, else the latest resource version
:return: if record id is provided, the latest record version, else the latest
resource version
"""
action = (
'datastore_get_record_versions'
Expand Down
41 changes: 20 additions & 21 deletions ckanext/versioned_datastore/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ def datastore_modify_fields(self, resource_id, mapping, fields):
:param resource_id: the resource id that was searched
:param mapping: the mapping for the elasticsearch index containing the
resource's data. This is the raw mapping as a dict, retrieved
straight from elasticsearch's mapping endpoint
resource's data. This is the raw mapping as a dict, retrieved straight from
elasticsearch's mapping endpoint
:param fields: the field definitions that have so far been extracted from the
mapping, by default this is all fields
mapping, by default this is all fields
:return: the list of field definition dicts
"""
return fields

def datastore_modify_index_doc(self, resource_id, index_doc):
'''
"""
Action allowing the modification of a resource's data during indexing. The
index_doc passed is a dict in the form:
Expand All @@ -134,7 +134,7 @@ def datastore_modify_index_doc(self, resource_id, index_doc):
:param resource_id: the id of the resource being indexed
:param index_doc: a dict that will be sent to elasticsearch
:return: the dict for elasticsearch to index
'''
"""
return index_doc

def datastore_is_read_only_resource(self, resource_id):
Expand Down Expand Up @@ -162,7 +162,7 @@ def datastore_after_indexing(self, request, splitgill_stats, stats_id):
:param request: the ResourceIndexRequest object that triggered the indexing task
:param splitgill_stats: the statistics about the indexing task from splitgill
:param stats_id: the id of the statistics entry in the ImportStats database
table
table
"""
pass

Expand Down Expand Up @@ -230,7 +230,7 @@ def datastore_after_convert_basic_query(self, basic_query, multisearch_query):
custom filters.
:param basic_query: the original basic query, before it was modified by other
plugins
plugins
:param multisearch_query: the converted multisearch version of the query
:return: the modified multisearch query
"""
Expand All @@ -243,9 +243,8 @@ def get_query_schemas(self):
Hook to allow registering custom query schemas.
:return: a list of tuples of the format (query schema version, schema object)
where the query schema version is a string of format v#.#.# and the
schema object is an instance of
ckanext.versioned_datastore.lib.query.Schema
where the query schema version is a string of format v#.#.# and the schema
object is an instance of ckanext.versioned_datastore.lib.query.Schema
"""
return []

Expand All @@ -262,7 +261,7 @@ def download_modify_notifier_start_templates(
:param text_template: the text template string
:param html_template: the html template string
:return: a 2-tuple containing the text template string and the html template
string
string
"""
return text_template, html_template

Expand All @@ -277,7 +276,7 @@ def download_modify_notifier_end_templates(
:param text_template: the text template string
:param html_template: the html template string
:return: a 2-tuple containing the text template string and the html template
string
string
"""
return text_template, html_template

Expand All @@ -292,7 +291,7 @@ def download_modify_notifier_error_templates(
:param text_template: the text template string
:param html_template: the html template string
:return: a 2-tuple containing the text template string and the html template
string
string
"""
return text_template, html_template

Expand All @@ -317,9 +316,9 @@ def download_derivative_generators(self, registered_derivatives=None):
Extend or modify the list of derivative generators.
:param registered_derivatives: a dict of existing derivative generator classes,
returned from previously loaded plugins
returned from previously loaded plugins
:return: a dict of loaded derivative generator classes, keyed on the name used
to specify them in download requests
to specify them in download requests
"""
return registered_derivatives or {}

Expand All @@ -328,9 +327,9 @@ def download_file_servers(self, registered_servers=None):
Extend or modify the list of file servers.
:param registered_servers: a dict of existing file server classes, returned from
previously loaded plugins
previously loaded plugins
:return: a dict of loaded file server classes, keyed on the name used to specify
them in download requests
them in download requests
"""
return registered_servers or {}

Expand All @@ -339,9 +338,9 @@ def download_notifiers(self, registered_notifiers=None):
Extend or modify the list of download notifiers.
:param registered_notifiers: a dict of existing notifier classes, returned from
previously loaded plugins
previously loaded plugins
:return: a dict of loaded notifier classes, keyed on the name used to specify
them in download requests
them in download requests
"""
return registered_notifiers or {}

Expand All @@ -350,9 +349,9 @@ def download_data_transformations(self, registered_transformations=None):
Extend or modify the list of data transformations.
:param registered_transformations: a dict of existing data transformations,
returned from previously loaded plugins
returned from previously loaded plugins
:return: a dict of loaded transformations, keyed on the name used to specify
them in download requests
them in download requests
"""
return registered_transformations or {}

Expand Down
12 changes: 7 additions & 5 deletions ckanext/versioned_datastore/lib/basic_query/geo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from ckan.plugins import toolkit
from elasticsearch_dsl import Q

Expand All @@ -11,11 +12,12 @@ def add_point_filter(search, distance, coordinates):
Adds a point filter query to the search object and returns a new search object.
:param search: the current elasticsearch DSL object
:param distance: the radius of the circle centred on the specified location within which records
must lie to be matched. This can specified in any form that elasticsearch
accepts for distances (see their doc, but essentially values like 10km etc).
:param coordinates: the point to centre the radius on, specified as a lon/lat pair in a list
(i.e. [40.2, -20]).
:param distance: the radius of the circle centred on the specified location within
which records must lie to be matched. This can specified in any form that
elasticsearch accepts for distances (see their doc, but essentially values like
10km etc).
:param coordinates: the point to centre the radius on, specified as a lon/lat pair
in a list (i.e. [40.2, -20]).
:return: a search object
"""
options = {
Expand Down
16 changes: 8 additions & 8 deletions ckanext/versioned_datastore/lib/basic_query/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from ckan.plugins import PluginImplementations
from elasticsearch_dsl import Search

from .geo import add_geo_search
from ..datastore_utils import prefix_field
from ...interfaces import IVersionedDatastore
from ..datastore_utils import prefix_field
from .geo import add_geo_search


def _find_version(data_dict):
Expand All @@ -17,8 +17,8 @@ def _find_version(data_dict):
recline.js framework used by the NHM on CKAN 2.3 where no additional parameters can
be passed other than q, filters etc.
:param data_dict: the data dict, this might be modified if the __version__ key is used (it will
be removed if present)
:param data_dict: the data dict, this might be modified if the __version__ key is
used (it will be removed if present)
:return: the version found as an integer, or None if no version was found
"""
version = data_dict.get('version', None)
Expand Down Expand Up @@ -49,9 +49,9 @@ def create_search(context, data_dict, original_data_dict):
:param context: the context dict
:param data_dict: the data dict of parameters
:return: a 3-tuple containing: the original data_dict that was passed into this function, the
data_dict after modification by other plugins and finally the
elasticsearch-dsl Search object
:return: a 3-tuple containing: the original data_dict that was passed into this
function, the data_dict after modification by other plugins and finally the
elasticsearch-dsl Search object
"""
# allow other extensions implementing our interface to modify the data_dict
for plugin in PluginImplementations(IVersionedDatastore):
Expand Down Expand Up @@ -82,7 +82,7 @@ def build_search_object(
facets=None,
facet_limits=None,
sort=None,
**kwargs
**kwargs,
):
"""
Given the parameters, creates a new elasticsearch-dsl Search object and returns it.
Expand Down
20 changes: 11 additions & 9 deletions ckanext/versioned_datastore/lib/basic_query/utils.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import copy
import json

from ckan.lib.search import SearchIndexError
from ckan.plugins import PluginImplementations
from elasticsearch import NotFoundError
from elasticsearch_dsl import MultiSearch, Search
from splitgill.indexing.utils import DOC_TYPE
from splitgill.search import create_version_query

from ckan.lib.search import SearchIndexError
from ckan.plugins import PluginImplementations
from ...interfaces import IVersionedDatastore
from .. import common
from ..datastore_utils import prefix_resource, prefix_field
from ..datastore_utils import prefix_field, prefix_resource
from ..importing.details import get_all_details
from ...interfaces import IVersionedDatastore


def run_search(search, indexes, version=None):
"""
Convenience function to runs a search on the given indexes using the client
available in this module.
If the index(es) required for the search are missing then a CKAN SearchIndexError exception is
raised.
If the index(es) required for the search are missing then a CKAN SearchIndexError
exception is raised.
:param search: the elasticsearch-dsl search object
:param indexes: either a list of index names to search in or a single index name as a string
:param indexes: either a list of index names to search in or a single index name as
a string
:param version: version to filter the search results to, optional
:return: the result of running the query
"""
Expand All @@ -37,7 +39,7 @@ def run_search(search, indexes, version=None):


def format_facets(aggs):
'''
"""
Formats the facet aggregation result into the format we require. Specifically we expand the
buckets out into a dict that looks like this:
Expand All @@ -61,7 +63,7 @@ def format_facets(aggs):
:param aggs: the aggregation dict returned from splitgill/elasticsearch
:return: the facet information as a dict
'''
"""
facets = {}
for facet, details in aggs.items():
facets[facet] = {
Expand Down
28 changes: 16 additions & 12 deletions ckanext/versioned_datastore/lib/datastore_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from cachetools import TTLCache, cached
from ckan import model
from ckan.plugins import toolkit, PluginImplementations
from ckan.plugins import PluginImplementations, toolkit
from splitgill.indexing.utils import DOC_TYPE
from cachetools import cached, TTLCache

from . import common
from ..interfaces import IVersionedDatastore
from . import common


def get_latest_version(resource_id):
Expand Down Expand Up @@ -71,7 +71,7 @@ def get_public_alias_name(resource_id):
datastore data. This is just "pub" (retrieved from get_public_alias_prefix above)
prepended to the normal prefixed index name, for example:
pubnhm-05ff2255-c38a-40c9-b657-4ccb55ab2feb
pubnhm-05ff2255-c38a-40c9-b657-4ccb55ab2feb
:param resource_id: the resource's id
:return: the name of the alias
Expand Down Expand Up @@ -107,10 +107,11 @@ def update_privacy(resource_id, is_private=None):
already set correctly on the resource's index in Elasticsearch this does nothing.
:param resource_id: the resource's id
:param is_private: whether the package the resource is in is private or not. This is an optional
parameter, if it is left out we look up the resource's package in the
database and find out the private setting that way.
:return: True if modifications were required to update the resource data's privacy, False if not
:param is_private: whether the package the resource is in is private or not. This is
an optional parameter, if it is left out we look up the resource's package in
the database and find out the private setting that way.
:return: True if modifications were required to update the resource data's privacy,
False if not
"""
if is_private is None:
resource = model.Resource.get(resource_id)
Expand All @@ -128,7 +129,8 @@ def make_private(resource_id):
all, or the alias already doesn't exist, nothing happens.
:param resource_id: the resource's id
:return: True if modifications were required to make the resource's data private, False if not
:return: True if modifications were required to make the resource's data private,
False if not
"""
index_name = prefix_resource(resource_id)
public_index_name = get_public_alias_name(resource_id)
Expand All @@ -146,7 +148,8 @@ def make_public(resource_id):
the alias already exists, nothing happens.
:param resource_id: the resource's id
:return: True if modifications were required to make the resource's data public, False if not
:return: True if modifications were required to make the resource's data public,
False if not
"""
index_name = prefix_resource(resource_id)
public_index_name = get_public_alias_name(resource_id)
Expand Down Expand Up @@ -190,8 +193,9 @@ def iter_data_fields(mapping):
a field at the top level is just ('field', ): {} but a nested one would be ('field',
'sub'): {}).
:param mapping: the mapping dict returned from elasticsearch, this should be the first value in
the dict after the index name, i.e. the result of get_mapping(index)[index]
:param mapping: the mapping dict returned from elasticsearch, this should be the
first value in the dict after the index name, i.e. the result of
get_mapping(index)[index]
:return: an iterator which yields fields and their configs
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .csv import CsvDerivativeGenerator
from .dwc import DwcDerivativeGenerator
from .json import JsonDerivativeGenerator
from .xlsx import XlsxDerivativeGenerator
from .dwc import DwcDerivativeGenerator

derivatives = [
CsvDerivativeGenerator,
Expand Down
4 changes: 2 additions & 2 deletions ckanext/versioned_datastore/lib/downloads/derivatives/csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv

from .base import BaseDerivativeGenerator
from ..utils import flatten_dict
from .base import BaseDerivativeGenerator


class CsvDerivativeGenerator(BaseDerivativeGenerator):
Expand All @@ -15,7 +15,7 @@ def __init__(
query,
resource_id=None,
delimiter='comma',
**format_args
**format_args,
):
super(CsvDerivativeGenerator, self).__init__(
output_dir, fields, query, resource_id, delimiter='comma', **format_args
Expand Down
Loading

0 comments on commit 4046e4d

Please sign in to comment.