From 29626fcc48f22649e0b2c4ad62752f341298be14 Mon Sep 17 00:00:00 2001 From: boxydog Date: Mon, 15 Jan 2024 20:33:49 -0600 Subject: [PATCH 1/8] Fix syntax error in askbot_add_osqa_content.py --- askbot/management/commands/askbot_add_osqa_content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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') From 40b37b99d2fcd524202ca83f3b3146de26e8953d Mon Sep 17 00:00:00 2001 From: boxydog Date: Mon, 15 Jan 2024 20:34:03 -0600 Subject: [PATCH 2/8] Add a plain .pre-commit-config.yaml --- .pre-commit-config.yaml | 90 +++++++++++++++++++++++++++++++++++++++++ README.md | 13 ++++++ pyproject.toml | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml 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..15e2a7d6cf 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,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/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..01149411fc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,71 @@ +[project] +requires-python = ">=3.8" +target-version = "py38" + +[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"] From 6977c000a384c2d4fa384617877e001cb9b74197 Mon Sep 17 00:00:00 2001 From: boxydog Date: Mon, 15 Jan 2024 20:35:17 -0600 Subject: [PATCH 3/8] Run pre-commit in github tests --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ef7937c127..d6a552949c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,12 @@ 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 From 39623b1015532cb4e67a7b96184759bca0f49ea4 Mon Sep 17 00:00:00 2001 From: boxydog Date: Mon, 15 Jan 2024 20:43:11 -0600 Subject: [PATCH 4/8] Fix prproject.toml --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 01149411fc..26b074fa05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,9 @@ +# pyproject.toml duplicates some information in setup.py +# However, setup.py is deprecated, and pyproject.toml is needed for ruff config [project] +name = "askbot" requires-python = ">=3.8" -target-version = "py38" +version = "0.12.2" [tool.ruff] # exclude Django migrations From 8d4df657d0da4b82e28a7f4ac0d4591ce108a780 Mon Sep 17 00:00:00 2001 From: boxydog Date: Tue, 16 Jan 2024 07:15:14 -0600 Subject: [PATCH 5/8] tweak comment --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 26b074fa05..e052402c9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,7 @@ # pyproject.toml duplicates some information in setup.py -# However, setup.py is deprecated, and pyproject.toml is needed for ruff config +# 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" From 6e9e57f24c010b4f178abe4ee7f1f0ef51dd8bd2 Mon Sep 17 00:00:00 2001 From: boxydog Date: Tue, 16 Jan 2024 07:18:56 -0600 Subject: [PATCH 6/8] get VERSION dynamically in pyproject.toml --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e052402c9c..9779159100 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,10 @@ [project] name = "askbot" requires-python = ">=3.8" -version = "0.12.2" +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "askbot.VERSION"} [tool.ruff] # exclude Django migrations From a4261bd76deda451005a86b70da4ed6e703b7002 Mon Sep 17 00:00:00 2001 From: boxydog Date: Tue, 16 Jan 2024 08:25:42 -0600 Subject: [PATCH 7/8] Make pyproject.toml legal for building by declaring more dynamic elements --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9779159100..8e2eb05307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ [project] name = "askbot" requires-python = ">=3.8" -dynamic = ["version"] +dynamic = ["version", "dependencies", "scripts", "classifiers", "license", + "description", "readme", "authors", "keywords"] [tool.setuptools.dynamic] version = {attr = "askbot.VERSION"} From 9e28b9495a472cc5b1e836aac3db52d9421cbf96 Mon Sep 17 00:00:00 2001 From: boxydog Date: Tue, 16 Jan 2024 10:59:05 -0600 Subject: [PATCH 8/8] Use non-deprecated form of installation with setuptools --- .github/workflows/tests.yml | 4 +++- README.md | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d6a552949c..7690ce4c42 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,7 +40,9 @@ jobs: 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/README.md b/README.md index 15e2a7d6cf..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: - - 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 +Install as follows: + +``` +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.