Hi all, on my project I’m using custom <first-part...
# general
l
Hi all, on my project I’m using custom first-party stubs but I noticed that when packaging, the resulting PEX also contains the type stubs, is there a way of stripping those type stubs when creating the PEX? (I’m assuming I don’t need those at all for running my code)
1
e
If the type stubs are owned by a target that owns nothing else, you should be able to add an exclude to the pex_binary dependencies.
That's a hack though, the real issue is Pants mostly treats dependencies as a global thing when its really not, its goal dependent. Packaging a pex_binary should probably never care about pyi nor should generating pydoc, etc.
💯 1
l
Thanks @enough-analyst-54434 I was already using the deps but forgot I can remove them using
!
, going to try now
it worked thanks!
h
In 2.16.x you can also add the type stubs in a custom mypy lockfile so that they are only available to mypy, and not have them as code deps at all
l
I was looking to that @happy-kitchen-89482 but isn’t that a lockfile for the extra stubs? In my case the stubs are not available as extra requirements
@enough-analyst-54434 sorry it didn’t work, I must be doing something wrong somewhere, this is my binary BUILD file
Copy code
deps = [
    "3rdparty/python:reqs#typer",
    "3rdparty/python:reqs#mysqlclient",
    "3rdparty/python:reqs#PyYAML",
    "!mypy-stubs/python-default:stubs",
]

python_sources(
    name="lib",
    dependencies=deps,
)

pex_binary(
    name="bin",
    entry_point="./app.py",
    interpreter_constraints=["==3.11.*"],
    strip_pex_env=True,
    dependencies=deps,
)
and the stubs BUILD file looks like this:
Copy code
python_sources(name="stubs", sources=["**/*.pyi"])
But I’m still seeing those stubs inside the pex 🤔
e
The second link I linked talks about
!!
- did you try that?
l
I just opened it, let me try!
e
You can skip the suspense witd
pants filedeps
- may need some sort of recursive or transitive flag - just tack on
-h
to see. I haven't used that in a while.
👌 1
😅 1
l
that did it! This is how it looks like now:
Copy code
deps = [
    "3rdparty/python:reqs#typer",
    "3rdparty/python:reqs#mysqlclient",
    "3rdparty/python:reqs#PyYAML",
]

python_sources(
    name="lib",
    dependencies=deps,
)

pex_binary(
    name="bin",
    entry_point="./app.py",
    interpreter_constraints=["==3.11.*"],
    strip_pex_env=True,
    dependencies=[
        *deps,
        "!!mypy-stubs/python-default:stubs",
    ],
)
e
I don't believe you any more, but hopefully this that worked worked for real!
l
this time is for real real 😜
h
extra_requirements
is now deprecated and will be removed entirely in 2.18
You just add any type stub requirements to the resolve
along with mypy itself
l
yeah I mean
extra_stub_requirement
h
same
the docs will be clearer in 2.18 🙂
❤️ 1
For now this solution sounds fine too 🙂
e
The type stubs are 1st party right?
l
yes, 1st party
I think I read the extra stub requirement had to be like a pip requirement
e
Yeah. @happy-kitchen-89482 probably missed the 1st party bit but maybe is thinking something fancy with python_distribution in the middle?
These two paths are mututally exclusive IIUC, you can't
!!
3rdparty transitive deps.
l
I’m trying to avoid python distribution because our internal pypi is super slow
yes, 3rdparty deps don’t bother me atm, and mypy extra stub requirements will help with the big ones such as stub-requests and the like
h
Ah yes, sorry, everything I said was re third-party type stubs
👍 1
b
(Relevant issue, if you’d like a place to follow: https://github.com/pantsbuild/pants/issues/15454)
👍 1