Skip to content

Commit

Permalink
Use ruff for linting and formatting (#44)
Browse files Browse the repository at this point in the history
As a replacement for flake8, black and isort.
  • Loading branch information
markwaddle authored Sep 16, 2024
1 parent 127a3d1 commit e9383bb
Show file tree
Hide file tree
Showing 54 changed files with 372 additions and 455 deletions.
16 changes: 5 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"name": "semantic-workbench",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {
Expand All @@ -21,10 +20,11 @@
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 4000],

"forwardPorts": [
3000,
4000
],
// Use 'portsAttributes' to configure the behavior of specific port forwarding instances.
"portsAttributes": {
"3000": {
Expand All @@ -34,11 +34,9 @@
"label": "app:semantic-workbench"
}
},

// Use 'otherPortsAttributes' to set the defaults that are applied to all ports, unless overridden
// with port-specific entries in 'portsAttributes'.
// "otherPortsAttributes": {},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": {
// Build and restore dependencies for key projects in the repo
Expand All @@ -50,7 +48,6 @@
// Set up git to automatically set up the remote when pushing if it doesn't exist
"git_config": "git config --add push.autoSetupRemote true"
},

// Configure tool-specific properties.
"customizations": {
"vscode": {
Expand All @@ -59,22 +56,20 @@
"github.codespaces",
"aaron-bond.better-comments",
"aarontamasfe.even-better-toml",
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"epivision.vscode-file-header",
"esbenp.prettier-vscode",
"github.vscode-github-actions",
"ms-azuretools.vscode-docker",
"ms-python.black-formatter",
"ms-python.debugpy",
"ms-python.flake8",
"ms-python.python",
"ms-vscode.makefile-tools",
"ms-vscode.vscode-node-azure-pack",
"streetsidesoftware.code-spell-checker"
]
}
}

// Uncomment to run commands after the container is created.
// "containerEnv": {
// Disabled because it is being applied twice for the app because something else is setting it
Expand All @@ -83,7 +78,6 @@
// to use a higher capacity container and/or fewer open projects in the workspace.
// "NODE_OPTIONS": "--max-old-space-size=8192"
// }

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ node_modules
poetry.lock
__pycache__
.pytest_cache
.ruff_cache
.cache
bin/
obj/
Expand All @@ -24,4 +25,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
lerna-debug.log*
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"recommendations": [
"aaron-bond.better-comments",
"aarontamasfe.even-better-toml",
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-vscode.makefile-tools",
"ms-python.python",
"streetsidesoftware.code-spell-checker"
Expand Down
21 changes: 13 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"black-formatter.args": ["--config", "service/.black.toml"],
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
},
"editor.formatOnSave": true,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"flake8.args": ["--config", "service/.flake8"],
"isort.args": ["--profile", "black", "--gitignore"],
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
Expand All @@ -26,7 +23,9 @@
"**/.data/**",
"**/__pycache__/**"
],
"python.analysis.fixAll": ["source.unusedImports"],
"python.analysis.fixAll": [
"source.unusedImports"
],
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "${workspaceFolder}/semantic-workbench/v1/service/.venv",
Expand All @@ -35,14 +34,16 @@
"python.testing.cwd": "${workspaceFolder:v1}/service",
"python.testing.pytestArgs": [],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.unusedImports": "explicit",
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
"source.formatDocument": "explicit"
}
},
"ruff.nativeServer": "on",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
Expand All @@ -57,7 +58,9 @@
"source.fixAll": "explicit"
}
},
"css.lint.validProperties": ["composes"],
"css.lint.validProperties": [
"composes"
],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.lintTask.enable": true,
"editor.formatOnPaste": true,
Expand All @@ -82,7 +85,9 @@
"typescript",
"typescriptreact"
],
"files.associations": { "*.json": "jsonc" },
"files.associations": {
"*.json": "jsonc"
},
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand Down
5 changes: 0 additions & 5 deletions assistants/prospector-assistant/.black.toml

This file was deleted.

3 changes: 0 additions & 3 deletions assistants/prospector-assistant/.flake8

This file was deleted.

9 changes: 4 additions & 5 deletions assistants/prospector-assistant/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"black-formatter.args": ["--config", "./.black.toml"],
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand All @@ -11,8 +10,6 @@
"editor.formatOnSave": true,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"flake8.args": ["--config", "./.flake8"],
"isort.args": ["--profile", "black", "--gitignore"],
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
Expand All @@ -34,14 +31,16 @@
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.unusedImports": "explicit",
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
"source.formatDocument": "explicit"
}
},
"ruff.nativeServer": "on",
"search.exclude": {
"**/.venv": true,
"**/.data": true,
Expand Down
16 changes: 3 additions & 13 deletions assistants/prospector-assistant/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,14 @@ pdfplumber = "^0.11.2"
tiktoken = "^0.7.0"

# If you copy this file to your project, you should verify the relative path to the following:
semantic-workbench-assistant = { path = "../../semantic-workbench/v1/service/semantic-workbench-assistant", develop = true, extras=["dev"] }
semantic-workbench-assistant = { path = "../../semantic-workbench/v1/service/semantic-workbench-assistant", develop = true }

black = { version = "^24.3.0", optional = true }
flake8 = { version = "^6.1.0", optional = true }

[tool.poetry.extras]
dev = ["black", "flake8"]
[tool.poetry.group.dev.dependencies]
ruff = "^0.6.4"

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 120
profile = "black"

[tool.pyright]
exclude = ["venv", ".venv"]
16 changes: 1 addition & 15 deletions build-tools/makefiles/poetry.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export POETRY_VIRTUALENVS_IN_PROJECT
endif

POETRY_PACKAGE ?= .
BLACK_CONFIG ?= .black.toml
FLAKE8_CONFIG ?= .flake8

install_marker_path = .venv/.install-marker-$(notdir $(abspath $(1)))

Expand All @@ -23,24 +21,12 @@ $(POETRY_PACKAGE)/poetry.lock: $(POETRY_PACKAGE)/pyproject.toml
poetry --directory=$(POETRY_PACKAGE) lock

$(call install_marker_path,$(POETRY_PACKAGE)): $(POETRY_PACKAGE)/poetry.lock
poetry --directory=$(POETRY_PACKAGE) install --all-extras
poetry --directory=$(POETRY_PACKAGE) install
@$(call touch,$@)

.PHONY: clean-venv clean
clean-venv clean:
poetry --directory=$(POETRY_PACKAGE) env remove --all

ifneq ($(wildcard $(BLACK_CONFIG)),)
.PHONY: format black
format black: $(call install_marker_path,$(POETRY_PACKAGE))
poetry --directory $(POETRY_PACKAGE) run black --config $(BLACK_CONFIG) .
endif

ifneq ($(wildcard $(FLAKE8_CONFIG)),)
.PHONY: lint
lint flake8: $(call install_marker_path,$(POETRY_PACKAGE))
poetry --directory $(POETRY_PACKAGE) run flake8 --config $(FLAKE8_CONFIG) .
endif

DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include $(DIR)/shell.mk
5 changes: 0 additions & 5 deletions examples/python-01-echo-bot/.black.toml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/python-01-echo-bot/.flake8

This file was deleted.

9 changes: 4 additions & 5 deletions examples/python-01-echo-bot/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"black-formatter.args": ["--config", "./.black.toml"],
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand All @@ -11,8 +10,6 @@
"editor.formatOnSave": true,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"flake8.args": ["--config", "./.flake8"],
"isort.args": ["--profile", "black", "--gitignore"],
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
Expand All @@ -34,14 +31,16 @@
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.unusedImports": "explicit",
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
"source.formatDocument": "explicit"
}
},
"ruff.nativeServer": "on",
"search.exclude": {
"**/.venv": true,
"**/.data": true,
Expand Down
16 changes: 3 additions & 13 deletions examples/python-01-echo-bot/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,14 @@ python = "~3.11"
openai = "^1.3.9"

# If you copy this file to your project, you should verify the relative path to the following:
semantic-workbench-assistant = { path = "../../semantic-workbench/v1/service/semantic-workbench-assistant", develop = true, extras=["dev"] }
semantic-workbench-assistant = { path = "../../semantic-workbench/v1/service/semantic-workbench-assistant", develop = true }

black = { version = "^24.3.0", optional = true }
flake8 = { version = "^6.1.0", optional = true }

[tool.poetry.extras]
dev = ["black", "flake8"]
[tool.poetry.group.dev.dependencies]
ruff = "^0.6.4"

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 120
profile = "black"

[tool.pyright]
exclude = ["venv", ".venv"]
5 changes: 0 additions & 5 deletions examples/python-02-simple-chatbot/.black.toml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/python-02-simple-chatbot/.flake8

This file was deleted.

9 changes: 4 additions & 5 deletions examples/python-02-simple-chatbot/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"black-formatter.args": ["--config", "./.black.toml"],
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand All @@ -11,8 +10,6 @@
"editor.formatOnSave": true,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"flake8.args": ["--config", "./.flake8"],
"isort.args": ["--profile", "black", "--gitignore"],
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
Expand All @@ -34,14 +31,16 @@
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.unusedImports": "explicit",
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
"source.formatDocument": "explicit"
}
},
"ruff.nativeServer": "on",
"search.exclude": {
"**/.venv": true,
"**/.data": true,
Expand Down
Loading

0 comments on commit e9383bb

Please sign in to comment.