#Poetry

1 messages · Page 1 of 1 (latest)

tribal ledge
#

Here's a minimal poetry config:

[tool.poetry]
name = "main"
version = "0.0.0"
description = "Minimal Python module using Poetry"
authors = ["helderco"]

[tool.poetry.dependencies]
python = "^3.11"

[tool.poetry.group.dev.dependencies]
dagger-io = {path="./sdk", develop=true}

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Notice description and authors is required in Poetry.

restive kindle
#

I have both keys, though description is blank

tribal ledge
#
readme = "README.md"

Shouldn't be on src/.

restive kindle
#

Resolved that, progresses further to: Building wheel for pytest-ci-module (pyproject.toml) did not run successfully.

tribal ledge
#

Have you specified anything that changes where poetry finds the packages?

#

Your code, that is.

restive kindle
#

Not that I'm aware of, no

tribal ledge
#

What does poetry check tell you?

restive kindle
#

"All set!"

tribal ledge
#

Do you have anything extra besides my minimal example?

#

Have you kept the source in src/main.py?

restive kindle
#

Only readme = "src/README.md". Source is in src/main.py yep

tribal ledge
#

Why isn't README.md in the root of the module? src/ is meant for python packages.

restive kindle
#

Testing it in the root of the module now

#

So my pyproject.toml is, except obvious differences like description, identical to the above

tribal ledge
#

This is what I have:

.
├── src
│  └── main.py
├── dagger.json
├── poetry.lock
├── pyproject.toml
└── README.md
restive kindle
#

Still getting poetry.core.masonry.utils.module.ModuleOrPackageNotFound: No file/folder found for package pytest-ci-module

tribal ledge
#

Where have you set pytest-ci-module?

restive kindle
#

In pyproject.toml? No-where

tribal ledge
#

Oh, I guess it's you project name. Change it to main.

tribal ledge
#

If not main, then you have to tell Poetry to look for packages in src/. The default is to collapse based on the project name, so it has to match main.py or main/__init__.py.

restive kindle
#

But not "main" in pyproject.toml's name key

tribal ledge
#

Supporting other package names is planned but not ready.

restive kindle
#

That's done it, thanks!

#

I realise I'm testing this before docs cover these gotchas so thanks for debugging with me 🙂

tribal ledge
#

Thank you too! Now I won't forget to highlight keeping "main" as project name 😁

restive kindle
#

If it helps, this is going to form the basis of my demonstrating Dagger to a second client who has answered "how do we run the same commands locally as we do in CI" by making the mother of all monstrosity hierarchical Makefiles with many includes, so I'm excited to show this

tribal ledge
#

Something like:

packages = [
    { include = "main", from = "src" },]
restive kindle
#

So support for different package names is planned and will eventually be documented or default?

tribal ledge
#

Eventually be documented yes, but easiest to default to main.

#

Right now, what's in src/ needs to be main because that's imported internally by the SDK (hardcoded).

#

It can be main.py or main/__init__.py (for multiple files).

restive kindle
tribal ledge
#

What did you change?

#

Looks like it didn't find any functions.

restive kindle
#

name back to what it was originally, and added the packages key

#
[tool.poetry]
name = "pytest-ci-module"
version = "0.1.0"
description = "Test"
authors = ["Mjb141"]
packages = [{ include = "main", from = "src" }]
tribal ledge
#

Oh. Who's giving the ValueError, can you tell?

#

Is it Poetry or the SDK?

restive kindle
#

Looks like Poetry

tribal ledge
#

I guess you would need to make it a package to use it like that: main/__init__.py. There's another setting...

restive kindle
#
┃       ValueError: /src/src/main does not contain any element                        
┃       [end of output]                            
┃                                                   
┃   note: This error originates from a subprocess, and is likely not a problem with pip.                                                     
┃   ERROR: Failed building wheel for pytest-ci-module                                                                                    
┃ Failed to build pytest-ci-module       
┃ ERROR: Could not build wheels for pytest-ci-module, which is required to install pyproject.toml-based projects  
tribal ledge
#

Try this:

packages = [{ include = "src/main.py" }]
#

Curious if this works:

packages = [{ include = "main.py", from = "src" }]
restive kindle
tribal ledge
#

Ah, that's probably because it gets installed under src/main.py in site-packages. I suspect the second form should work.

#
packages = [{ include = "main.py", from = "src" }]
restive kindle
tribal ledge
#

Did you add from = "src"?

restive kindle
#

Nope, I just realised

tribal ledge
#

Awesome

restive kindle
#

That's the simplest one for sure, I'm going to leave it like that

tribal ledge
#

🙂

restive kindle
#

Super simple to switch this over to pytest now it's running. Few bits left to do in work tomorrow to apply these to some lambda function pytests and it'll be ready to demonstrate to my team. Glad I got that working 🙌

tribal ledge
#

Great!

#

Now I'm wondering about the dev group. That should probably be an optional group and in your host you'd have to say poetry install --with dev.

#

Not sure if that's being handled automatically for dev.

#

Since it's now a group like any other.

restive kindle
#

Does it need special consideration? poetry install installs all groups by default

tribal ledge
#

Ah, I guess it's ok because you need poetry to install from any group that's not the main one.

#

In dagger it's a pip install, not poetry install, so you should only get the main dependencies there.

restive kindle
#

Ah I see

tribal ledge
#

A caveat here is that the lockfile is ignored. So you can't pin dependencies yet.

restive kindle
#

I presume since you've said 'yet' that's also planned

#

Worth documenting that as well, else it's likely to lead to odd errors people can't diagnose

tribal ledge
#

Yes, it's planned. I'm considering using micropipenv for that.

restive kindle
#

Oh that looks useful. I've never seen that

#

I've simply added poetry to base images in the past and not really considered that I might not need it. Added that to the "test this at some point" list 🙂

tribal ledge