Skip to content

Commit f4fa7e7

Browse files
authored
Install and use Ruff to check and format python (#41)
1 parent eb8387b commit f4fa7e7

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

.github/workflows/python_lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check python syntax
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
ruff:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.13"]
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set Python Version
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements-dev.txt
25+
26+
- name: Python Ruff Lint and Format
27+
run: |
28+
ruff check --output-format=github .
29+
ruff format --check --diff

.ruff.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
target-version = "py313"
2+
exclude = ["migrations"]
3+
4+
[lint]
5+
extend-select = [
6+
"B", # flake8-bugbear
7+
"B9", # flake8-bugbear
8+
"C", # mccabe
9+
"E", # pycodestyle errors
10+
"F", # pyflakes
11+
"I", # isort
12+
"RUF100", # unused-noqa
13+
"UP", # pyupgrade
14+
"W", # pycodestyle warnings
15+
]
16+
ignore = [
17+
"C901", # too complex
18+
]

app/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class Plan(db.Model):
3131
__table_args__ = {"postgresql_partition_by": "HASH (id)"}
3232

3333
def as_dict(self):
34-
return dict(
35-
shareId=self.id,
36-
title=self.title,
37-
plan=self.plan,
38-
sql=self.sql,
39-
)
34+
return {
35+
"shareId": self.id,
36+
"title": self.title,
37+
"plan": self.plan,
38+
"sql": self.sql,
39+
}
4040

4141

4242
@app.route("/")
@@ -87,7 +87,7 @@ def save(json=False):
8787
result = query.fetchone()[0]
8888
(id, delete_key) = tuple(x for x in result[1:-1].split(","))
8989
if json:
90-
return jsonify(dict(id=id, deleteKey=delete_key))
90+
return jsonify({"id": id, "deleteKey": delete_key})
9191
return redirect(url_for("plan_from_db", id=id))
9292
return redirect(url_for("index"))
9393

@@ -148,7 +148,7 @@ def generate_tags(entrypoint, tags):
148148
if "css" in manifest_entry:
149149
tags.append(build_css_tag(manifest_entry["css"]))
150150

151-
return dict(assets=load_assets)
151+
return {"assets": load_assets}
152152

153153

154154
@app.route("/plan_error")

config.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import os
2+
23
WTF_CSRF_ENABLED = False
3-
SECRET_KEY = os.environ.get('SECRET_KEY', 'aSup3rS33kret')
4-
DB_NAME = os.environ.get('DB_NAME', 'postgres')
5-
DB_USER = os.environ.get('DB_USER', 'postgres')
6-
DB_PASS = os.environ.get('DB_PASS', 'postgres')
7-
DB_SERVICE = os.environ.get('DB_SERVICE', '0.0.0.0')
8-
DB_PORT = os.environ.get('DB_PORT', 5432)
9-
SQLALCHEMY_DATABASE_URI = 'postgresql://{0}:{1}@{2}:{3}/{4}'.format(
10-
DB_USER, DB_PASS, DB_SERVICE, DB_PORT, DB_NAME
4+
SECRET_KEY = os.environ.get("SECRET_KEY", "aSup3rS33kret")
5+
DB_NAME = os.environ.get("DB_NAME", "postgres")
6+
DB_USER = os.environ.get("DB_USER", "postgres")
7+
DB_PASS = os.environ.get("DB_PASS", "postgres")
8+
DB_SERVICE = os.environ.get("DB_SERVICE", "0.0.0.0")
9+
DB_PORT = os.environ.get("DB_PORT", 5432)
10+
SQLALCHEMY_DATABASE_URI = (
11+
f"postgresql://{DB_USER}:{DB_PASS}@{DB_SERVICE}:{DB_PORT}/{DB_NAME}"
1112
)
1213
DEBUG_TB_INTERCEPT_REDIRECTS = False
1314
DEBUG_TB_PROFILER_ENABLED = True

requirements-dev.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
flake8
2-
black
3-
isort
1+
ruff

0 commit comments

Comments
 (0)