Hey again, I think I have some kind of edge case w...
# general
f
Hey again, I think I have some kind of edge case which can't be handled by pants ... just to be sure I'd like to explain it and get some reactions. I have the scenario as in the attached picture: test_foo has foo_base as a dependency test_foo has no dependency on django-json-widget (and it's not getting loaded) foo_base has an seemlingly undeclared dependency on django-json-widget. If I now try to provide the dependency as described in the docs I get an warning: [WARN] The target foo/connect/foo_connect/settings.py:foo_connect_lib imports
foo_base.tenant_switcher.apps.TenantSwitcherConfig
, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['foo/connect:foo-base', 'foo/connect:reqs#foo-base']. does this make sense?
1
foo_base has django-json-widget in it's requirements.txt file but I suppose it has to be somewhere else, maybe in setup.py?
n
Assuming
foo_base
is a
python_requirement
or
python_requirements
, you can explicitly add
django-json-widget
as a dependency to it: https://www.pantsbuild.org/docs/python-third-party-dependencies#requirements-with-undeclared-dependencies
f
that's what I'm doing, or at least trying:
Copy code
python_sources()

python_requirement(
    name="django_json_widget",
    requirements=["django-json-widget"],
)

python_requirement(
    name="foo-base",
    requirements=["foo-base"],
    dependencies=[":django_json_widget"],
)


python_requirements(
    name="reqs",
    module_mapping={
        "django-parler": ["parler"],
        "django-parler-rest": ["parler_rest"],
        "django-environ": ["environ"],
        "django-autocomplete-light": ["dal"],
    }
)
hm
n
Sounds like your
requirements.txt
read by
python_requirements
also has
foo-base
in it? In that case you want to add
Copy code
overrides={
        "foo-base": {"dependencies": [":reqs#django-json-widget"]},
    },
to your python_requirements instead
No need to add an additional
python_requirement
with
foo-base
.
f
ok, if I try that, like so:
Copy code
python_requirements(
    name="reqs",
    module_mapping={
        "django-parler": ["parler"],
        "django-parler-rest": ["parler_rest"],
        "django-environ": ["environ"],
        "django-autocomplete-light": ["dal"],
    },
    overrides={
        "foo-base": {"dependencies": [":reqs#django_json_widget"]},
    },
)
I get this error:
Copy code
ValueError: The explicit dependency `foo/connect:reqs#django_json_widget` of the target at `foo/connect:reqs#foo-base` does not provide enough address parameters to identify which parametrization of the dependency target should be used.
with a list of possible addresses
but foo-base isn't listed
ah wrong, it is
nah, I'm confused
n
Does your requirements.txt have
django-json-widget
as well? If not, you still need a
python_requirement
for that dependency, and the address in your
overrides
would then be
:django_json_widget
(or w/e you name it).
f
yeah, my mistake
needed to be
django-json-widget
not
django_json_widget
ok, one step further, thank you!
🖖 1
with that the
python_source
target isn't needed at all
override only is sufficient
though with the next dependency this approach doesn't work 🤯
ok the 2nd neede to go into the BUILD file near the test, also done