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 install with nested packages with "--no-root-nested" or similar option to improve docker builds #3671

Closed
yeus opened this issue Feb 10, 2021 · 6 comments · Fixed by #6845
Labels
status/duplicate Duplicate issues

Comments

@yeus
Copy link

yeus commented Feb 10, 2021

  • [ x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x] I have searched the documentation and believe that my question is not covered.

Feature Request

Right now it is possible to install only the dependencies of a package with the poetry install --no-root --no-dev options. This is great to improve docker builds (cache behaviour for example).

it would be great to extend that functionality to nested packages. Something like

poetry install --no-root --no-dev --no-root-nested

which would tell poetry to only install the dependencies of the nested package, but
not the package itself. This would greatly improve the caching behaviour of docker builds as we would only need
to copy the pyproject.toml and poetry.lock files into the docker machine which causes much better caching behaviour.

@yeus yeus added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Feb 10, 2021
@mattmess1221
Copy link

A possible workaround could be done using poetry export. It's not ideal since it uses pip.

# install dependencies, cached build
COPY pyproject.toml poetry.lock ./
RUN bash -c "pip install -r <(poetry export)" # optionally --without-hashes

# Actually install the app
COPY . .
RUN poetry install --no-dev

@yeus
Copy link
Author

yeus commented Mar 12, 2021

I have found a temporary workaround right now by only copying "pypoject.toml" and "poetry.lock" for each subproject. Additionally in order for this to work one needs a project subfolder with an _init_.py in it. After all dependencies got resolved and installed in docker I copy the rest of the files into the docker image. This way we get somewhat nice caching behaviour:

# copy only the pyproject.toml and lockfile in order to make sure they are cached
# as graphengine depends on myprojectlibrary we also copy the myprojectlibrary pyproject.toml and poetry.lock directly
# to the dockerfile. 
COPY ./myproject/pyproject.toml ./myproject/poetry.lock "$PROJECT_DIR/myproject/"
COPY ./myprojectlibrary/pyproject.toml ./myprojectlibrary/poetry.lock "$PROJECT_DIR/myprojectlibrary/"
WORKDIR "$PROJECT_DIR/myproject"

# now we can do the installation without the actual packages which
# enables us to make use of the docker-cache. We will
# pull in the actual project files at a later stage
# In order for this to work we also need to create a "fake" myprojectlibrary directory
# we can install the project "normally" because we don't have the actual project files included here
RUN mkdir "$PROJECT_DIR/myprojectlibrary/myprojectlibrary" &&\
    touch "$PROJECT_DIR/myprojectlibrary/myprojectlibrary/__init__.py" &&\
    mkdir "$PROJECT_DIR/myproject/myproject" &&\
    touch "$PROJECT_DIR/myproject/myproject/__init__.py" &&\
    POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-dev -vvv

COPY . $PROJECT_DIR

where "myproject" depends on "myprojectlibrary" like this in the pyporject.toml file:

myprojectlibrary = { path = "../myprojectlibrary/", develop = true}

@yeus
Copy link
Author

yeus commented Mar 12, 2021

So given that the above method works, it would probably be sufficient for poetry to simply ignore the library folder inside a python project when called with a flag like the one I mentioned above (--no-root-nested). (in my case "myprojectlibrary" and "myproject"). Those would normally get linked when installing subprojects. But that obviously isn't needed in this case ..

@neersighted
Copy link
Member

What is being asked for right now is very unclear to me, but as best I can tell this is a sub-ask for #2270 -- if that is not correct, please update this issue with a clear explanation of what, from a environment/technical level, is being requested.

@neersighted neersighted closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2022
@neersighted neersighted added status/duplicate Duplicate issues and removed kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Oct 4, 2022
@adriangb
Copy link
Contributor

This would be fixed exactly by #6845

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/duplicate Duplicate issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants