You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python has support for running the __main__.py file of a package through the python -m <pkg> command. I noticed that while installing Maturin exposes the maturin command, it does not allow you to run python -m maturin.
One of the reasons for allowing this method is to choose which specific Python interpreter to use. I believe that using specific versions of Python is necessary for certain bindings. (I'm not positive on that, though.) If a developer has multiple versions of Maturin installed on there machine, each for a different Python version, this allows them to gracefully pick which version to use.
# Instead of
$ /path/to/python3.8/bin/maturin develop
# We could run
$ python3.8 -m maturin develop
Or for windows:
$ py -3.9 -m maturin develop
Another thing to keep in mind is that multiple popular packages use __main__.py as well. PIP, Flask, Rich, and many others use it.
Solution
I propose that Maturin exposes a __main__.py file in the maturin folder. This file would either call the executable file directly, or call the specific function in the Rust bindings.
Drawbacks
While doing this would be good for compatibility, there are a few issues. The first is that the only way the Python package can access Maturin is through calling the executable with subprocess. This makes assumptions that Maturin is on the path already. If this method is used, there is no way to call a specific Python interpreter. This essentially removes the point of using __main__ in the first place.
The fix this, __main__ needs to figure out where the specific version's Python folder is, then call the located executable. This isn't that difficult to do, (I'm pretty sure there's a built-in function for finding the folder), but still seems overly-complicated.
On the other hand, if we didn't want to use subprocess, we'd have to ship a library file with the folder. We'd also have to abstract main.rs to another file that can be imported by Python. This version probably won't work, as it requires too many breaking changes.
Conclusion
Adding a __main__.py file to the Python package that can be executed with python -m maturin would benefit both compatibility and version-specification. This Python file would locate where binaries are installed for that specific Python version (or virtual environment), then call the Maturin executable that exists there.
Thank you for your time and consideration,
~ BD103
The text was updated successfully, but these errors were encountered:
Reasoning
Python has support for running the
__main__.py
file of a package through thepython -m <pkg>
command. I noticed that while installing Maturin exposes thematurin
command, it does not allow you to runpython -m maturin
.One of the reasons for allowing this method is to choose which specific Python interpreter to use. I believe that using specific versions of Python is necessary for certain bindings. (I'm not positive on that, though.) If a developer has multiple versions of Maturin installed on there machine, each for a different Python version, this allows them to gracefully pick which version to use.
Or for windows:
Another thing to keep in mind is that multiple popular packages use
__main__.py
as well. PIP, Flask, Rich, and many others use it.Solution
I propose that Maturin exposes a
__main__.py
file in thematurin
folder. This file would either call the executable file directly, or call the specific function in the Rust bindings.Drawbacks
While doing this would be good for compatibility, there are a few issues. The first is that the only way the Python package can access Maturin is through calling the executable with subprocess. This makes assumptions that Maturin is on the path already. If this method is used, there is no way to call a specific Python interpreter. This essentially removes the point of using
__main__
in the first place.The fix this,
__main__
needs to figure out where the specific version's Python folder is, then call the located executable. This isn't that difficult to do, (I'm pretty sure there's a built-in function for finding the folder), but still seems overly-complicated.On the other hand, if we didn't want to use subprocess, we'd have to ship a library file with the folder. We'd also have to abstract
main.rs
to another file that can be imported by Python. This version probably won't work, as it requires too many breaking changes.Conclusion
Adding a
__main__.py
file to the Python package that can be executed withpython -m maturin
would benefit both compatibility and version-specification. This Python file would locate where binaries are installed for that specific Python version (or virtual environment), then call the Maturin executable that exists there.Thank you for your time and consideration,
~ BD103
The text was updated successfully, but these errors were encountered: