Skip to main content

Transpiles Bython to Python

Project description

Bython

Python with braces. Because Python is awesome, but whitespace is awful.

Bython is a Python preprosessor which translates curly braces into indentation.

Key features

  • Write Python using braces instead of whitespace, and use the transpiler to convert it to valid Python code
    • Transpiles curly braces while keeping maps, fstrings, and curlies inside strings intact
  • Allows for translation of && and || to and and or
  • Can optionally translate true and false to True and False

Code example

myMap = {
    "status": "awesome!"
}

def print_message(num_of_times) {
    for i in range(num_of_times) {
        print(f"Bython is {myMap["status"]}");
    }
}

if __name__ == "__main__" {
    print_message(10);
}

Installation

Install from pip

$ python -m pip install bython-prushton

Quick intro

Bython works by first translating Bython-files (required file ending: .by) into Python-files, and then using Python to run them. You therefore need a working installation of Python for Bython to work.

To run a Bython program, simply type

$ python -m bython-prushton source.by 

to run source.by. If you want more details on how to run Bython files (flags, etc), type

$ python -m bython-prushton -h

To transpile an entire directory, run bython with the -o to specify the output directory, and -e to specify the entry point.

$ python -m bython-prushton -o dist -e main.py src

To transpile without running, omit the -e argument. You can also include -t to translate lowercase booleans to uppercase and null to None

$ python -m bython-prushton -o dist -t src

Contributing

Code

If you want to contribute, make sure to install

  • Python
  • Colorama

All source code is located in src

  • src/bython.py handles the command line arguments
  • src/parser.py handles tokenizing and parsing files
  • src/py2by.py parses python to bython and could use some help

testcases only test bython conversions, and are structured as follows:

<test name>
|-main.by Bython code to convert
|-expected_out.txt Expected out when running the bython
|-build/ Dir for transpiled python code

run make test to run bython tests

Installation

If you want to write an install recipe for windows or mac, please feel free. I cannot write these scripts myself as I have neither.

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

bython_prushton-1.1.5.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

bython_prushton-1.1.5-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file bython_prushton-1.1.5.tar.gz.

File metadata

  • Download URL: bython_prushton-1.1.5.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bython_prushton-1.1.5.tar.gz
Algorithm Hash digest
SHA256 b426773086b6de31adbbb3ee2e86798335c37a39a0572d013a2346820f9d50a3
MD5 f6f0819c31ff79641d0a7b81d8a9c1b3
BLAKE2b-256 399f86de4ced81feb3a99c6bbf08b0e4fe911b0ef127ba137b856d64ed3cb400

See more details on using hashes here.

File details

Details for the file bython_prushton-1.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for bython_prushton-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2b09d2cca18efb14ebde4ed6613c06f521e76d49315fd51246282ee3a0641543
MD5 917f437afdadb4250256b03399ea5a15
BLAKE2b-256 38b20244faaaa2b6eb615e3fb3c8ab4e6f501b6e97e1bf613bb277f5ca4d6401

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