diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ef7937c127..7690ce4c42 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,11 +30,19 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + # see https://github.com/pre-commit/action/#using-this-action + - name: pre-commit checks + uses: pre-commit/action@v2.0.0 + env: + # it's okay for github to commit to main/master + SKIP: no-commit-to-branch - name: Install dependencies run: | python -m pip install --upgrade pip pip install setuptools-rust - python setup.py install + # replacement for "python setup.py install" + # See also https://packaging.python.org/en/latest/discussions/setup-py-deprecated/#setup-py-deprecated + python -m pip install . pip install -r requirements-tests.txt cat askbot_setup_test_inputs.txt | askbot-setup - name: Run tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..9d7aab0360 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,90 @@ +# See http://pre-commit.com/#python +# See https://github.com/pre-commit/pre-commit-hooks +# Run 'pre-commit install' to install the pre-commit hooks +repos: + +# TODO: enable +#- repo: https://github.com/adamchainz/django-upgrade +# rev: 1.15.0 +# hooks: +# - id: django-upgrade +# args: [--target-version, "4.2"] + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + # TODO: enable check-docstring-first + # - id: check-docstring-first + - id: check-merge-conflict + - id: check-symlinks + - id: debug-statements + - id: detect-private-key + # ruff format will handle quoting + # - id: double-quote-string-fixer + # TODO: enable each of these, one at a time: + # - id: end-of-file-fixer + # - id: mixed-line-ending + # - id: trailing-whitespace + # exclude: (.csv|.tsv)$ + # - id: pretty-format-json + # args: ['--no-sort-keys', '--autofix'] + # don't commit directly to main or master + - id: no-commit-to-branch + +# TODO: enable auto-formatting of Django templates (html, css, js) +#- repo: https://github.com/rtts/djhtml +# rev: '3.0.6' +# hooks: +# - id: djhtml +# - id: djcss +# - id: djjs + +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.5 + hooks: + - id: ruff + args: ["--fix"] + # TODO: ruff-format + # - id: ruff-format + +# ruff does not re-implement all of pylint, see https://github.com/astral-sh/ruff/issues/970 +# TODO: put back pylint +#- repo: https://github.com/PyCQA/pylint +# rev: v3.0.1 +# hooks: +# - id: pylint +# args: +# # black is controlling line length: +# - --disable=line-too-long +# # let's not worry too much right now about dup code. +# - --disable=duplicate-code +# - --disable=fixme +# - --disable=import-error +# - --disable=logging-fstring-interpolation +# - --disable=missing-class-docstring +# - --disable=missing-function-docstring +# - --disable=missing-module-docstring +# - --disable=too-few-public-methods +# - --disable=too-many-arguments +# # - --disable=too-many-branches +# - --disable=too-many-locals +# # isort is taking care of import order: +# - --disable=wrong-import-order +# # re-enable these args +# - --disable=unused-argument +# - --disable=invalid-name +# - --disable=raise-missing-from + +#- repo: https://github.com/Lucas-C/pre-commit-hooks +# rev: v1.5.4 +# hooks: +# # TODO: enable forbid-crlf and forbid-tabs +# # - id: forbid-crlf +# # don't remove-crlf, seems dangerous +# # - id: remove-crlf +# # - id: forbid-tabs +# # don't remove-tabs, seems dangerous +# # - id: remove-tabs diff --git a/README.md b/README.md index 2fb196d299..2f1da4d790 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,16 @@ Branch `0.7.x` - is the latest version supporting Django 1.5 ## Installation -Installation was tested with Python 3.7 with the following commands: +Install as follows: - pip install --upgrade pip - pip install setuptools-rust - python setup.py install - askbot-setup # answer the questions or use parameters to askbot-setup - cd # substitute with the actual directory, default is `askbot_site` - python manage.py migrate # assumes that the database specified by askbot-setup is available +``` +pip install --upgrade pip +pip install setuptools-rust +python -m pip install . +askbot-setup # answer the questions or use parameters to askbot-setup +cd # substitute with the actual directory, default is `askbot_site` +python manage.py migrate # assumes that the database specified by askbot-setup is available +``` The last command above will create a working Django project in the project root directory that you specify with the `askbot-setup` script. @@ -52,6 +54,19 @@ All documentation is in the directory askbot/doc Follow https://help.github.com/articles/fork-a-repo to to learn how to use `fetch` and `push` as well as other help on using git. +pre-commit +========== + +This repository uses [pre-commit](https://pre-commit.com/) to check +some code rules, so please install it: + +``` +$ pre-commit install +``` + +It will then check the rules upon `git commit`. + + License, copyright and trademarks ================================= Askbot software is licensed under GPL, version 3. diff --git a/askbot/management/commands/askbot_add_osqa_content.py b/askbot/management/commands/askbot_add_osqa_content.py index 225f615b50..0630f25f49 100644 --- a/askbot/management/commands/askbot_add_osqa_content.py +++ b/askbot/management/commands/askbot_add_osqa_content.py @@ -177,7 +177,7 @@ def import_users(self): self.copy_bool_parameter(from_user, to_user, 'is_staff') self.copy_bool_parameter(from_user, to_user, 'is_active') self.copy_bool_parameter(from_user, to_user, 'is_superuser') - if from.user.is_superuser: + if from_user.is_superuser: to_user.set_status('d') self.copy_numeric_parameter(from_user, to_user, 'last_login', operator='max') self.copy_numeric_parameter(from_user, to_user, 'date_joined', operator='min') diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..8e2eb05307 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,80 @@ +# pyproject.toml duplicates some information in setup.py +# However, pyproject.toml is now standard, and needed for ruff config +# See also https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html +# See also https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ +[project] +name = "askbot" +requires-python = ">=3.8" +dynamic = ["version", "dependencies", "scripts", "classifiers", "license", + "description", "readme", "authors", "keywords"] + +[tool.setuptools.dynamic] +version = {attr = "askbot.VERSION"} + +[tool.ruff] +# exclude Django migrations +extend-exclude = ["**/migrations"] + +[tool.ruff.lint] +# add more rules +# see https://docs.astral.sh/ruff/configuration/#using-pyprojecttoml +# "F" contains autoflake, see https://github.com/astral-sh/ruff/issues/1647 +# These are all TODO, because they make so many changes. +# I put ** on some to do earlier. +select = [ + # default Ruff checkers as of ruff 0.1.3: E4, E7, E9, F + # ** TODO: "E4", + # ** TODO: "E7", + # ** TODO: "E9", + # ** TODO: "F", # pyflakes + + # the rest in alphabetical order: + # TODO: "A", # flake8-builtins + # TODO: "ARG", # flake8-unused-arguments + # TODO: "B", # flake8-bugbear + # TODO: "BLE", # flake8-blind-except + # TODO: Do I want "COM", # flake8-commas + # TODO: "C4", # flake8-comprehensions + # ** TODO: "DJ", # flake8-django + # TODO: "DTZ", # flake8-datetimez + # TODO: "EM", # flake8-errmsg + # ** TODO: "EXE", # flake8-executable + # TODO: "FURB", # refurb + # TODO: "FBT", # flake8-boolean-trap + # TODO: "G", # flake8-logging-format + # ** TODO: "I", # isort + # TODO: "ICN", # flake8-import-conventions + # TODO: "INP", # flake8-no-pep420 + # TODO: "INT", # flake8-gettext + # TODO: "ISC", # flake8-implicit-str-concat + # TODO: "LOG", # flake8-logging + # TODO: "PERF", # perflint + # TODO: "PIE", # flake8-pie + # TODO: "PL", # pylint + # TODO: "PYI", # flake8-pyi + # TODO: "RET", # flake8-return + # TODO: "RSE", # flake8-raise + # TODO: "RUF", + # TODO: "SIM", # flake8-simplify + # TODO: "SLF", # flake8-self + # TODO: "SLOT", # flake8-slots + # TODO: "TID", # flake8-tidy-imports + # ** TODO: "UP", # pyupgrade + # ** TODO: "Q", # flake8-quotes + # TODO: "TCH", # flake8-type-checking + # TODO: "T10", # flake8-debugger + # ** TODO: "T20", # flake8-print + # TODO: "S", # flake8-bandit + # TODO: "YTT", # flake8-2020 + # TODO: add more flake8 rules +] + +# rules to ignore globally: +ignore = [ +] + +[tool.ruff.lint.extend-per-file-ignores] + +# per-file ignores +#"**/migrations/*" = ["Q"] +#"**/management/commands/*" = ["T20"]