Replies: 1 comment 1 reply
-
Related: https://discord.com/channels/1087530497313357884/1161291847734403072/1161348656239231247 Rust allows this: https://stackoverflow.com/questions/58739075/how-do-i-import-multiple-versions-of-the-same-crate I'm very interested in being able to vendor libraries easily with the mojo package manager. If I use a lib and no functions/structs of this lib is exposed publicly in my interface, I don't see why the user should have to care about what's the version of my lib and how it fits with other libraries's requirements. e.g. I can vendor numpy if I only use numpy to do some computation and never use numpy arrays in my public interface, it improves the packaging UX for my end users as I won't add any version requirement on their numpy installed. Many projects actually do this manually and vendor old versions. For example Pydantic: |
Beta Was this translation helpful? Give feedback.
-
The Wikipedia article dependency hell provides a good definition and list of dependency hell forms. The proposed solution should solve all the forms of the dependency hell, but for the sake of clarity, we shall consider only the "Conflicting dependencies" form.
Example of conflicting dependencies
Imagine we have an application where we need to import third party
library_a
andlibrary_b
. Howeverlibrary_b
also depends onlibrary_a
in version 1.7, but in our own code we depend onlibrary_a
in version 3.0 which is not backwards compatible with version 1.7. This poses an unsolvable problem in most programming languages, as they do not allow "Side-by-side installation of multiple versions" (although there are frameworks like OSGI which allow solving this kind of issue on a higher level).Proposed solution for side-by-side installation in Mojo
In order to solve dependency hell, a future Mojo package manager could allow multi version side-by-side installation of the same package, this however is only one part of the solution.
Automatic import rewrite
Say application code and dependency definitions always take precedence and the package manager installs
library_a
in version 3.0 and additionally introduceslibrary_a_1_7
which reflects the 1.7 version of thelibrary_a
, needed bylibrary_b
. As the code inlibrary_b
imports symbols formlibrary_a
with statements similar to:from library_a import *
,library_b
would link tolibrary_a
in version 3.0, which can potentially lead to compilation or even runtime errors. Hence I would suggest that the compiler rewrites the import statements inlibrary_b
to befrom library_a_1_7 import *
. Given that Mojo packages contain not only binary, but also the IR code for recompilation, this should be feasible.Beta Was this translation helpful? Give feedback.
All reactions