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.1.0.tar.gz (15.2 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.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dopy_syntax-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 8838f9b086ce2aacdadcf66dff29cc4dfc88b53d8bf32fe7869e0887ce23d9a9
MD5 49bd421f98e465137a6d187b739cd770
BLAKE2b-256 99c3839d42f1c6a7fc0fbeeb4de089d0a8bf0a627b11fc15ea3f80046c704846

See more details on using hashes here.

File details

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

File metadata

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

Hashes for dopy_syntax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 738b281de07aca4d6b614f38f4603e1fa7314da72a5d53dc0be4e38e833205a3
MD5 7456ecce9cf540623c704ed8ab21ed43
BLAKE2b-256 69fef81788abcc5faada452ab20c628673b31e3e32f4d23f8b704a0ec20bef00

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