https://pantsbuild.org/ logo
#general
Title
# general
h

hundreds-carpet-28072

11/10/2022, 1:59 PM
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

bitter-ability-32190

11/10/2022, 2:14 PM
Not vanilla, but you could in a plugin. What use-case are ya thinking about?
h

hundreds-carpet-28072

11/10/2022, 2:34 PM
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

bitter-ability-32190

11/10/2022, 2:36 PM
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

fresh-cat-90827

11/12/2022, 6:58 PM
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

hundreds-carpet-28072

11/14/2022, 1:12 PM
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
2 Views