Skip to content

Commit

Permalink
chore: install linters
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jan 25, 2024
1 parent c410690 commit 45c2079
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 162 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<small>[Compare with first commit](https://github.com/DataShades/ckanext-charts/compare/e6de562696bc54582001c3b06bb423d29853f308...v0.0.1)</small>

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions ckanext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
56 changes: 0 additions & 56 deletions ckanext/charts/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions ckanext/charts/types.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
127 changes: 127 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 43 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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 = [email protected]
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:
Expand All @@ -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
Loading

0 comments on commit 45c2079

Please sign in to comment.