Does Pants expose module mappings in BUILD files i...
# general
h
Does Pants expose module mappings in BUILD files in any way? I would like to be able to get the original requirement name given the mapped module name
Copy code
module_mapping={
    "ansicolors": ["colors"]
} 
###  get ^ when given ^
b
Not vanilla, but you could in a plugin. What use-case are ya thinking about?
h
We perform linting checks on our python requirements using Pants, one being checking for unused requirements. We currently use
./pants dependencies :: --filter-target-type="python_requirements"
to find imported modules but for said check to work we’d need to be able to map these back to their original package/requirement names somehow
b
I was thinking of making a plugin for this. In the meantime you might just wanna `peek`the entire codebase and have a light wrapper which does the calculation
👍 1
f
hey Danny 👋 given this
BUILD
file target:
Copy code
python_requirements(name="reqs", module_mapping={"foo": ["bar", "baz"]})
You could do
Copy code
$ ./pants --filter-target-type="python_requirements" peek : | jq '.[] | .module_mapping'
{
  "foo": [
    "bar",
    "baz"
  ]
}
and then either do a
jq
magic or probably easier to pipe to Python and get the
foo
when you have
bar
h
Exactly what I did @fresh-cat-90827, just reversed the module mappings dict 👍 Although I have noticed that
./pants dependencies
does actually do what I expected in giving the original package name, just not for a specific package being mapped. But I need to look into that further