Skip to content

Commit 66e32b8

Browse files
author
Seva D
authored
Added RUFF linter. Cleaned up code. Removed pydantic dependency. (#32)
Added RUFF linter. Cleaned up code. Removed pydantic dependency.
1 parent ebde828 commit 66e32b8

76 files changed

Lines changed: 1231 additions & 2072 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ jobs:
1919
cache: 'yarn'
2020
cache-dependency-path: 'frontend/yarn.lock'
2121
- name: Install Dependencies
22-
run: |
23-
make install
22+
run: make install
2423
- name: Run Lint
2524
run: make lint
2625
- name: Run Tests

Makefile

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,88 @@
11
.PHONY: clean
22
clean:
3-
find . -type d -name "__pycache__" -exec rm -rf {} + > /dev/null 2>&1
4-
find . -type f -name "*.pyc" -exec rm -rf {} + > /dev/null 2>&1
5-
rm -rf htmlcov
6-
rm -rf .coverage
3+
@exec find . -type d -name "__pycache__" -exec rm -rf {} + > /dev/null 2>&1
4+
@exec find . -type f -name "*.pyc" -exec rm -rf {} + > /dev/null 2>&1
5+
@exec rm -rf htmlcov
6+
@exec rm -rf .coverage
77

88
.PHONY: fix
99
fix:
10-
poetry run pyupgrade --exit-zero-even-if-changed --py39-plus fastadmin/**/*.py tests/**/*.py
11-
poetry run isort --settings-path pyproject.toml fastadmin tests
12-
poetry run black --config pyproject.toml fastadmin tests
13-
cd frontend && make fix
10+
@echo "Run ruff"
11+
@exec poetry run ruff --fix fastadmin tests examples docs
12+
@echo "Run isort"
13+
@exec poetry run isort fastadmin tests examples docs
14+
@echo "Run black"
15+
@exec poetry run black fastadmin tests examples docs
16+
@echo "Run mypy"
17+
@exec poetry run mypy -p fastadmin -p tests -p examples -p docs
18+
@echo "Run frontend linters"
19+
@exec make -C frontend fix
1420

1521
.PHONY: lint
1622
lint:
17-
poetry run isort --diff --check-only --settings-path pyproject.toml fastadmin tests
18-
poetry run black --diff --check --config pyproject.toml fastadmin tests
19-
poetry run flake8 --show-source --config .flake8 fastadmin tests
20-
poetry run mypy --show-error-code --install-types --non-interactive --namespace-packages --show-traceback --config-file pyproject.toml fastadmin
21-
cd frontend && make lint
23+
@echo "Run ruff"
24+
@exec poetry run ruff fastadmin tests examples docs
25+
@echo "Run isort"
26+
@exec poetry run isort --check-only fastadmin tests examples docs
27+
@echo "Run black"
28+
@exec poetry run black --check --diff fastadmin tests examples docs
29+
@echo "Run mypy"
30+
@exec poetry run mypy -p fastadmin -p tests -p examples -p docs
31+
@echo "Run frontend linters"
32+
@exec make -C frontend lint
2233

2334
.PHONY: test
2435
test:
25-
poetry run python generate_db.py
26-
ADMIN_ENV_FILE=example.env poetry run pytest --cov=fastadmin --cov-report=term-missing --cov-report=xml --cov-fail-under=90 -s tests
27-
cd frontend && make test
36+
@exec poetry run python generate_db.py
37+
@exec env ADMIN_ENV_FILE=example.env poetry run pytest --cov=fastadmin --cov-report=term-missing --cov-report=xml --cov-fail-under=90 -s tests
38+
@exec make -C frontend test
2839

2940
.PHONY: kill
3041
kill:
31-
kill -9 $$(lsof -t -i:8090)
32-
kill -9 $$(lsof -t -i:3030)
42+
@exec kill -9 $$(lsof -t -i:8090)
43+
@exec kill -9 $$(lsof -t -i:3030)
3344

3445
.PHONY: collectstatic
3546
collectstatic:
36-
rm -rf ./fastadmin/static/js
37-
rm -rf ./fastadmin/static/css
38-
cp -rf ./frontend/build/static/js/ ./fastadmin/static/js/
39-
cp -rf ./frontend/build/static/css/ ./fastadmin/static/css/
40-
mv fastadmin/static/js/main*.js fastadmin/static/js/main.min.js
41-
mv fastadmin/static/css/main*.css fastadmin/static/css/main.min.css
42-
rm fastadmin/static/js/*.txt
47+
@exec rm -rf ./fastadmin/static/js
48+
@exec rm -rf ./fastadmin/static/css
49+
@exec cp -rf ./frontend/build/static/js/ ./fastadmin/static/js/
50+
@exec cp -rf ./frontend/build/static/css/ ./fastadmin/static/css/
51+
@exec mv fastadmin/static/js/main*.js fastadmin/static/js/main.min.js
52+
@exec mv fastadmin/static/css/main*.css fastadmin/static/css/main.min.css
53+
@exec rm fastadmin/static/js/*.txt
4354

4455
.PHONY: install
4556
install:
46-
poetry install --all-extras
47-
make -C frontend install
57+
@exec poetry install --all-extras
58+
@exec make -C frontend install
4859

4960

5061
.PHONY: docs
5162
docs:
52-
make -C docs build
53-
cp ./docs/README.md ./README.md
63+
@exec make -C docs build
5464

5565

5666
.PHONY: build
5767
build:
58-
make docs
59-
make -C frontend build
60-
make collectstatic
68+
@exec make docs
69+
@exec make -C frontend build
70+
@exec make collectstatic
6171

6272
.PHONY: pre-commit-install
6373
pre-commit-install:
64-
poetry run pip install pre-commit
65-
poetry run pre-commit install
74+
@exec poetry run pip install pre-commit
75+
@exec poetry run pre-commit install
6676

6777
.PHONY: pre-commit
6878
pre-commit:
69-
poetry run pre-commit run --all-files
79+
@exec poetry run pre-commit run --all-files
7080

7181
.PHONY: push
72-
push:
73-
make fix
74-
make lint
75-
make test
76-
make build
77-
make pre-commit
78-
git stash
79-
git checkout main
80-
git pull origin main
81-
git stash pop
82-
git add .
83-
git commit -am "$(message)"
84-
git push origin main
82+
pre-push:
83+
@exec make fix
84+
@exec make lint
85+
@exec make pre-commit-install
86+
@exec make pre-commit
87+
@exec make docs
88+
@exec make build

README.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Install the package using pip:
133133

134134

135135

136-
Note: For zsh and macos use: <code>pip install fastadmin\[fastapi,django\]</code>
136+
Note: For zsh and macos use: <code>pip install fastadmin[fastapi,django]</code>
137137

138138

139139

@@ -314,8 +314,8 @@ Setup FastAdmin for a framework
314314

315315
```python
316316
from fastapi import FastAPI
317-
from fastadmin import fastapi_app as admin_app
318317

318+
from fastadmin import fastapi_app as admin_app
319319

320320
app = FastAPI()
321321

@@ -373,8 +373,8 @@ urlpatterns = [
373373

374374
```python
375375
from flask import Flask
376-
from fastadmin import flask_app as admin_app
377376

377+
from fastadmin import flask_app as admin_app
378378

379379
app = Flask(__name__)
380380

@@ -433,13 +433,13 @@ Register ORM models
433433

434434

435435
```python
436-
import bcrypt
437436
from uuid import UUID
438437

439-
from tortoise.models import Model
438+
import bcrypt
440439
from tortoise import fields
440+
from tortoise.models import Model
441441

442-
from fastadmin import register, TortoiseModelAdmin
442+
from fastadmin import TortoiseModelAdmin, register
443443

444444

445445
class User(Model):
@@ -449,7 +449,7 @@ class User(Model):
449449
is_active = fields.BooleanField(default=False)
450450

451451
def __str__(self):
452-
return self.username
452+
return self.username
453453

454454

455455
@register(User)
@@ -501,7 +501,7 @@ class User(models.Model):
501501
is_active = models.BooleanField(default=False)
502502

503503
def __str__(self):
504-
return self.username
504+
return self.username
505505

506506

507507
@register(User)
@@ -542,20 +542,14 @@ class UserAdmin(DjangoModelAdmin):
542542

543543
```python
544544
import bcrypt
545-
from sqlalchemy import (
546-
Boolean,
547-
String,
548-
Integer,
549-
select,
550-
)
545+
from sqlalchemy import Boolean, Integer, String, select
546+
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
551547
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
552-
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
553548

554549
from fastadmin import SqlAlchemyModelAdmin, register
555550

556-
557551
sqlalchemy_engine = create_async_engine(
558-
f"sqlite+aiosqlite:///:memory:",
552+
"sqlite+aiosqlite:///:memory:",
559553
echo=True,
560554
)
561555
sqlalchemy_sessionmaker = async_sessionmaker(sqlalchemy_engine, expire_on_commit=False)
@@ -575,7 +569,7 @@ class User(Base):
575569
is_active: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
576570

577571
def __str__(self):
578-
return self.username
572+
return self.username
579573

580574

581575
@register(User, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
@@ -628,7 +622,7 @@ db = Database()
628622
db.bind(provider="sqlite", filename=":memory:", create_db=True)
629623

630624

631-
class User(db.Entity):
625+
class User(db.Entity): # type: ignore [name-defined]
632626
_table_ = "user"
633627
id = PrimaryKey(int, auto=True)
634628
username = Required(str)
@@ -637,7 +631,7 @@ class User(db.Entity):
637631
is_active = Required(bool, default=False)
638632

639633
def __str__(self):
640-
return self.username
634+
return self.username
641635

642636

643637
@register(User)

0 commit comments

Comments
 (0)