From 45c20794a7372b6567b3fee75cc161871cf3f0b6 Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Thu, 25 Jan 2024 17:44:58 +0200 Subject: [PATCH] chore: install linters --- .github/workflows/test.yml | 1 - .pre-commit-config.yaml | 38 +++++++++ CHANGELOG.md | 1 - Makefile | 3 - ckanext/__init__.py | 2 + ckanext/charts/tests/test_plugin.py | 56 ------------ ckanext/charts/types.py | 2 + pyproject.toml | 127 ++++++++++++++++++++++++++++ setup.cfg | 49 +++++++++-- setup.py | 100 ++-------------------- 10 files changed, 217 insertions(+), 162 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ccfdfe..02b724b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,4 +45,3 @@ jobs: ckan -c test.ini db init - name: Run tests run: pytest --ckan-ini=test.ini --cov=ckanext.charts --disable-warnings ckanext/charts - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..12e8ae6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +default_install_hook_types: +- pre-commit +- pre-push +- commit-msg + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + # - id: check-yaml + - id: end-of-file-fixer + stages: [pre-commit] + - id: trailing-whitespace + stages: [pre-commit] + - id: debug-statements + stages: [pre-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 + stages: [pre-commit] + +## Ruff +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.260 + hooks: + - id: ruff + stages: [pre-commit] diff --git a/CHANGELOG.md b/CHANGELOG.md index 171d2f9..6556e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,4 +17,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [v0.0.1](https://github.com/DataShades/ckanext-charts/releases/tag/v0.0.1) - 2021-09-01 [Compare with first commit](https://github.com/DataShades/ckanext-charts/compare/e6de562696bc54582001c3b06bb423d29853f308...v0.0.1) - diff --git a/Makefile b/Makefile index 7bed9f1..787e9b3 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,3 @@ help: changelog: ## compile changelog git changelog -c conventional -o CHANGELOG.md - -vendor: - cp node_modules/chart.js/dist/chart.umd.js ckanext/charts/assets/vendor/chart.js diff --git a/ckanext/__init__.py b/ckanext/__init__.py index ed48ed0..35ee891 100644 --- a/ckanext/__init__.py +++ b/ckanext/__init__.py @@ -3,7 +3,9 @@ # this is a namespace package try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/ckanext/charts/tests/test_plugin.py b/ckanext/charts/tests/test_plugin.py index 3a00373..e69de29 100644 --- a/ckanext/charts/tests/test_plugin.py +++ b/ckanext/charts/tests/test_plugin.py @@ -1,56 +0,0 @@ -""" -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: -https://docs.ckan.org/en/2.9/contributing/testing.html - -To write tests for your extension you should install the pytest-ckan package: - - pip install pytest-ckan - -This will allow you to use CKAN specific fixtures on your tests. - -For instance, if your test involves database access you can use `clean_db` to -reset the database: - - import pytest - - from ckan.tests import factories - - @pytest.mark.usefixtures("clean_db") - def test_some_action(): - - dataset = factories.Dataset() - - # ... - -For functional tests that involve requests to the application, you can use the -`app` fixture: - - from ckan.plugins import toolkit - - def test_some_endpoint(app): - - url = toolkit.url_for('myblueprint.some_endpoint') - - response = app.get(url) - - assert response.status_code == 200 - - -To temporary patch the CKAN configuration for the duration of a test you can use: - - import pytest - - @pytest.mark.ckan_config("ckanext.myext.some_key", "some_value") - def test_some_action(): - pass -""" -import ckanext.charts.plugin as plugin - - -@pytest.mark.ckan_config("ckan.plugins", "charts") -@pytest.mark.usefixtures("with_plugins") -def test_plugin(): - assert plugin_loaded("charts") diff --git a/ckanext/charts/types.py b/ckanext/charts/types.py index 8b02d00..babcbbf 100644 --- a/ckanext/charts/types.py +++ b/ckanext/charts/types.py @@ -1,8 +1,10 @@ from __future__ import annotations + from typing import Any, Iterable from typing_extensions import TypedDict + class ChartJsDataset(TypedDict): label: str data: Iterable[Any] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d23a4b7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,127 @@ +[tool.black] +# line-length = 88 +# preview = true + +[tool.ruff] +target-version = "py38" +select = [ + # "B", # likely bugs and design problems + # "BLE", # do not catch blind exception + # "C40", # better list/set/dict comprehensions + # "C90", # check McCabe complexity + # "COM", # trailing commas + "E", # pycodestyle error + # "W", # pycodestyle warning + "F", # pyflakes + # "G", # format strings for logging statements + # "N", # naming conventions + # "PL", # pylint + # "PT", # pytest style + # "PIE", # misc lints + # "Q", # preferred quoting style + # "RET", # improvements for return statements + # "RSE", # improvements for rise statements + # "S", # security testing + # "SIM", # simplify code + # "T10", # debugging statements + # "T20", # print statements + # "TID", # tidier imports + # "TRY", # better exceptions + # "UP", # upgrade syntax for newer versions of the language +] +ignore = [ + "E712", # comparison to bool: violated by SQLAlchemy filters + "PT004", # fixture does not return anything, add leading underscore: violated by clean_db + "PLC1901", # simplify comparison to empty string: violated by SQLAlchemy filters +] + +[tool.ruff.per-file-ignores] +"ckanext/charts/tests*" = ["S", "PL"] + +[tool.isort] +known_ckan = "ckan" +known_ckanext = "ckanext" +known_self = "ckanext.charts" +sections = "FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,CKAN,CKANEXT,SELF,LOCALFOLDER" +profile = "black" + +[tool.pytest.ini_options] +addopts = "--ckan-ini test.ini" +filterwarnings = [ + "ignore::sqlalchemy.exc.SADeprecationWarning", + "ignore::sqlalchemy.exc.SAWarning", + "ignore::DeprecationWarning", +] + +[tool.pyright] +pythonVersion = "3.8" +include = ["ckanext"] +exclude = [ + "**/test*", + "**/migration", +] +strict = [] + +strictParameterNoneValue = true + +# Check the meaning of rules here +# https://github.com/microsoft/pyright/blob/main/docs/configuration.md +reportFunctionMemberAccess = true # non-standard member accesses for functions +reportMissingImports = true +reportMissingModuleSource = true +reportMissingTypeStubs = false +reportImportCycles = true +reportUnusedImport = true +reportUnusedClass = true +reportUnusedFunction = true +reportUnusedVariable = true +reportDuplicateImport = true +reportOptionalSubscript = true +reportOptionalMemberAccess = true +reportOptionalCall = true +reportOptionalIterable = true +reportOptionalContextManager = true +reportOptionalOperand = true +reportTypedDictNotRequiredAccess = false # Context won't work with this rule +reportConstantRedefinition = true +reportIncompatibleMethodOverride = true +reportIncompatibleVariableOverride = true +reportOverlappingOverload = true +reportUntypedFunctionDecorator = false +reportUnknownParameterType = true +reportUnknownArgumentType = false +reportUnknownLambdaType = false +reportUnknownMemberType = false +reportMissingTypeArgument = true +reportInvalidTypeVarUse = true +reportCallInDefaultInitializer = true +reportUnknownVariableType = true +reportUntypedBaseClass = true +reportUnnecessaryIsInstance = true +reportUnnecessaryCast = true +reportUnnecessaryComparison = true +reportAssertAlwaysTrue = true +reportSelfClsParameterName = true +reportUnusedCallResult = false # allow function calls for side-effect only +useLibraryCodeForTypes = true +reportGeneralTypeIssues = true +reportPropertyTypeMismatch = true +reportWildcardImportFromLibrary = true +reportUntypedClassDecorator = false +reportUntypedNamedTuple = true +reportPrivateUsage = true +reportPrivateImportUsage = true +reportInconsistentConstructor = true +reportMissingSuperCall = false +reportUninitializedInstanceVariable = true +reportInvalidStringEscapeSequence = true +reportMissingParameterType = true +reportImplicitStringConcatenation = false +reportUndefinedVariable = true +reportUnboundVariable = true +reportInvalidStubStatement = true +reportIncompleteStub = true +reportUnsupportedDunderAll = true +reportUnusedCoroutine = true +reportUnnecessaryTypeIgnoreComment = true +reportMatchNotExhaustive = true diff --git a/setup.cfg b/setup.cfg index 5f8dd67..fd6044a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,46 @@ +[metadata] +name = ckanext-charts +version = 0.0.2 +description = +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/DataShades/ckanext-charts +author = Sergey Motornyuk +author_email = sergey.motornyuk@linkdigital.com.au +license = AGPL +classifiers = + Development Status :: 4 - Beta + License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + +keywords = CKAN + +[options] +python_requires = >= 3.8 +packages = find: +namespace_packages = ckanext +install_requires = + typing-extensions>=4.4.0 +include_package_data = True + +[options.entry_points] +ckan.plugins = + charts = ckanext.charts.plugin:ChartsPlugin + +babel.extractors = + ckan = ckan.lib.extract:extract_ckan + +[options.extras_require] +test = + pytest-ckan + ckanext-toolbelt + +dev = + %(test)s + [extract_messages] keywords = translate isPlural add_comments = TRANSLATORS: @@ -19,9 +62,3 @@ previous = true domain = ckanext-charts directory = ckanext/charts/i18n statistics = true - -[tool:pytest] -filterwarnings = - ignore::sqlalchemy.exc.SADeprecationWarning - ignore::sqlalchemy.exc.SAWarning - ignore::DeprecationWarning diff --git a/setup.py b/setup.py index d51b33b..288c82d 100644 --- a/setup.py +++ b/setup.py @@ -1,105 +1,15 @@ -# -*- coding: utf-8 -*- -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -from codecs import open # To use a consistent encoding -from os import path - -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-charts''', - - # 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.0.2', - - description='''''', - long_description=long_description, - long_description_content_type="text/markdown", - - # The project's main homepage. - url='https://github.com/DataShades/ckanext-charts', - - # Author details - author='''Sergey Motornyuk''', - author_email='''sergey.motornyuk@linkdigital.com.au''', - - # 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 - "typing_extensions", - ], - - # 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 '/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] - charts=ckanext.charts.plugin:ChartsPlugin - - [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 # http://babel.pocoo.org/docs/messages/#extraction-method-mapping-and-configuration message_extractors={ - 'ckanext': [ - ('**.py', 'python', None), - ('**.js', 'javascript', None), - ('**/templates/**.html', 'ckan', None), + "ckanext": [ + ("**.py", "python", None), + ("**.js", "javascript", None), + ("**/templates/**.html", "ckan", None), ], } )