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 3a9d381 commit 1dd01dd
Show file tree
Hide file tree
Showing 35 changed files with 144 additions and 221 deletions.
13 changes: 7 additions & 6 deletions ckanext/attribution/commands/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from ckan.model import Session
from ckan.model.package_extra import PackageExtra
from ckan.plugins import toolkit
from fuzzywuzzy import fuzz, process
from sqlalchemy import and_, or_

from ckanext.attribution.commands import migration
from ckanext.attribution.logic.actions.helpers import get_author_string
from ckanext.attribution.model import (
Expand All @@ -19,14 +22,12 @@
relationships,
)
from ckanext.attribution.model.crud import (
AgentQuery,
PackageQuery,
PackageContributionActivityQuery,
AgentAffiliationQuery,
AgentContributionActivityQuery,
AgentQuery,
PackageContributionActivityQuery,
PackageQuery,
)
from fuzzywuzzy import process, fuzz
from sqlalchemy import and_, or_


def get_commands():
Expand Down Expand Up @@ -235,7 +236,7 @@ def merge_agents(q, match_threshold):
@click.option(
'--limit', help='Process n packages at a time (best for testing/debugging).'
)
@click.option('--dry-run', help='Don\'t save anything to the database.', is_flag=True)
@click.option('--dry-run', help="Don't save anything to the database.", is_flag=True)
@click.option(
'--search-api/--no-search-api',
help='Search external APIs (e.g. ORCID) for details.',
Expand Down
6 changes: 3 additions & 3 deletions ckanext/attribution/commands/migration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .parser import Parser
from .common import multi_choice, rgx
from .combiner import Combiner
from .api_search import APISearch
from .combiner import Combiner
from .common import multi_choice, rgx
from .parser import Parser
10 changes: 6 additions & 4 deletions ckanext/attribution/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import itertools
import re

from ckan.plugins import toolkit, plugin_loaded
from ckanext.attribution.model.crud import PackageQuery, AgentQuery
from ckan.plugins import plugin_loaded, toolkit

from ckanext.attribution.model.crud import AgentQuery, PackageQuery


def can_edit():
Expand All @@ -29,12 +30,13 @@ def split_caps(string_input):


def get_contributions(pkg_id):
'''
"""
Template access for the
:func:`~ckanext.attribution.model.crud.PackageQuery.get_contributions` query method.
:param pkg_id:
:return:
'''
"""
return PackageQuery.get_contributions(pkg_id)


Expand Down
30 changes: 1 addition & 29 deletions ckanext/attribution/lib/orcid_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,19 @@


class OrcidApi(object):
"""
"""

def __init__(self):
self.key = toolkit.config.get('ckanext.attribution.orcid_key')
self.secret = toolkit.config.get('ckanext.attribution.orcid_secret')
self._debug = toolkit.config.get('ckanext.attribution.debug', 'True') == 'True'

@cached_property
def conn(self):
"""
"""
if self.key is None or self.secret is None:
raise Exception(toolkit._('ORCID API credentials not supplied.'))
return orcid.PublicAPI(self.key, self.secret, sandbox=self._debug)

@cached_property
def read_token(self):
"""
"""
if self.key is None or self.secret is None:
raise Exception(toolkit._('ORCID API credentials not supplied.'))
url = (
Expand All @@ -57,12 +47,6 @@ def read_token(self):
return None

def search(self, orcid_q=None, q=None, family_name=None, given_names=None):
'''
:param orcid_q: (Default value = None)
:param q: (Default value = None)
'''
query = []
if orcid_q is not None and orcid_q != '':
query.append('orcid:' + orcid_q)
Expand All @@ -77,7 +61,7 @@ def search(self, orcid_q=None, q=None, family_name=None, given_names=None):
records = []
loaded_ids = []
for r in search_response.get('result', []):
_id = r.get(u'orcid-identifier', {}).get(u'path', None)
_id = r.get('orcid-identifier', {}).get('path', None)
if _id is not None and _id not in loaded_ids:
try:
orcid_record = self.as_agent_record(self.read(_id))
Expand All @@ -90,22 +74,10 @@ def search(self, orcid_q=None, q=None, family_name=None, given_names=None):
return result

def read(self, orcid_id):
'''
:param orcid_id:
'''
record = self.conn.read_record_public(orcid_id, 'record', self.read_token)
return record

def as_agent_record(self, orcid_record):
'''
:param orcid_record:
'''
names = orcid_record.get('person', {}).get('name', {})
return {
'family_name': names.get('family-name', {}).get('value', ''),
Expand Down
15 changes: 2 additions & 13 deletions ckanext/attribution/lib/ror_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
# This file is part of ckanext-attribution
# Created by the Natural History Museum in London, UK

import requests
import json

import requests


class RorApi(object):
url = 'https://api.ror.org'

def read(self, ror_id):
'''
:param ror_id:
'''
response = requests.get('{0}/organizations/{1}'.format(self.url, ror_id))
if not response.ok:
return None
Expand Down Expand Up @@ -48,12 +43,6 @@ def search(self, q):
}

def as_agent_record(self, ror_record):
'''
:param ror_record:
'''
if ror_record is None:
return {}
address = ror_record.get('addresses')
Expand Down
9 changes: 5 additions & 4 deletions ckanext/attribution/logic/actions/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
# Created by the Natural History Museum in London, UK

from ckan.plugins import toolkit
from ckantools.decorators import action, basic_action

from ckanext.attribution.logic.actions.helpers import (
parse_contributors,
get_author_string,
parse_contributors,
)
from ckanext.attribution.logic.actions.meta import help, schema
from ckanext.attribution.model.crud import (
AgentAffiliationQuery,
AgentContributionActivityQuery,
AgentQuery,
ContributionActivityQuery,
PackageContributionActivityQuery,
AgentAffiliationQuery,
)
from ckantools.decorators import action, basic_action
from ckanext.attribution.logic.actions.meta import help, schema


@action(schema.agent_affiliation_create, help.agent_affiliation_create)
Expand Down
3 changes: 2 additions & 1 deletion ckanext/attribution/logic/actions/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This file is part of ckanext-attribution
# Created by the Natural History Museum in London, UK

from ckantools.decorators import action

from ckanext.attribution.logic.actions.meta import help, schema
from ckanext.attribution.model.crud import (
AgentAffiliationQuery,
Expand All @@ -12,7 +14,6 @@
ContributionActivityQuery,
PackageContributionActivityQuery,
)
from ckantools.decorators import action


@action(schema.agent_affiliation_delete, help.agent_affiliation_delete)
Expand Down
10 changes: 6 additions & 4 deletions ckanext/attribution/logic/actions/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
#
# This file is part of ckanext-attribution
# Created by the Natural History Museum in London, UK

import re

from ckan.plugins import toolkit
from ckantools.decorators import action

from ckanext.attribution.lib.orcid_api import OrcidApi
from ckanext.attribution.lib.ror_api import RorApi
from ckanext.attribution.logic.actions.meta import help, schema
from ckanext.attribution.model.crud import AgentQuery
from ckantools.decorators import action
from ckanext.attribution.logic.actions.meta import schema, help


@action(
Expand Down Expand Up @@ -109,7 +111,7 @@ def agent_external_search(q, sources):
orcid_remaining = 0
orcidapi = OrcidApi()
orcid_search = orcidapi.search(q=q)
n = orcid_search.get(u'total', 0)
n = orcid_search.get('total', 0)
orcid_records = orcid_search.get('records')
orcid_records = [
r
Expand All @@ -125,7 +127,7 @@ def agent_external_search(q, sources):
ror_remaining = 0
rorapi = RorApi()
ror_search = rorapi.search(q=q)
n = ror_search.get(u'total', 0)
n = ror_search.get('total', 0)
ror_records = ror_search.get('records')
ror_records = [
r
Expand Down
6 changes: 3 additions & 3 deletions ckanext/attribution/logic/actions/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import json

from ckan.plugins import toolkit

from ckanext.attribution.model.crud import (
AgentQuery,
AgentAffiliationQuery,
AgentContributionActivityQuery,
AgentQuery,
ContributionActivityQuery,
AgentAffiliationQuery,
PackageQuery,
PackageContributionActivityQuery,
)


Expand Down
Loading

0 comments on commit 1dd01dd

Please sign in to comment.