#Poetry
1 messages · Page 1 of 1 (latest)
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.
I have both keys, though description is blank
readme = "README.md"
Shouldn't be on src/.
Resolved that, progresses further to: Building wheel for pytest-ci-module (pyproject.toml) did not run successfully.
Have you specified anything that changes where poetry finds the packages?
Your code, that is.
Not that I'm aware of, no
What does poetry check tell you?
"All set!"
Do you have anything extra besides my minimal example?
Have you kept the source in src/main.py?
Only readme = "src/README.md". Source is in src/main.py yep
Testing it in the root of the module now
So my pyproject.toml is, except obvious differences like description, identical to the above
This is what I have:
.
├── src
│ └── main.py
├── dagger.json
├── poetry.lock
├── pyproject.toml
└── README.md
Still getting poetry.core.masonry.utils.module.ModuleOrPackageNotFound: No file/folder found for package pytest-ci-module
Where have you set pytest-ci-module?
In pyproject.toml? No-where
Oh, I guess it's you project name. Change it to main.
Ohhh
I had that same setup
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.
But not "main" in pyproject.toml's name key
Supporting other package names is planned but not ready.
That's done it, thanks!
I realise I'm testing this before docs cover these gotchas so thanks for debugging with me 🙂
Thank you too! Now I won't forget to highlight keeping "main" as project name 😁
If you want to test changing anyway, you need to set packages: https://python-poetry.org/docs/pyproject/#packages
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
Something like:
packages = [
{ include = "main", from = "src" },]
So support for different package names is planned and will eventually be documented or default?
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).
This results in: ValueError: /src/src/main does not contain any element
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" }]
Looks like Poetry
I guess you would need to make it a package to use it like that: main/__init__.py. There's another setting...
┃ 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
Try this:
packages = [{ include = "src/main.py" }]
Curious if this works:
packages = [{ include = "main.py", from = "src" }]
This works
This results in:
✘ exec /runtime ERROR [0.93s]
┃ ╭─ Error
┃ │ The "main" module could not be found. Did you create a "src/main.py" file in │
┃ │ the root of your project?
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" }]
Also doesn't work:
┃ ValueError: /src/main.py 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
Did you add from = "src"?
Nope, I just realised
This works
Awesome
That's the simplest one for sure, I'm going to leave it like that
🙂
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 🙌
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.
Does it need special consideration? poetry install installs all groups by default
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.
Ah I see
A caveat here is that the lockfile is ignored. So you can't pin dependencies yet.
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
Yes, it's planned. I'm considering using micropipenv for that.