rich-london-74860
10/26/2023, 6:09 PMpants
to publish python packages as .whl
files and I’m wondering how do I publish a package with optional dependencies, like with extras_require in setuptools?
Since pants
infers 3rd-party dependencies or pulls them from python_requirement
targets specified in dependencies
of a python_source
target, I assume this would have to be specified in the python_source
target? It’s almost more like I need to subtract dependencies from the published python_distribution
than adding extra dependencies.
I apologize if documentation for this already exists, but I cannot find it.curved-television-6568
10/26/2023, 6:13 PMrich-london-74860
10/26/2023, 6:17 PMmy_package
and sub-module my_package.dataframes
uses pandas
but other sub-modules do not.
Dependents of my_package
should be able to use my_package
without necessarily using pandas
too.
Those dependents that do want to use my_package.dataframes
should specify a dependency on my_package[pandas]
curved-television-6568
10/26/2023, 6:18 PMrich-london-74860
10/26/2023, 6:19 PMpants
, pandas
would need to be specified as a python_requirement
, it would need to be included as a dependency in the python_sources
for this package and it would need to be installed in the resolve
, but that dependency needs to get subtracted from the published .whl
curved-television-6568
10/26/2023, 6:21 PMrich-london-74860
10/26/2023, 6:30 PMpython_distrubtion
? Does including it in extras_require
automatically remove it from default?
Extending the example I described above, my BUILD
file should look something like:
python_requirement(
name="pandas",
requirements=["pandas"],
)
python_sources(
name="lib",
sources=["src/**/*.py"],
dependencies=[":pandas"],
)
python_tests(
name="tests",
sources=["test/**/*.py"]
)
python_distribution(
name="dist",
dependencies=[":lib"],
sdist=False,
provides=setup_py(
name="my_package",
version="1.2.3",
)
)
As this is. pants package
will create a .whl
file that has a dependency on pandas
.
I understand that I can add extra_requires={"pandas": ["pandas"]}
to setup_py
, but does that remove pandas
from the default dependencies of my_package
?
Do I need to pass install_requires=[]
to setup_py
?curved-television-6568
10/26/2023, 6:33 PMI have a feeling optional dependencies is a lacking feature, tbh.
curved-television-6568
10/26/2023, 6:33 PMsetup.py
and not have pants generate it, think..curved-television-6568
10/26/2023, 6:35 PM!!pandas
and then add it manually to your extras, that could work.rich-london-74860
10/26/2023, 6:36 PMpython_distribution(
name="dist",
dependencies=[":lib", "!pandas"],
sdist=False,
provides=setup_py(
name="my_package",
version="1.2.3",
extras_require={"pandas": ["pandas"]}
)
)
curved-television-6568
10/26/2023, 6:37 PM!!
), hopefully 😜curved-television-6568
10/26/2023, 6:38 PMpandas
you exclude would need to be the address for your requirement target, but still…happy-kitchen-89482
10/27/2023, 4:24 AMhappy-kitchen-89482
10/27/2023, 4:24 AMhappy-kitchen-89482
10/27/2023, 4:26 AMhappy-kitchen-89482
10/27/2023, 4:26 AMhappy-kitchen-89482
10/27/2023, 4:28 AMhappy-kitchen-89482
10/27/2023, 4:28 AMlively-football-87758
10/27/2023, 9:42 AMhappy-kitchen-89482
10/27/2023, 9:51 AMlively-football-87758
10/27/2023, 9:53 AMlate-advantage-75311
10/27/2023, 10:12 AMlate-advantage-75311
10/27/2023, 10:13 AMlively-football-87758
10/30/2023, 9:25 AM