Automated Python to Mojo code translation
Project description
py2mojo
Automated Python to Mojo code translation
A tool to automatically convert Python code to the new Mojo programming language.
Installation
pip install py2mojo
Usage
You can read the usage by running py2mojo --help
:
❯ py2mojo --help
usage: py2mojo [-h] [--inplace] [--extension {mojo,🔥}] [--convert-def-to-fn | --no-convert-def-to-fn] [--convert-class-to-struct | --no-convert-class-to-struct] [--float-precision {32,64}]
filenames [filenames ...]
positional arguments:
filenames
options:
-h, --help show this help message and exit
--inplace Rewrite the file inplace
--extension {mojo,🔥} File extension of the generated files
--convert-def-to-fn, --no-convert-def-to-fn
--convert-class-to-struct, --no-convert-class-to-struct
--float-precision {32,64}
Examples:
❯ py2mojo myfile.py
❯ py2mojo mypackage/*.py
⚠ Disclaimer
Please be aware that the Mojo programming language is still in its nascent stages of development. As with any young language, there might be frequent updates, changes, and unforeseen quirks in its syntax and behavior. There will probably be instances where the conversion might not work and may require manual adjustments.
So, consider this tool as experimental. Please do not trust the generated code and double-check it.
Implementation details
This uses a similar approach to the pyupgrade tool, using the AST parser to analyze the Python code and replace some parts of it with the equivalent Mojo code.
As Mojo is a superset of Python, non-replaced logic should be also a valid Mojo code.
Contributing
How to install it locally
-
Fork the repository
-
Clone your fork:
git clone git@github.com:youraccount/py2mojo.git
- Install it locally:
cd py2mojo
pip install -e .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py2mojo-0.0.2.tar.gz
.
File metadata
- Download URL: py2mojo-0.0.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e621706db9a4ecfb05b17b9cb849f8bd0518f77b6492a375ce26c76db2414a |
|
MD5 | 38ee627c23ac4fc75ee6a3708dd61719 |
|
BLAKE2b-256 | 96f7a879817023aeb9e96d096826eca727bbd9adb45cca43c9713c5c918a0266 |
File details
Details for the file py2mojo-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: py2mojo-0.0.2-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162ceaee5fd4b5128612e19965c800d985ae67f720ec1ad5fd6eda413459d376 |
|
MD5 | 4df34e2ebcb5f438eddea37e9b02a066 |
|
BLAKE2b-256 | 9dd06e36af374f638e4c5b987991a031b6f57f6aa7e9af441dd690bb97c688e7 |