Transform Python code using do..end blocks instead of indentation-based scoping
Project description
dopy
An experimental Python preprocessor that enables do..end syntax in place of strict indentation
Requirements
python 3.10+pip
Installation
pip install dopy-syntax
Features
- Converts ruby/lua style
do..endblocks into indented blocks - Maintains python's semantics
- Preserves string literals and comments
- Processes .dopy files into pep8 compliant .py files (maintaining the dir structure)
- supports type hints
- Recursively transpiles imports (multithreaded)
Usage
Programmatic
from dopy.core import Dopy
dopy = Dopy()
source = '''
def hello_world() do
print("Hello")
end
hello_world()
'''
processed = dopy.preprocess(source)
exec(processed, namespace={})
More examples in the examples dir
cli
dopy my_module.dopy
Will use the current active python interpreter, can be overridden with PYTHON_PATH env var
Flags
-h --help: Print help text
-k --keep: Keep transpiled python files in place (will overwrite)
-d --dry-run: Print the transpiled python code to console and exit
-c --check: Check dopy syntax without transpiling
Syntax Rules
- Make sure the
dokeyword is on the same line as rest of the block declaration, endshould be on its own line- all imports at the top of the module
- must create a
__init__.pyfile in dirs so that the transpiled python modules can be recognised
Acknowledgements
This project is hugely inspired by mathialo/bython
Todo
-
py2dopyscript - function level imports
- nvim-treesitter support
License
See LICENSE
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dopy_syntax-0.0.1.tar.gz.
File metadata
- Download URL: dopy_syntax-0.0.1.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.8 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f8269533c5a0f325d8e34b2a9e3a67a2bb0c27226afc3b15d81ef4031ebeed0
|
|
| MD5 |
cd538d3a81ab69247452d1613b1c12b2
|
|
| BLAKE2b-256 |
e21db46c0cd745373c273f49a437b33b47de6f333e4ad0f8437daa6c788a540a
|
File details
Details for the file dopy_syntax-0.0.1-py3-none-any.whl.
File metadata
- Download URL: dopy_syntax-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.8 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa71969268b392eb1a0f4c8048edb74e1db144d2fb7b64331b13575beda7458f
|
|
| MD5 |
9e4fa14ed7f0462d6d7408bca522758d
|
|
| BLAKE2b-256 |
9bda48e5e412f0e7b791129f5b62bafc60db3cc6d4d9cfd10bb5e5660650cad9
|