Skip to main content

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..end blocks 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)

-s,--stdout: Print the transpiled python code to console and exit

-c,--check: Check dopy syntax without transpiling

Syntax Rules

  • Make sure the do keyword is on the same line as rest of the block declaration,
  • end should be on its own line
  • all imports at the top of the module
  • must create a __init__.py file in dirs so that the transpiled python modules can be recognised

Acknowledgements

This project is hugely inspired by mathialo/bython

Todo

  • py2dopy script
  • function level imports
  • nvim-treesitter support

License

See LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dopy_syntax-0.0.2.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dopy_syntax-0.0.2-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file dopy_syntax-0.0.2.tar.gz.

File metadata

  • Download URL: dopy_syntax-0.0.2.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.8 Darwin/24.1.0

File hashes

Hashes for dopy_syntax-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4c3a380a6e8af0cae69adb887af662953a17cf60b87361d159e4fd13c5f315ef
MD5 3c8c3155ff55b9d2e11014a4427ceeb0
BLAKE2b-256 0a819086441e654e883c51ae8b8b6f21d18e0f2f0425eb6df59553cd1397bb5a

See more details on using hashes here.

File details

Details for the file dopy_syntax-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dopy_syntax-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.1 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

Hashes for dopy_syntax-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7ed872d3f245a9247b914f20db7762c80fa22c0fa380cb7668db2a725e84b9c6
MD5 fd17ac5a558188e6b9cb1756f8864f63
BLAKE2b-256 9cefccbc7ec6447373bf714c5851a2e0d68bfdbc1431d0ca1396490abb30be4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page