How to tell pip to install test dependencies? - python

We are using pip -e . to install our package in editable/development mode, instead of using python setup.py develop. (We have to do so, because we pull packages from the public PyPi server and a private one. This did not worked for us using python setup.py develop.)
But pip -e . does not install test dependencies and I could not find some flag to force it to do so. How do I install test dependencies using pip?

I use extra_require in the setup.py as specified here. For example:
setup(
name="Project-A",
...
extras_require={
'develop': ["mock==2.0.0"],
}
)
And to execute it using pip install:
pip install -e .[develop]

Related

Vendoring dependencies not working with --find-links

I'm trying to build a package with its dependencies and then install in a separate step.
I'm not using a requirements file I'm using setup.cfg and pyproject.toml.
pip download vendor --dest ./build/dependencies --no-cache-dir
python setup.py check
python setup.py bdist_wheel
python setup.py sdist
That seems to install dependencies into the ./build/dependencies folder, but I can't figure out how to install the wheel by looking in that folder for dependencies.
--find-links doesn't appear to work because I get "Could not find a version that satisfies the requirement.." errors when doing this:
python -m pip install --no-index $(ls dist/*.whl) --find-links="./build/dependencies"
It builds fine without --no-index fetching from the internet.
I also tried running pip install with --target like this,
pip install -e . --target=./build/dependencies
But get the same errors when trying to point to it with --find-links.

How can I install a local Python package with extra components using pip?

pip supports installing extra components while installing a Python package from internet, e.g.,
pip install dask[all]
pip install "dask[all] # git+https://github.com/dask/dask"
However, does it support installing extra components when installing from a local Python package? For example, if I have the dask Python package downloaded to local, how can I install it with specific extra components?
I've just figured it out.
pip3 install "dsutil[cv] # file:///home/dclong/dsutil-0.54.1-py3-none-any.whl"
Yes, you can install extras from a local package. If they're defined in the package's setup.py file in the extras_require dictionary, then you can install them with pip install ."[extra1, extra2]". For example, if you have the following in your setup.py:
extras_require={
'docs': ["sphinx>=1.6", "sphinx_rtd_theme>=0.2.4", "sphinx-click"],
'dev': ["pre-commit>=2.10.0"]
},
you can install the docs and dev extras with pip install ".[docs, dev]" when you're in the directory containing setup.py (you'd use the path to the directory containing setup.py in the place of . otherwise).

How to install dependencies with square brackets in python setup.py?

I am trying to include the ray into my own package. However, there are some dependencies needed for using ray that should be installed via pip install ray[all].
If I just add ray[all] into the install_requires of setup.py, like:
setup(
...
install_requires=[
...
"ray==1.0.0",
"ray[all]==1.0.0",
]
)
Then running pip install -e . can not install the dependencies specified in ray[all]. However, I wish my user can install everything simply via running pip install -e ..
Can anyone provide a solution for this issue? Thanks!
Try pip install -e .[all].
In general pip install -e .[extras] should work for all python packages that are packaged with setuptools.

Perform a command after pip install <package>

I bundle my package as a sdist zip file , after that i can import my package anywhere using pip install , but i want to run some post install commands automatically after calling pip install.
I cannot use python setup.py install because it is a sdist and i am using pip to install it . I do have a PostInstall class but nothing runs after pip install package. Is there a way to automatically run a script after pip install package.
I have tried using postinstall but it doesnt work and also i am not sure how to use the scripts atrib in the setup method.
This is my setup.py file :
Setup.py
I cannot use python setup.py install because it is a sdist and i am using pip to install it . I do have a MyInstall class but nothing run after pip install package.

pip build . similar to python setup.py build

Instead of doing
python setup.py install
we can do
pip install .
But, it does not build the library rather installs the egg without building.
Is there any command to build from pip which works similar to
python setup.py build
?
pip install -e .
It builds and then installs.

Categories

Resources