echoing-farmer-15630
01/10/2023, 2:17 PMpants
, the dependency analyzer got too good 🙂
Silly problem: I'm trying to extract a subset of a library which tried to hide its dependencies by putting imports under if
statements, which I think used to work (but I may be wrong) ie something like:
def hide_imports(library: str):
if library == "numpy":
import numpy as result
elif library == "pandas":
import pandas as result
return result
but pants
cannot be fooled:
❯ ./pants dependencies --no-dependencies-transitive src/.../test.py
//:root_requirements#numpy
//:root_requirements#pandas
...
(the situation is more complex with internal dependencies, but you get the idea; what if we wanted to build a library which only included numpy
as a dependency and would be ok if someone called hide_imports("pandas")
?)
Is there any way to build a python_distribution
or pex_binary
with "only obvious" dependencies enclosed or expressly excluding some dependencies? Trying to build a subset of a library for a client without exposing more IP than necessary.bitter-ability-32190
01/10/2023, 2:21 PM# pants: no-infer-dep
2. In the BUILD file declare a dependency for the file and use an exclusion: e.g. !//:root-reqs#pandas
(note the exclamation mark)
3. Muck up your source code import so pants doesn't know what's going on (mostly a joke 😌)echoing-farmer-15630
01/10/2023, 10:36 PMno-infer-dep
business earlier but somehow missed the comment tag (and knew about the exclusion but thought it would just break things somehow). Thanks very much for the help!