Skip to content

Commit

Permalink
fix(config): always get the pyproject.toml path from PDM/Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
GabDug committed Dec 23, 2023
1 parent 94e4a0e commit 22f8a3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/sync_pre_commit_lock/pdm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def on_pdm_install_setup_pre_commit(
project: Project, *, hooks: HookManager, candidates: list[Candidate], dry_run: bool, **_: Any
) -> None:
printer = PDMPrinter(project.core.ui)
plugin_config: SyncPreCommitLockConfig = load_config()
project_root: Path = project.root
plugin_config: SyncPreCommitLockConfig = load_config(project_root / project.PYPROJECT_FILENAME)
printer.debug("Checking if pre-commit hooks are installed")

if not plugin_config.automatically_install_hooks:
Expand Down
2 changes: 1 addition & 1 deletion src/sync_pre_commit_lock/poetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class PoetrySetupPreCommitHooks(SetupPreCommitHooks):
def run_sync_pre_commit_version(printer: PoetryPrinter, dry_run: bool, application: Application) -> None:
poetry_locked_packages = application.poetry.locker.locked_repository().packages
locked_packages = {str(p.name): GenericLockedPackage(p.name, str(p.version)) for p in poetry_locked_packages}
plugin_config = load_config()
plugin_config = load_config(application.poetry.pyproject_path)
file_path = Path().cwd() / plugin_config.pre_commit_config_file

SyncPreCommitHooksVersion(
Expand Down
6 changes: 4 additions & 2 deletions tests/test_poetry/test_poetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_handle_post_command_exit_code_not_zero() -> None:


@patch("sync_pre_commit_lock.poetry_plugin.PoetrySetupPreCommitHooks.execute")
def test_handle_post_command_install_add_commands(mocked_execute: MagicMock) -> None:
@patch("sync_pre_commit_lock.config.toml.load", return_value={"tool": {"sync-pre-commit-lock": {}}})
def test_handle_post_command_install_add_commands(mocked_execute: MagicMock, mock_load: MagicMock) -> None:
event = MagicMock(
spec=ConsoleTerminateEvent,
exit_code=0,
Expand Down Expand Up @@ -62,7 +63,8 @@ def test_handle_post_command_self_command() -> None:


@patch("sync_pre_commit_lock.poetry_plugin.SyncPreCommitHooksVersion.execute")
def test_handle_post_command_install_add_lock_update_commands(mocked_execute: MagicMock) -> None:
@patch("sync_pre_commit_lock.config.toml.load", return_value={"tool": {"sync-pre-commit-lock": {}}})
def test_handle_post_command_install_add_lock_update_commands(mocked_execute: MagicMock, mock_load: MagicMock) -> None:
event = MagicMock(
spec=ConsoleTerminateEvent,
exit_code=0,
Expand Down

0 comments on commit 22f8a3b

Please sign in to comment.