-
Notifications
You must be signed in to change notification settings - Fork 991
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
[bug] conans.model.version can't be imported unless conan is imported first #17493
Comments
Hi @fredizzimo There is already a public API for Yes, anything under |
I'll reply on a more general level first, before creating specific issues. The conan/conan/tools/scm/__init__.py Line 2 in 581a04a
Here's a list of all from conans.client.graph.graph import DepsGraph
from conans.client.graph.graph import Node, RECIPE_EDITABLE
from conans.client.graph.graph_error import GraphError
from conans.client.graph.python_requires import PyRequires
from conans.model.info import ConanInfo
from conans.model.layout import Infos, Conf
from conans.model.options import Options
from conans.model.recipe_ref import RecipeReference
from conans.model.requires import Requirements
from conans.model.settings import Settings
from conans.model.version import Version
from conans.model.version_range import VersionRange Much of it is to just get typing information, for example our main def init(self):
self.name: str
self.settings: Settings
self.options: Options
self.python_requires: PyRequires # pylint: disable=attribute-defined-outside-init
self.requires: Requirements
self.tool_requires: Requirements
self.info: ConanInfo
self.cpp: Infos
self.conf_info: Conf
self.build_folder: str
self.package_folder: str
self.source_folder: str
self.export_sources_folder: str
self.recipe_folder: str Others, like the conan/conan/api/subapi/list.py Line 37 in 581a04a
In some cases, the models are referred to in the documentation like, |
Thanks for the feedback. I am afraid that this will be a challenge. We will move the remaining Even after the move, it will not be allowed to import Please understand that the surface area of Conan codebase is huge. We cannot just simply expose all of it and allow users to use it directly, that will automatically put the project development and evolution to a halt, because it will be impossible to modify anything without breaking users. So there are no plans to expose that much of the Conan internals in the public API. Regarding typing, which might help for IDE auto completion and things like that, is also strongly discouraged, except for publicly available and documented models. Because such typing automatically expose to developers all implementation methods and attributes of those classes, even if they are not publicly documented and not intended for being used in recipes or user code in general, which are not only likely to break, but also have risky behavior that can easily can cause bugs and issues when used directly in user code.
Yes, this is generated automatically from code, so some errors are expected, this is why the API is still marked as experimental. It is very likely that these objects when exposed in the API will either be treated as opaque objects (they can only be returned and passed to other API methods), or they will have a very limited public api, like a |
Thanks for the reply, and explaining your situation, which we completely understand. That's indeed a tricky situation, and we are aware of things breaking. So, we are currently treating every update as a potentially breaking one by locking the patch version of Conan, so in that sense it's not the end of the world if things move around and change a bit. All our code was done before there was any documentation for the API, or at least much less than the current one, so we had no way of knowing what's supposed to be exposed or not. The tests do not help either, for example https://github.com/conan-io/conan/blob/44fe575039d8eb314c41668a056fd3973c6567c7/test/integration/conan_api/list_test.py, since they also import from the That said for a way forward, I suggest that you create interfaces for everything exposed by the API, and completely type annotate it. The type annotation is quite important for us actually, since we have quite much code dealing with Conan, and would like to be able to lint everything properly. It also helps with detecting errors when updating. And the interfaces help with isolating the actual implementation and only expose what's needed. Documentation does not work as well, since it's much harder to check, and when things change, it's easy for things to get unnoticed. Similarly, the type annotation for the Conan file was required to get even somewhat reasonable output from pylint. Without it, it gets very confused. So, it would be nice to get that officially annotated as well. Once there's a good specification, we can look at the API, and give more concrete examples of things currently missing, and what we need to do. At least I hope so, because someone else is taking over the maintenance of the conan code on our side. |
Describe the bug
When trying to import
conans.model.version
without importing anything else first and import error is generatedThe bug might be invalid if things under
conans
is considered private. But in practice for us, it isn't since a lot of the API uses models that only exists there, so I think at least bigger parts of it need to be public.Tested with Conan 2.9.3 and 2.10.2
How to reproduce it
The text was updated successfully, but these errors were encountered: