-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to install dependencies to target directory. pip -t flag analogue #1937
Comments
Hey @mvoitko , could you please add a use case, where you think this feature would be useful? fin swimmer |
I'm interested in this feature to be able to download and build python packages as part of deploying to AWS Lambda. In order to deploy to Lambda you need to zip up your source code and dependencies and upload them to an S3 bucket. My build currently involves doing: poetry export -f requirements.txt --without-hashes > requirements.txt
pip install -r requirements.txt -t ./bundle/ The
It would be nice to be able to run something like: poetry install -t ./bundle/ This would have the advantage of verifying hashes, simplifying the build and removing the direct dependency on |
This could also help with caching dependencies in building containers as well I think. #1382 |
We would also like to bundle an application for:
It looks like there is an open Pull Request for this feature here: #799 |
Similarly to @beanaroo, I too would like to be able to install packages to a specific directory for AWS Lambda deployments and Docker Containers. It would be awesome to have this added to Poetry. |
It appears the latest relevant PR is #2682 |
Any update on this issue? The PR doesn't seem to be moving. As mentioned above, it would be nice to have this feature especially for Lambda deployments. |
It also seems some packages in Arch Linux like https://archlinux.org/packages/community/any/yubikey-manager/ started using |
Any update on the draft PR? |
Any updates on this? |
Clearly something helpful for bundling Lambda and containers. One thing also important is to be able to bundle only production dependencies (not dev). Any news ? |
A lot of people are explaining it's useful for bundling lambda and containers but it's might be helpful to explain why that is. Regarding containers, Docker has a concept of a multi-stage build. In a multistage build you can have a builder image and a live image in the same file. The builder image has compilers for cython and so on installed. The live one has none of these build dependencies installed and only has the resulting binaries. So the motivating example for poetry is to install all the dependencies to a specific directory and then, copy the files from the build image into the live image. Without this feature, we need to do surgery on Thanks! |
Any update on this? The below may be the simplest way to bundle an application with all dependencies into an AWS Lambda package but if poetry natively support an equivalent feature, that would be great. $ poetry build --format wheel
$ pip install ./dist/foobar.whl -t ldist
$ cd ldist && zip lambda * -r |
I'd like to bring another user case. I have setup a git hook on post-merge to trigger a django server restart when code is merged to the repository's master branch. In the git hook, Things like django collectstatic and django migrate are run, so that new static files are collected, and new migrations are applied. It would be useful to also be able to also automatically install new packages, and this requires targeting a different directory than the one the post-merge hook is on. I'd need to be able to install the new packages from |
Does anyone know what is the current status of this? It's the last item preventing many people from migrating to poetry |
This would also be useful for deployment as an Azure Function app. |
I'm not familiar with the target environments, but is using pip itself viable? |
I'm also looking to get that feature, specifically I'll be using it for AWS Lambda |
Another vote for the AWS Lambda use case. |
+1 For the Lambda use case |
Another solution that worked for me is installing the dependencies directly into the project. This will create a poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
poetry install --no-dev
# function handler file for AWS lambda
cp lambda_function.py .venv/lib/python3.9/site-packages/
cp -r ./YOUR_APPLICATION_ROOT .venv/lib/python3.9/site-packages/
# set permissions so the aws runtime can execute the files
find .venv/lib/python3.9/site-packages -type f -print0 | xargs -0 chmod 644
find .venv/lib/python3.9/site-packages -type f -print0 | xargs -0 chmod 755
cd .venv/lib/python3.9/site-packages/
zip -q -r lambda.zip ./* |
+1 |
Hi, having followed this issue and other related (#1174), I've found that related pr (#799 and #2682) have been closed in favor of an official bundle plugin (https://github.com/python-poetry/poetry-plugin-bundle) edit: just saw plugins are coming with 1.2.0 which is not yet released |
@Cajuteq thanks for linking the plugin bundle. Please forgive my lack of knowledge - pretty new to python. It looks like it's designed to only work with virtual envs? Specifically there's no way to bundle directly into the root python environment? For deployment, I don't want to mess with venvs. Based on this thread my current deployment is: RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
RUN /root/.local/bin/poetry config virtualenvs.create false
# We copy just the requirements.txt first to leverage Docker cache
COPY poetry.lock pyproject.toml ./
# https://github.com/python-poetry/poetry/issues/1937
RUN /root/.local/bin/poetry export --format requirements.txt --without-hashes --output requirements.txt
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" Above skips venv making this mentally easy for deployment. My question becomes - is using the plugin as simple as |
I maintain a plugin that adds Poetry support for a build tool used in the ROS community. It requires that Python dependencies be installed to a specific location. The bundle plugin ended up being a perfect solution to this problem, and I was able to replace my old @nitsujri Without getting too into how virtual environments work, you may be able to get away with setting the RUN poetry bundle venv /my_project/my_venv
ENV PYTHONPATH="/my_project/my_venv/lib/python3.x/site-packages:${PYTHONPATH}" That should allow you to use the libraries in the virtual environment without having to enter it. Let me know how it works for you. |
Closing as out of scope for the main project / covered by the bundle plugin. |
+1 for lambda and for sagemaker containers. It would be great to not have to move out of the poetry ecosystem back into pip when moving to production. |
See https://github.com/python-poetry/poetry-plugin-bundle -- this is out of scope for the core of Poetry, but would make sense as a FR on the plugin. |
My use case is installing poetry dependencies in a python lambda container. I agree being able to do e.g.
|
Any updates for this? +1 for the AWS lambda use case, would be so so nice to have. |
Same thing for Azure Function resulting to exit the poetry ecosystem |
Admins, can we lock this conversation? The issue is closed as out of scope and there are perfectly good solutions above. The recent comments have all been "+1"s from folks who haven't bothered to read the thread. For the record, the solutions include:
|
Feature Request
Add possibility to install dependencies to target directory. pip -t flag analogue.
The proposed command example is
poetry install -t ./vendor
The text was updated successfully, but these errors were encountered: