Skip to content

Commit

Permalink
Merge pull request #6 from ewjoachim/split-by-equal
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Apr 1, 2024
2 parents 529628b + 664b00d commit cc0fdcf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ repos:
"--skip=another_project",
# You can specify that a given hook id (like "pyright-python")
# should be mapped to a given PyPI package name (like "pyright")
"--map=pyright-python:pyright",
"--map=ruff-pre-commit:ruff",
"--map",
"pyright-python=pyright",
"--map",
"ruff-pre-commit=ruff",
]

# Use this hook to sync a specific hook with a Poetry group, adding all
Expand All @@ -45,7 +47,7 @@ repos:
# "mypy" is the id of a pre-commit hook
# "types" is the name of your poetry group containing typing dependencies
# "main" is the automated name associated with the "default" poetry dependencies
args: ["--bind", "mypy:types,main"]
args: ["--bind", "mypy=types,main"]
```
## How it works
Expand All @@ -67,7 +69,7 @@ leading `v`).

### `sync-hooks-additional-dependencies_cli`

This hook will iterate over all the `--bind {pre-commit-hook}:{poetry_groups}`
This hook will iterate over all the `--bind {pre-commit-hook}={poetry_groups}`
arguments you provided, and for each of them, it will look for the
corresponding groups in your `pyproject.toml`. If it finds it, then it will
look for the version of all the dependencies of these groups in your
Expand Down
10 changes: 5 additions & 5 deletions poetry_to_pre_commit/sync_hooks_additional_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

def format_bind(value: str) -> tuple[str, set[str]]:
try:
key, value = value.split(":", 1)
key, value = value.split("=", 1)
except ValueError:
raise ValueError(
f"Invalid bind value: {value}. Expected format: pre_commit_hook_id:poetry_group[,poetry_group,...]."
f"Invalid bind value: {value}. Expected format: pre_commit_hook_id=poetry_group[,poetry_group,...]."
)
return key, set(value.split(","))

Expand All @@ -38,13 +38,13 @@ def get_sync_hooks_additional_dependencies_parser() -> argparse.ArgumentParser:
type=format_bind,
action="append",
default=[],
help="Bind pre-commit hook ids to poetry group names (e.g. mypy:types). "
help="Bind pre-commit hook ids to poetry group names (e.g. mypy=types). "
"To add the main package dependencies, use the poetry group name "
f"`{MAIN_GROUP}`. You can bind multiple poetry groups to a single hook "
"id by either using multiple flags, or by providing a comma-separated "
"list of poetry group names (e.g. "
f"`--bind mypy:{MAIN_GROUP} --bind mypy:types` or "
f"`--bind mypy:{MAIN_GROUP},types`).",
f"`--bind mypy={MAIN_GROUP} --bind mypy:types` or "
f"`--bind mypy={MAIN_GROUP},types`).",
)
return parser

Expand Down
4 changes: 2 additions & 2 deletions poetry_to_pre_commit/sync_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def get_sync_repos_parser() -> argparse.ArgumentParser:
"--map",
action="append",
default=[],
type=lambda x: tuple(x.split(":")),
type=lambda x: tuple(x.split("=")),
help="Map repo name to PyPI name in case of mismatch "
"(e.g. 'pyright-python:pyright'). Note: if the repo name "
"(e.g. 'pyright-python=pyright'). Note: if the repo name "
"is a mirror, the prefix 'mirrors-' is assumed, you don't need to explicit it. "
"Flag can be repeated multiple times.",
)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sync_hooks_additional_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
@pytest.mark.parametrize(
"value,expected",
[
("foo:bar", ("foo", {"bar"})),
("foo:bar,baz", ("foo", {"bar", "baz"})),
("foo=bar", ("foo", {"bar"})),
("foo=bar,baz", ("foo", {"bar", "baz"})),
],
)
def test_format_bind(value, expected):
Expand All @@ -32,7 +32,7 @@ def test_combine_bind_values():

def test_get_sync_hooks_additional_dependencies_parser():
parser = sync_hooks_additional_dependencies.get_sync_hooks_additional_dependencies_parser()
assert parser.parse_args(["--bind", "foo:bar,baz", "--bind", "foo:qux"]).bind == [
assert parser.parse_args(["--bind", "foo=bar,baz", "--bind", "foo=qux"]).bind == [
("foo", {"bar", "baz"}),
("foo", {"qux"}),
]
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_sync_hooks_additional_dependencies(tmp_path, poetry_cwd):
)

sync_hooks_additional_dependencies.sync_hooks_additional_dependencies(
argv=["foo", "--bind", "pyright:types,main"],
argv=["foo", "--bind", "pyright=types,main"],
pre_commit_path=pre_commit_path,
poetry_cwd=poetry_cwd,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sync_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_repo_url_to_pypi_name(input, expected):
{"filenames": [], "map": [], "skip": ["foo", "bar"]},
),
(
["--map", "foo:bar", "--map", "baz:qux"],
["--map", "foo=bar", "--map", "baz=qux"],
{"filenames": [], "map": [("foo", "bar"), ("baz", "qux")], "skip": []},
),
],
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_sync_repos(tmp_path, poetry_cwd):
)

sync_repos.sync_repos(
argv=["foo", "--map", "pyright-python:pyright"],
argv=["foo", "--map", "pyright-python=pyright"],
pre_commit_path=pre_commit_path,
poetry_cwd=poetry_cwd,
)
Expand Down

0 comments on commit cc0fdcf

Please sign in to comment.