Importing from dependency during build in __init__.py
fails
#3065
-
Hi, Here's a behavior that I try to understand and how to properly work with: My Python application has some imports from its default dependencies in its E.g.: Installing the project as an editable package...
✖ Update application 1.0.0.dev0+g0800c24d.local -> None failed
See C:\Users\<blackened>\AppData\Local\pdm\pdm\Logs\pdm-install-u1if94ts.log for detailed debug log.
[BuildError]: Build backend raised error: Module 'descope' is missing, please make sure it is specified in the 'build-system.requires' section. If it is not possible, add it to the project and use '--no-isolation' option.
File "<blackened>\__init__.py", line 1, in <module>
from descope import DescopeClient
ModuleNotFoundError: No module named 'descope'
Note: descope is just a random library that I added as default dependency to proof my point. I understand the error message but I would like to understand also
Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
why would it import your package during build? that doesn't seem correct. you may be doing things wrong but I can't guess unless you provide more info or code |
Beta Was this translation helpful? Give feedback.
-
My bad, I wasn't even aware of this detail until @pawamoy mentioned it: using dynamic version (in my case a getter) makes the difference. My example from above, indeed, does not reproduce the error. The example has to be extended like this (I add an archive with the source for your convenience). BTW: I reproduced it with pdm version 2.16.1 and 2.17.2, both with pdm-backend version 2.3.3
[project]
name = "pdm_build_test"
dynamic = ["version"]
description = "Default template for PDM package"
authors = [
{name = "b-morgenthaler", email = "some_email@some_company.org"},
]
dependencies = [
"descope>=1.6.6", # note that this is just a random dependency - could be anything
]
requires-python = ">=3.10.14"
readme = "README.md"
license = {text = "MIT"}
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
[tool.pdm]
distribution = true
[tool.pdm.version]
source = "call"
getter = "src.pdm_build_test.version:get_package_version" |
Beta Was this translation helpful? Give feedback.
You can refactor the get version function out of your package to make it standalone