Skip to content

Commit

Permalink
chore: configure alembic to run hooks (#12792)
Browse files Browse the repository at this point in the history
After a migration file is generated, run `black` and `isort` to conform
to our linter rules.

Closes #10053
Closes #10146

Signed-off-by: Mike Fiedler <[email protected]>

Signed-off-by: Mike Fiedler <[email protected]>
  • Loading branch information
miketheman authored Jan 9, 2023
1 parent 0a39690 commit 63c8b0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/unit/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def handler(config):


def test_configure_alembic(monkeypatch):
config_obj = pretend.stub(set_main_option=pretend.call_recorder(lambda *a: None))
config_obj = pretend.stub(
set_main_option=pretend.call_recorder(lambda *a: None),
set_section_option=pretend.call_recorder(lambda *a: None),
)

def config_cls():
return config_obj
Expand All @@ -100,6 +103,13 @@ def config_cls():
pretend.call("script_location", "warehouse:migrations"),
pretend.call("url", config.registry.settings["database.url"]),
]
assert alembic_config.set_section_option.calls == [
pretend.call("post_write_hooks", "hooks", "black, isort"),
pretend.call("post_write_hooks", "black.type", "console_scripts"),
pretend.call("post_write_hooks", "black.entrypoint", "black"),
pretend.call("post_write_hooks", "isort.type", "console_scripts"),
pretend.call("post_write_hooks", "isort.entrypoint", "isort"),
]


def test_raises_db_available_error(pyramid_services, metrics):
Expand Down
5 changes: 5 additions & 0 deletions warehouse/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def _configure_alembic(config):
alembic_cfg = alembic.config.Config()
alembic_cfg.set_main_option("script_location", "warehouse:migrations")
alembic_cfg.set_main_option("url", config.registry.settings["database.url"])
alembic_cfg.set_section_option("post_write_hooks", "hooks", "black, isort")
alembic_cfg.set_section_option("post_write_hooks", "black.type", "console_scripts")
alembic_cfg.set_section_option("post_write_hooks", "black.entrypoint", "black")
alembic_cfg.set_section_option("post_write_hooks", "isort.type", "console_scripts")
alembic_cfg.set_section_option("post_write_hooks", "isort.entrypoint", "isort")
return alembic_cfg


Expand Down

0 comments on commit 63c8b0e

Please sign in to comment.