Black/add assets to package/update pyproject.toml

This commit is contained in:
Sergey Motornyuk 2021-08-13 12:25:03 +03:00
parent 05c153dc77
commit af8380070a
9 changed files with 102 additions and 34 deletions

View File

@ -1,4 +1,4 @@
include README.rst
include LICENSE.txt
include requirements.txt
recursive-include ckanext/googleanalytics *.html *.js
recursive-include ckanext/googleanalytics *.html *.js *.json *.css *.yml *.mo

View File

@ -22,19 +22,17 @@ DATASET_EDIT_REGEX = re.compile("/dataset/edit/([a-z0-9-_]+)")
def get_commands():
return [
googleanalytics
]
return [googleanalytics]
@click.group(short_help=u"GoogleAnalytics commands")
def googleanalytics():
pass
@googleanalytics.command()
def init():
"""Initialise the local stats database tables
"""
"""Initialise the local stats database tables"""
model.Session.remove()
model.Session.configure(bind=model.meta.engine)
dbutil.init_tables()
@ -75,9 +73,11 @@ def _resource_url_tag():
def _recent_view_days():
return tk.asint(tk.config.get(
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
))
return tk.asint(
tk.config.get(
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
)
)
###############################################################################
@ -253,8 +253,7 @@ def get_ga_data_new(service, profile_id, start_date=None, end_date=None):
def save_ga_data(packages_data):
"""Save tuples of packages_data to the database
"""
"""Save tuples of packages_data to the database"""
for identifier, visits in list(packages_data.items()):
recently = visits.get("recent", 0)
ever = visits.get("ever", 0)
@ -287,10 +286,13 @@ def save_ga_data(packages_data):
def ga_query(
service, profile_id, query_filter=None, from_date=None, metrics=None,
service,
profile_id,
query_filter=None,
from_date=None,
metrics=None,
):
"""Execute a query against Google Analytics
"""
"""Execute a query against Google Analytics"""
now = datetime.datetime.now()
to_date = now.strftime("%Y-%m-%d")
if isinstance(from_date, datetime.date):

View File

@ -23,8 +23,7 @@ DATASET_EDIT_REGEX = re.compile("/dataset/edit/([a-z0-9-_]+)")
class InitDB(CkanCommand):
"""Initialise the local stats database tables
"""
"""Initialise the local stats database tables"""
summary = __doc__.split("\n")[0]
usage = __doc__
@ -65,9 +64,11 @@ class LoadAnalytics(CkanCommand):
self.resource_url_tag = self.CONFIG.get(
"googleanalytics_resource_prefix", DEFAULT_RESOURCE_URL_TAG
)
self.recent_view_days = asint(self.CONFIG.get(
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
))
self.recent_view_days = asint(
self.CONFIG.get(
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
)
)
# funny dance we need to do to make sure we've got a
# configured session
@ -267,8 +268,7 @@ class LoadAnalytics(CkanCommand):
log.info("Saved %s records from google" % len(packages_data))
def save_ga_data(self, packages_data):
"""Save tuples of packages_data to the database
"""
"""Save tuples of packages_data to the database"""
for identifier, visits in list(packages_data.items()):
recently = visits.get("recent", 0)
ever = visits.get("ever", 0)
@ -309,8 +309,7 @@ class LoadAnalytics(CkanCommand):
metrics=None,
sort=None,
):
"""Execute a query against Google Analytics
"""
"""Execute a query against Google Analytics"""
if not to_date:
now = datetime.datetime.now()
to_date = now.strftime("%Y-%m-%d")

View File

@ -15,6 +15,7 @@ from ckan.controllers.api import ApiController
from ckan.exceptions import CkanVersionException
import ckan.plugins.toolkit as tk
try:
tk.requires_ckan_version("2.9")
except CkanVersionException:

View File

@ -47,7 +47,9 @@ class AnalyticsPostThread(threading.Thread):
log.debug("Sending API event to Google Analytics: " + data)
# send analytics
res = requests.post(
"http://www.google-analytics.com/collect", data, timeout=10,
"http://www.google-analytics.com/collect",
data,
timeout=10,
)
# signals to queue job is done
self.queue.task_done()

View File

@ -6,6 +6,7 @@ import ckan.plugins as plugins
from ckanext.googleanalytics.views import ga
from ckanext.googleanalytics.cli import get_commands
class GAMixinPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.IClick)

View File

@ -14,7 +14,7 @@ import ckan.views.resource as resource
from ckan.common import g
CONFIG_HANDLER_PATH = 'googleanalytics.download_handler'
CONFIG_HANDLER_PATH = "googleanalytics.download_handler"
log = logging.getLogger(__name__)
ga = Blueprint("google_analytics", "google_analytics")
@ -40,7 +40,9 @@ def action(logic_function, ver=api.API_MAX_VERSION):
ga.add_url_rule(
"/api/action/<logic_function>", methods=["GET", "POST"], view_func=action,
"/api/action/<logic_function>",
methods=["GET", "POST"],
view_func=action,
)
ga.add_url_rule(
u"/<int(min=3, max={0}):ver>/action/<logic_function>".format(
@ -57,11 +59,9 @@ def download(id, resource_id, filename=None, package_type="dataset"):
handler = import_string(handler_path, silent=True)
else:
handler = None
log.warning((
'Missing {} config option.'
).format(CONFIG_HANDLER_PATH))
log.warning(("Missing {} config option.").format(CONFIG_HANDLER_PATH))
if not handler:
log.debug('Use default CKAN callback for resource.download')
log.debug("Use default CKAN callback for resource.download")
handler = resource.download
_post_analytics(
g.user,
@ -71,8 +71,11 @@ def download(id, resource_id, filename=None, package_type="dataset"):
resource_id,
)
return handler(
package_type=package_type, id=id,
resource_id=resource_id, filename=filename)
package_type=package_type,
id=id,
resource_id=resource_id,
filename=filename,
)
ga.add_url_rule(

View File

@ -1,3 +1,63 @@
[tool.black]
line-length = 79
include = '\.py$'
[tool.towncrier]
issue_format = ""
directory = "changes"
package = "ckanext.googleanalytics"
package_dir = "ckanext"
filename = "CHANGELOG.rst"
name = "ckanext-googleanalytics"
[tool.pyright]
pythonVersion = "3.8"
include = ["ckanext/googleanalytics"]
exclude = [
"**/test*",
"**/migration",
]
ignore = [
"ckan"
]
strict = []
strictParameterNoneValue = true # type must be Optional if default value is None
reportFunctionMemberAccess = true # non-standard member accesses for functions
reportMissingImports = true
reportMissingModuleSource = true
reportMissingTypeStubs = false
reportImportCycles = false
reportUnusedImport = false
reportUnusedClass = true
reportUnusedFunction = true
reportUnusedVariable = false
reportDuplicateImport = true
reportOptionalSubscript = true
reportOptionalMemberAccess = true
reportOptionalCall = true
reportOptionalIterable = true
reportOptionalContextManager = true
reportOptionalOperand = true
reportTypedDictNotRequiredAccess = false # We are using Context in a way that conflicts with this check
reportConstantRedefinition = false
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = true
reportOverlappingOverload = true
reportUntypedFunctionDecorator = false
reportUnknownParameterType = false # it creates a lot of noise
reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportMissingTypeArgument = true
reportInvalidTypeVarUse = true
reportCallInDefaultInitializer = true
reportUnknownVariableType = false
reportUntypedBaseClass = false # ignore it because we are relying on untyped CKAN
reportUnnecessaryIsInstance = true
reportUnnecessaryCast = true
reportUnnecessaryComparison = true
reportAssertAlwaysTrue = true
reportSelfClsParameterName = true
reportUnusedCallResult = false # allow function calls for side-effect only (like logic.check_acces)
useLibraryCodeForTypes = true

View File

@ -2,7 +2,7 @@ import os
from setuptools import setup, find_packages
HERE = os.path.dirname(__file__)
version = "2.0.4"
version = "2.0.5"
extras_require = {}
_extras_groups = [