Skip to content

Commit

Permalink
Added RUFF linter. Cleaned up code. Removed pydantic dependency. (#32)
Browse files Browse the repository at this point in the history
Added RUFF linter. Cleaned up code. Removed pydantic dependency.
  • Loading branch information
Seva D authored Jun 10, 2023
1 parent ebde828 commit 66e32b8
Show file tree
Hide file tree
Showing 76 changed files with 1,231 additions and 2,072 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: Install Dependencies
run: |
make install
run: make install
- name: Run Lint
run: make lint
- name: Run Tests
Expand Down
100 changes: 52 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,84 +1,88 @@
.PHONY: clean
clean:
find . -type d -name "__pycache__" -exec rm -rf {} + > /dev/null 2>&1
find . -type f -name "*.pyc" -exec rm -rf {} + > /dev/null 2>&1
rm -rf htmlcov
rm -rf .coverage
@exec find . -type d -name "__pycache__" -exec rm -rf {} + > /dev/null 2>&1
@exec find . -type f -name "*.pyc" -exec rm -rf {} + > /dev/null 2>&1
@exec rm -rf htmlcov
@exec rm -rf .coverage

.PHONY: fix
fix:
poetry run pyupgrade --exit-zero-even-if-changed --py39-plus fastadmin/**/*.py tests/**/*.py
poetry run isort --settings-path pyproject.toml fastadmin tests
poetry run black --config pyproject.toml fastadmin tests
cd frontend && make fix
@echo "Run ruff"
@exec poetry run ruff --fix fastadmin tests examples docs
@echo "Run isort"
@exec poetry run isort fastadmin tests examples docs
@echo "Run black"
@exec poetry run black fastadmin tests examples docs
@echo "Run mypy"
@exec poetry run mypy -p fastadmin -p tests -p examples -p docs
@echo "Run frontend linters"
@exec make -C frontend fix

.PHONY: lint
lint:
poetry run isort --diff --check-only --settings-path pyproject.toml fastadmin tests
poetry run black --diff --check --config pyproject.toml fastadmin tests
poetry run flake8 --show-source --config .flake8 fastadmin tests
poetry run mypy --show-error-code --install-types --non-interactive --namespace-packages --show-traceback --config-file pyproject.toml fastadmin
cd frontend && make lint
@echo "Run ruff"
@exec poetry run ruff fastadmin tests examples docs
@echo "Run isort"
@exec poetry run isort --check-only fastadmin tests examples docs
@echo "Run black"
@exec poetry run black --check --diff fastadmin tests examples docs
@echo "Run mypy"
@exec poetry run mypy -p fastadmin -p tests -p examples -p docs
@echo "Run frontend linters"
@exec make -C frontend lint

.PHONY: test
test:
poetry run python generate_db.py
ADMIN_ENV_FILE=example.env poetry run pytest --cov=fastadmin --cov-report=term-missing --cov-report=xml --cov-fail-under=90 -s tests
cd frontend && make test
@exec poetry run python generate_db.py
@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
@exec make -C frontend test

.PHONY: kill
kill:
kill -9 $$(lsof -t -i:8090)
kill -9 $$(lsof -t -i:3030)
@exec kill -9 $$(lsof -t -i:8090)
@exec kill -9 $$(lsof -t -i:3030)

.PHONY: collectstatic
collectstatic:
rm -rf ./fastadmin/static/js
rm -rf ./fastadmin/static/css
cp -rf ./frontend/build/static/js/ ./fastadmin/static/js/
cp -rf ./frontend/build/static/css/ ./fastadmin/static/css/
mv fastadmin/static/js/main*.js fastadmin/static/js/main.min.js
mv fastadmin/static/css/main*.css fastadmin/static/css/main.min.css
rm fastadmin/static/js/*.txt
@exec rm -rf ./fastadmin/static/js
@exec rm -rf ./fastadmin/static/css
@exec cp -rf ./frontend/build/static/js/ ./fastadmin/static/js/
@exec cp -rf ./frontend/build/static/css/ ./fastadmin/static/css/
@exec mv fastadmin/static/js/main*.js fastadmin/static/js/main.min.js
@exec mv fastadmin/static/css/main*.css fastadmin/static/css/main.min.css
@exec rm fastadmin/static/js/*.txt

.PHONY: install
install:
poetry install --all-extras
make -C frontend install
@exec poetry install --all-extras
@exec make -C frontend install


.PHONY: docs
docs:
make -C docs build
cp ./docs/README.md ./README.md
@exec make -C docs build


.PHONY: build
build:
make docs
make -C frontend build
make collectstatic
@exec make docs
@exec make -C frontend build
@exec make collectstatic

.PHONY: pre-commit-install
pre-commit-install:
poetry run pip install pre-commit
poetry run pre-commit install
@exec poetry run pip install pre-commit
@exec poetry run pre-commit install

.PHONY: pre-commit
pre-commit:
poetry run pre-commit run --all-files
@exec poetry run pre-commit run --all-files

.PHONY: push
push:
make fix
make lint
make test
make build
make pre-commit
git stash
git checkout main
git pull origin main
git stash pop
git add .
git commit -am "$(message)"
git push origin main
pre-push:
@exec make fix
@exec make lint
@exec make pre-commit-install
@exec make pre-commit
@exec make docs
@exec make build
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Install the package using pip:



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



Expand Down Expand Up @@ -314,8 +314,8 @@ Setup FastAdmin for a framework

```python
from fastapi import FastAPI
from fastadmin import fastapi_app as admin_app

from fastadmin import fastapi_app as admin_app

app = FastAPI()

Expand Down Expand Up @@ -373,8 +373,8 @@ urlpatterns = [

```python
from flask import Flask
from fastadmin import flask_app as admin_app

from fastadmin import flask_app as admin_app

app = Flask(__name__)

Expand Down Expand Up @@ -433,13 +433,13 @@ Register ORM models


```python
import bcrypt
from uuid import UUID

from tortoise.models import Model
import bcrypt
from tortoise import fields
from tortoise.models import Model

from fastadmin import register, TortoiseModelAdmin
from fastadmin import TortoiseModelAdmin, register


class User(Model):
Expand All @@ -449,7 +449,7 @@ class User(Model):
is_active = fields.BooleanField(default=False)

def __str__(self):
return self.username
return self.username


@register(User)
Expand Down Expand Up @@ -501,7 +501,7 @@ class User(models.Model):
is_active = models.BooleanField(default=False)

def __str__(self):
return self.username
return self.username


@register(User)
Expand Down Expand Up @@ -542,20 +542,14 @@ class UserAdmin(DjangoModelAdmin):

```python
import bcrypt
from sqlalchemy import (
Boolean,
String,
Integer,
select,
)
from sqlalchemy import Boolean, Integer, String, select
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker

from fastadmin import SqlAlchemyModelAdmin, register


sqlalchemy_engine = create_async_engine(
f"sqlite+aiosqlite:///:memory:",
"sqlite+aiosqlite:///:memory:",
echo=True,
)
sqlalchemy_sessionmaker = async_sessionmaker(sqlalchemy_engine, expire_on_commit=False)
Expand All @@ -575,7 +569,7 @@ class User(Base):
is_active: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)

def __str__(self):
return self.username
return self.username


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


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

def __str__(self):
return self.username
return self.username


@register(User)
Expand Down
Loading

0 comments on commit 66e32b8

Please sign in to comment.