Skip to content

Commit

Permalink
Do not add dependencies to some ignored Poetry libraries
Browse files Browse the repository at this point in the history
Otherwise, the generated py_binary targets depend on non existing
dependencies (such as setuptool).

Poetry doesn't add several packages in the poetry.lock file:
https://github.com/python-poetry/poetry/blob/d2fd581c9a856a5c4e60a25acb95d06d2a963cf2/poetry/puzzle/provider.py#L55
See also python-poetry/poetry#1584 for explanations.
  • Loading branch information
nlewo committed Aug 28, 2020
1 parent 512c111 commit 2a954bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rules_poetry/poetry.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
load(":json_parser.bzl", "json_parse")

# Because Poetry doesn't add several packages in the poetry.lock file,
# they are excluded from the list of packages.
# See https://github.com/python-poetry/poetry/blob/d2fd581c9a856a5c4e60a25acb95d06d2a963cf2/poetry/puzzle/provider.py#L55
# and https://github.com/python-poetry/poetry/issues/1584
POETRY_UNSAFE_PACKAGES = ["setuptools", "distribute", "pip", "wheel"]

def _clean_name(name):
return name.lower().replace("-", "_").replace(".", "_")

Expand Down Expand Up @@ -65,7 +71,7 @@ def _impl(repository_ctx):
fail("Did not find file hashes in poetry.lock file")

# using a `dict` since there is no `set` type
excludes = {x.lower(): True for x in repository_ctx.attr.excludes}
excludes = {x.lower(): True for x in repository_ctx.attr.excludes + POETRY_UNSAFE_PACKAGES}
for requested in mapping:
if requested.lower() in excludes:
fail("pyproject.toml dependency {} is also in the excludes list".format(requested))
Expand Down

0 comments on commit 2a954bb

Please sign in to comment.