Skip to content

Commit

Permalink
Merge pull request #35 from arena-ai/use_ruff
Browse files Browse the repository at this point in the history
Use ruff for text formatting and linting
  • Loading branch information
ngrislain authored Oct 15, 2024
2 parents 8afbc1d + f95faf3 commit f9d238f
Show file tree
Hide file tree
Showing 86 changed files with 3,473 additions and 1,325 deletions.
83 changes: 83 additions & 0 deletions backend/.tools-cfg/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 79
indent-width = 4

# Assume Python 3.10
target-version = "py310"

[lint]

# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default. Flake8 BugBear
select = ["E4", "E7", "E9", "F", "B"]

ignore-init-module-imports = true

# 2. Avoid enforcing line-length violations (`E501`)
ignore = ["E501","B028","B904"]

# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in select subdirectories.
[lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]


[format]
# Use single quotes
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
8 changes: 8 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ clean:
docker rmi $(IMAGE_NAME):$(TAG)
docker rmi $(REGISTRY)/$(IMAGE_NAME):$(TAG)

ruff_check:
ruff format --config .tools-cfg/ruff.toml app
ruff check --fix --config .tools-cfg/ruff.toml app

ruff_fix:
ruff format --config .tools-cfg/ruff.toml app
ruff check --fix --config .tools-cfg/ruff.toml app

.PHONY: all build push up test clean
10 changes: 8 additions & 2 deletions backend/app/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def run_migrations_offline():
"""
url = get_url()
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True
url=url,
target_metadata=target_metadata,
literal_binds=True,
compare_type=True,
)

with context.begin_transaction():
Expand All @@ -75,12 +78,15 @@ def run_migrations_online():

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata, compare_type=True
connection=connection,
target_metadata=target_metadata,
compare_type=True,
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
Expand Down
29 changes: 18 additions & 11 deletions backend/app/alembic/versions/0b08d03d3898_add_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@
Create Date: 2024-03-26 15:53:36.296380
"""

from alembic import op
import sqlalchemy as sa
import sqlmodel.sql.sqltypes


# revision identifiers, used by Alembic.
revision = '0b08d03d3898'
down_revision = 'f37ff4c2a612'
revision = "0b08d03d3898"
down_revision = "f37ff4c2a612"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('setting',
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"setting",
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column(
"content", sqlmodel.sql.sqltypes.AutoString(), nullable=False
),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("timestamp", sa.DateTime(), nullable=True),
sa.Column("owner_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["owner_id"],
["user.id"],
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('setting')
op.drop_table("setting")
# ### end Alembic commands ###
176 changes: 123 additions & 53 deletions backend/app/alembic/versions/23a9e2f29a02_cascade_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,143 @@
Create Date: 2024-07-23 10:09:57.795034
"""

from alembic import op
import sqlalchemy as sa
import sqlmodel.sql.sqltypes


# revision identifiers, used by Alembic.
revision = '23a9e2f29a02'
down_revision = 'a3b5b8f12daf'
revision = "23a9e2f29a02"
down_revision = "a3b5b8f12daf"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('event', 'owner_id',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_constraint('event_parent_id_fkey', 'event', type_='foreignkey')
op.drop_constraint('event_owner_id_fkey', 'event', type_='foreignkey')
op.create_foreign_key(None, 'event', 'user', ['owner_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key(None, 'event', 'event', ['parent_id'], ['id'], ondelete='CASCADE')
op.alter_column('eventattribute', 'event_id',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('eventattribute', 'attribute_id',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_constraint('eventattribute_attribute_id_fkey', 'eventattribute', type_='foreignkey')
op.drop_constraint('eventattribute_event_id_fkey', 'eventattribute', type_='foreignkey')
op.create_foreign_key(None, 'eventattribute', 'event', ['event_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key(None, 'eventattribute', 'attribute', ['attribute_id'], ['id'], ondelete='CASCADE')
op.alter_column('eventidentifier', 'event_id',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_constraint('eventidentifier_event_id_fkey', 'eventidentifier', type_='foreignkey')
op.create_foreign_key(None, 'eventidentifier', 'event', ['event_id'], ['id'], ondelete='CASCADE')
op.alter_column('setting', 'owner_id',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column(
"event", "owner_id", existing_type=sa.INTEGER(), nullable=True
)
op.drop_constraint("event_parent_id_fkey", "event", type_="foreignkey")
op.drop_constraint("event_owner_id_fkey", "event", type_="foreignkey")
op.create_foreign_key(
None, "event", "user", ["owner_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
None, "event", "event", ["parent_id"], ["id"], ondelete="CASCADE"
)
op.alter_column(
"eventattribute", "event_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"eventattribute",
"attribute_id",
existing_type=sa.INTEGER(),
nullable=True,
)
op.drop_constraint(
"eventattribute_attribute_id_fkey",
"eventattribute",
type_="foreignkey",
)
op.drop_constraint(
"eventattribute_event_id_fkey", "eventattribute", type_="foreignkey"
)
op.create_foreign_key(
None,
"eventattribute",
"event",
["event_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
None,
"eventattribute",
"attribute",
["attribute_id"],
["id"],
ondelete="CASCADE",
)
op.alter_column(
"eventidentifier",
"event_id",
existing_type=sa.INTEGER(),
nullable=True,
)
op.drop_constraint(
"eventidentifier_event_id_fkey", "eventidentifier", type_="foreignkey"
)
op.create_foreign_key(
None,
"eventidentifier",
"event",
["event_id"],
["id"],
ondelete="CASCADE",
)
op.alter_column(
"setting", "owner_id", existing_type=sa.INTEGER(), nullable=True
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('setting', 'owner_id',
existing_type=sa.INTEGER(),
nullable=False)
op.drop_constraint(None, 'eventidentifier', type_='foreignkey')
op.create_foreign_key('eventidentifier_event_id_fkey', 'eventidentifier', 'event', ['event_id'], ['id'])
op.alter_column('eventidentifier', 'event_id',
existing_type=sa.INTEGER(),
nullable=False)
op.drop_constraint(None, 'eventattribute', type_='foreignkey')
op.drop_constraint(None, 'eventattribute', type_='foreignkey')
op.create_foreign_key('eventattribute_event_id_fkey', 'eventattribute', 'event', ['event_id'], ['id'])
op.create_foreign_key('eventattribute_attribute_id_fkey', 'eventattribute', 'attribute', ['attribute_id'], ['id'])
op.alter_column('eventattribute', 'attribute_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column('eventattribute', 'event_id',
existing_type=sa.INTEGER(),
nullable=False)
op.drop_constraint(None, 'event', type_='foreignkey')
op.drop_constraint(None, 'event', type_='foreignkey')
op.create_foreign_key('event_owner_id_fkey', 'event', 'user', ['owner_id'], ['id'])
op.create_foreign_key('event_parent_id_fkey', 'event', 'event', ['parent_id'], ['id'])
op.alter_column('event', 'owner_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column(
"setting", "owner_id", existing_type=sa.INTEGER(), nullable=False
)
op.drop_constraint(None, "eventidentifier", type_="foreignkey")
op.create_foreign_key(
"eventidentifier_event_id_fkey",
"eventidentifier",
"event",
["event_id"],
["id"],
)
op.alter_column(
"eventidentifier",
"event_id",
existing_type=sa.INTEGER(),
nullable=False,
)
op.drop_constraint(None, "eventattribute", type_="foreignkey")
op.drop_constraint(None, "eventattribute", type_="foreignkey")
op.create_foreign_key(
"eventattribute_event_id_fkey",
"eventattribute",
"event",
["event_id"],
["id"],
)
op.create_foreign_key(
"eventattribute_attribute_id_fkey",
"eventattribute",
"attribute",
["attribute_id"],
["id"],
)
op.alter_column(
"eventattribute",
"attribute_id",
existing_type=sa.INTEGER(),
nullable=False,
)
op.alter_column(
"eventattribute",
"event_id",
existing_type=sa.INTEGER(),
nullable=False,
)
op.drop_constraint(None, "event", type_="foreignkey")
op.drop_constraint(None, "event", type_="foreignkey")
op.create_foreign_key(
"event_owner_id_fkey", "event", "user", ["owner_id"], ["id"]
)
op.create_foreign_key(
"event_parent_id_fkey", "event", "event", ["parent_id"], ["id"]
)
op.alter_column(
"event", "owner_id", existing_type=sa.INTEGER(), nullable=False
)
# ### end Alembic commands ###
Loading

0 comments on commit f9d238f

Please sign in to comment.