Skip to content
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

poetry instead of Pipfile #123

Closed
RCheese opened this issue Feb 28, 2020 · 9 comments
Closed

poetry instead of Pipfile #123

RCheese opened this issue Feb 28, 2020 · 9 comments

Comments

@RCheese
Copy link
Contributor

RCheese commented Feb 28, 2020

subj

@jlugao
Copy link

jlugao commented Mar 2, 2020

+1 on poetry, however, I am not sure how to go about deployment with it, might have to generate a requirements.txt for that

@RCheese
Copy link
Contributor Author

RCheese commented Mar 2, 2020

+1 on poetry, however, I am not sure how to go about deployment with it, might have to generate a requirements.txt for that

Poetry might generate requirements.txt out of the box since 1.0 version for docker install or PyCharm indexing and etc. In case of pipfile you need a another tool as requirementslib for this

@StephenBrown2
Copy link
Contributor

StephenBrown2 commented Mar 2, 2020

Like @RCheese said (but with links), Poetry 1.x will generate a requirements.txt:
https://python-poetry.org/docs/cli/#export

poetry export -f requirements.txt > requirements.txt

@RCheese
Copy link
Contributor Author

RCheese commented Mar 2, 2020

Poetry 1.x will generate a requirements.txt:
https://python-poetry.org/docs/cli/#export

poetry export -f requirements.txt > requirements.txt

I wrote the same)

@laurentS
Copy link

I have modified my project to use poetry, and I changed the dockerfiles to do the following:

COPY ./backend/app/pyproject.toml ./backend/app/poetry.lock /app/
RUN cd /app && $HOME/.poetry/bin/poetry config virtualenvs.create false && $HOME/.poetry/bin/poetry install

The config virtualenvs.create false part disables the use/creation of a venv by poetry, so it installs everything in the "main" python inside the docker images. While not required, I feel that using the same tool everywhere makes more sense.

As a side note, I use a custom base image with most of my python dependencies in it to save time in CI, and there is a bug in poetry that reinstalls everything even if included in the base image, but it still works.

@lucawen
Copy link

lucawen commented Apr 6, 2020

this will be really great and simple to change!

@tiangolo
Copy link
Member

Yep. I want to migrate this to Poetry 😄

I just haven't had the time yet.

@mrbox
Copy link

mrbox commented Apr 15, 2020

I'll create a PR for this, most likely this week. @tiangolo what do you think about also changing backend.dockerfile to install dependencies using Poetry instead of raw pip install ...?

@tiangolo
Copy link
Member

We now have Poetry, and it's integrated into the Dockerfiles as well. 🚀

Thanks @RCheese for the idea and PR!

@RCheese RCheese closed this as completed Apr 18, 2020
br3ndonland added a commit to whythawk/full-stack-fastapi-postgresql that referenced this issue Jul 19, 2021
fastapi#69
fastapi#123
fastapi#144
fastapi/full-stack-fastapi-template@00297f9

Commit 00297f9 gitignored poetry.lock. This commit will add poetry.lock
to version control with Git to avoid dependency resolution errors during
Docker builds.

There is no established convention for working with Poetry in Docker,
so developers have to consider each use case individually. See:
python-poetry/poetry#1879 (comment)

In this project, the Dockerfile copies poetry.lock into the Docker image,
but there's no step to generate poetry.lock in the first place. Without
poetry.lock, dependency resolutions are commonly seen, such as:

```text
❯ bash scripts/test.sh

WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
db uses an image, skipping
flower uses an image, skipping
pgadmin uses an image, skipping
proxy uses an image, skipping
queue uses an image, skipping
Building backend
[+] Building 15.3s (8/10)
 => [internal] load build definition from backend.dockerfile                                      0.2s
 => => transferring dockerfile: 797B                                                              0.1s
 => [internal] load .dockerignore                                                                 0.1s
 => => transferring context: 2B                                                                   0.0s
 => [internal] load metadata for ghcr.io/br3ndonland/inboard:fastapi-python3.9                    0.3s
 => [1/6] FROM ghcr.io/br3ndonland/inboard:fastapi-python3.9@sha256:5591f436a37490a1569afd9e55ae  0.0s
 => [internal] load build context                                                                 0.0s
 => => transferring context: 64.67kB                                                              0.0s
 => CACHED [2/6] COPY ./app/pyproject.toml ./app/poetry.lock* /app/                               0.0s
 => CACHED [3/6] WORKDIR /app/                                                                    0.0s
 => ERROR [4/6] RUN bash -c "if [ true == 'true' ] ; then poetry install --no-root ; else poetr  14.4s
------
 > [4/6] RUN bash -c "if [ true == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi":
 Skipping virtualenv creation, as specified in config file.
 Installing dependencies from lock file
 Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting   dependencies. Run update to update them.

   SolverProblemError

   Because app depends on sqlalchemy-stubs (^0.3) which doesn't match any versions, version solving failed.

   at /opt/poetry/lib/poetry/puzzle/solver.py:241 in _solve
       237│             packages = result.packages
       238│         except OverrideNeeded as e:
       239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
       240│         except SolveFailure as e:
     → 241│             raise SolverProblemError(e)
       242│
       243│         results = dict(
       244│             depth_first_search(
       245│                 PackageNode(self._package, packages), aggregate_package_nodes
------
executor failed running [/bin/sh -c bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"]: exit code: 1
ERROR: Service 'backend' failed to build : Build failed
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants