Giter VIP home page Giter VIP logo

Comments (8)

frenzymadness avatar frenzymadness commented on July 29, 2024

Thanks a lot for your kind words and detailed report, those are very appreciated!

I can try to update the assemble script to use pip install . also for projects with pyproject.toml that sounds reasonable. I'm a little bit afraid that the pip we have in UBI8 might be too old to support this but that's easily fixable by UPGRADE_PIP_TO_LATEST env variable.

Do you know about any project I can test the change on? All projects I found so far have at least minimal setup.py files for compatibility.

FYI, I'll take a look at this next week because I'll be out of the office till the end of the week.

from s2i-python-container.

shifqu avatar shifqu commented on July 29, 2024

Hi @frenzymadness , thanks for the fast response.

Indeed, I guess in order to support the pyproject.toml the condition should be that ! -z "$UPGRADE_PIP_TO_LATEST" && -f pyproject.toml.

So far, I do not have a public project for this. But I suppose I could make a public poetry project. Just not sure how to test the s2i build for it.
Would it be sufficient if I created a public repo that has a minimal poetry project in there? (With poetry project, I mean a project that uses pyproject.toml)

from s2i-python-container.

shifqu avatar shifqu commented on July 29, 2024

To be complete and for anyone else stumbling upon this issue.

As long as we import absolute and without modules, s2i works fine.
But as soon as you try to import from your root module, it will fail, since the pip install . never happened.

As a current workaround we added an .s2i/bin/assemble script with following content:

 #!/bin/bash
echo "Before assembling"

/usr/libexec/s2i/assemble
rc=$?

if [ $rc -eq 0 ]; then
    echo "After successful assembling"
    pip install .
    rc=$?
    echo "Ran pip install ."
else
    echo "After failed assembling"
fi

exit $rc

Ofcourse it would be great if we didn't have to ship our projects with a custom assemble script, but at least we are no longer blocked to deploy our images on openshift.

While writing this, we could likely also have used an empty setup.cfg file or something, but when debugging this did not seem to work, however, I think it was just my mind that was blurry and something went wrong with adding the setup.cfg :)

from s2i-python-container.

shifqu avatar shifqu commented on July 29, 2024

I have just created a minimal poetry project and made it public.
I added requests as a main dependency and black as a dev dependency.
I didn't use any proxy for the requirements, so this repo should be usable by anyone.

If there is anything else I could add to make the s2i usage more easy, let me know and I will (try to) add to this project.

The project: https://github.com/shifqu/minimal-poetry

from s2i-python-container.

frenzymadness avatar frenzymadness commented on July 29, 2024

Thanks for the example. I'm testing it now. Could you please help me understand what kind of import didn't work for you when the app itself is not installed? When I build a container image with the example project, I see it in the working directory so import minimal_poetry should work.

What I've tried is to have these modules in the minimal_poetry package:
a.py with some content:

foo = 8

b.py with a relative import:

from .a import foo

c.py with absolute import:

from minimal_poetry.a import foo

And it seems that all of them works fine:

>>> from minimal_poetry import a
>>> from minimal_poetry import b
>>> from minimal_poetry import c

The reason is that CWD /opt/app-root/src is in PYTHONPATH and therefore all packages from that path are importable.

from s2i-python-container.

shifqu avatar shifqu commented on July 29, 2024

Thanks for testing this!
So I checked again and apparently, I had left out an important detail of our setup, which is that we use a src layout. I recreated the minimal_poetry package minimal-poetry-src-layout. This was done by running poetry new $ProjectPath --src.
I also included the a, b and c files already and once again added requests as a regular dep and black as a dev-dep.

Could you try again with this set-up?

Maybe there is an ENV var that we can set? Like $APP_HOME? I have tried setting the APP_HOME, but then I still get the ModuleNotFound error. I suppose this is because in the run script we add pwd to the path before we cd into app_home. link to run relevant line in run script

I think maybe the title of this issue should become something along the lines of Cannot use absolute imports in poetry project with src-layout

Apologies for not mentioning the src layout earlier, I had thought it was merely a detail 🤦‍♂️

Also, since this is quite an exotic scenario (poetry in combination with src layout), I would understand if you'd lower the priority on this. We currently work around this by shipping our repos with an assemble script as I mentioned in an earlier comment.

from s2i-python-container.

frenzymadness avatar frenzymadness commented on July 29, 2024

I had the solution since the last week but I hoped I'll be able to test a new CI config on it. It seems that the new CI will take much longer so I've opened #575 to not block this. Would you mind taking a look at the proposed solution?

from s2i-python-container.

shifqu avatar shifqu commented on July 29, 2024

Thanks @frenzymadness! I reviewed and put my stamp of approval on the PR :)

from s2i-python-container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.