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

Non-editable installation of the project itself #443

Closed
pawamoy opened this issue May 5, 2021 · 1 comment · Fixed by #468
Closed

Non-editable installation of the project itself #443

pawamoy opened this issue May 5, 2021 · 1 comment · Fixed by #468
Labels
⭐ enhancement Improvements for existing features

Comments

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented May 5, 2021

Is your feature request related to a problem? Please describe.

I'm currently experimenting with PDM in Docker multi-stage builds.

  • In the "builder" phase, I install PDM, copy the necessary files, and run pdm install --prod --no-lock.
  • In the "run" phase, I simply copy the __pypackages__ lib directory from the builder phase, and add it to the PYTHONPATH.
# build stage
FROM baseimage AS builder

# install PDM
RUN pip install -U pip setuptools wheel
RUN pip install pdm

# copy files
RUN mkdir -p /api/src
COPY pyproject.toml pdm.lock README.md /api/
COPY src/namespace /api/src/namespace

# install deps and project
WORKDIR /api
RUN pdm install --prod --no-lock



# run stage
FROM runimage

# retrieve packages from build stage
RUN mkdir /api
COPY --from=builder /api/__pypackages__/3.8/lib /api/pkgs
ENV PYTHONPATH=/api/pkgs

# set command/entrypoint
COPY run.py /api/run.py
CMD ["python3", "/api/run.py"]

The problem is that PDM installed the current project in editable mode, meaning all I have in my final /api/pkgs is the dependencies and the egg-link of my project. Upon running run.py, it fails with No module named 'namespace'.

Describe the solution you'd like

Since I'm installing the dependencies and project for production (emphasized by the --prod flag), I would like my current project to be installed in non-editable mode in the __pypackages__ lib directory. If you want this to stay flexible, I would gladly have a second --no-editable flag to explicitly ask for this behavior.

Alternatives you've considered

I can run pip install . --no-deps --use-feature=in-tree-build -t __pypackages__/3.8/lib in the build stage, after pdm install --prod --no-lock.

I could also build a wheel in the build stage, and copy it in the run stage to install it with pip install my-wheel.whl -t /api/pkgs --no-deps. But it would require to have pip available in the run stage, which might also be problematic.

In the two cases above, I feel like I would need an additional flag in build stage to tell PDM not to install the project at all (only the prod deps), something like Poetry's --no-root. Otherwise there's an extraneous egg-link in my packages that I should probably remove.

I also considered using a venv as an artifact instead of the __pypackages__ lib directory, but why keep using venv when we can get rid of it 🙂

Final note

Maybe I'm doing this all wrong, and there's a more obvious way? I'm open to suggestions 😄

@pawamoy pawamoy added the ⭐ enhancement Improvements for existing features label May 5, 2021
@pawamoy
Copy link
Sponsor Contributor Author

pawamoy commented May 14, 2021

Actually the first alternative solution I mentioned does not work for namespace packages because of this: pypa/pip#8063 (comment)

So I definitely need either a --no-root flag, a --no-editable flag, both, or a change in the installation behavior when --prod is used 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant