hey again. it seems I ran into an issue where some...
# general
f
hey again. it seems I ran into an issue where some 3rd party python packages are found with a (implicite) mapping of
-
with
_
and some are not. strarting from django settings I have f.e.
Copy code
'django_countries',
'django_json_widget',
and in requirements.txt
Copy code
django-countries==7.5
django-json-widget==1.1.1
so far so good, but I run into
ModuleNotFoundError: No module named 'django_json_widget'
when trying to run a test. Any ideas about this?
I tried to fix this with an module_mapping in the python_requirements target.
l
There are a bunch of built-in mappings in https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/dependency_inference/default_module_mapping.py that are generally applied for known packages. Your two are not listed there in the django section, so that is why you are having to do it yourself
And it isn't working?
If you are going off of https://www.pantsbuild.org/docs/python-third-party-dependencies#use-modules-and-module_mapping-when-the-module-name-is-not-standard and it isn't working, def post more details about the example (pants.toml, BUILD and the consuming file) and we can try to see together what is going on.
f
I'm not sure if default module mapping is involved here since it's working for
django-countries
(which is loaded first and not in the defaults) and not working for
django-json-widget
. so my guess would be the translation of pypi package name with a dash to an underscore in the source package name - but that can't be right since it doesn't work ... 🤔
and yes, I'm trying to solve it with 'Use
modules
and
module_mapping
when the module name is not standard' but somehow it doesn't work - for this example. For other modules like f.e.
"django-autocomplete-light": ["dal"],
it's working just fine.
l
oh you're probably right, that the default is converting
-
between
_
and only then applying those hardcoded mappings
f
somehow though f.e. for
"django-admin-rangefilter": ["rangefilter"],
it seems to not work
l
btw, how are the imports set up? it is in a django settings file rather than a direct import?
f
here it's about the settings file
l
if you run
pants dependencies your-source-target
what do you see?
your-source-target being the address of the source file that you expect depends on the particular requirement
f
without the transitive flag I don't see f.e. dal
with the flag it's in
foo/bar:reqs#django-autocomplete-light
(needed to edit because of names 😆 )
aaah
so, I have a mismatch between the actual dependencies from the source target and what I try to import from settings
l
Ok, if you have a lead go ahead. If you still get stuck, you may have to provide some more details (ideally an example repo) for us to minimally reproduce the issue and I would be happy to try to understand what is going on. Until then I think I am too new to provide more useful suggestions.
f
yeah I can't really provide this as an example since it's closed source 🤷
anyways, you already helped me - thx!
l
you can always adapt the example to a minimal open source repo that reproduces the issue (like with
foo.py
instead of
some_trade_secret_stuff.py
) It is a common technique used on this channel and is very effective for getting help and increasing collective knowledge.
f
here though it's the actual large code base and not really easy to reproduce, just saying ... of course as the last resort that's probably what I'd have to do
I try to avoid it though - feels like weeks of work 😆
l
It may be a false economy, Marius. In constructing that minimal example you may end up solving it - the smallest repo that can reproduce the issue you are seeing. (I'm sure you've had that experience lots of times in regular development), or you may find that what you are experiencing as an issue is actually two distinct issues. Anyway, that's my bit of encouragement for the day 🙂
f
😄 🤝