Skip to main content

Provides pandas-like expressions capabilities to the bolt extension of mecha

Project description

bolt-expressions

GitHub Actions PyPI PyPI - Python Version Code style: black Discord

a pandas-esque API for creating expressions within bolt

Introduction

Bolt is a scripting language which mixes both python and mcfunction. This package amplifies this language by adding an API for creating fluent expressions loosely based off of the pandas syntax. These expressions are use for simplifying large bits of scoreboard and storage operation allowing you to swiftly create complex operations with the ease of normal programming.

from bolt_expressions import Scoreboard, Data

math = Scoreboard.objective("math")
storage = Data.storage(example:temp)

stack = storage.hotbar[0]

math["@s"] = stack.Count * math["$cost"] + math["$value"] - stack.tag.discount * 0.75

->

execute store result score @s math run data get storage example:temp hotbar[0].Count 1
scoreboard players operation @s math *= $cost math
scoreboard players operation @s math += $value math
execute store result score $i1 bolt.expr.temp run data get storage example:temp hotbar[0].tag.discount 0.75
scoreboard players operation @s math -= $i1 bolt.expr.temp

Installation

The package can be installed with pip. Note, you must have beet, mecha and bolt installed to use this package.

$ pip install bolt-expressions

Getting started

This package is designed to be used within any bolt script (either a .mcfunction or bolt file) inside a bolt enabled project.

require:
    - bolt
    - bolt_expressions

pipeline:
    - mecha

Once you've required bolt and bolt_expressions, you are able to import the python package directly inside your bolt script.

from bolt_expressions import Scoreboard, Data

Now you're free to use the API objects. Create objectives, block, storage and entity nbt sources to easily write expressions as simple or complex as you like to make it.

math = Scoreboard.objective("math")
executor = Data.entity("@s")
block = Data.block("~ ~ ~")
storage = Data.storage(example:storage)

math["$value"] = math["$points"] + executor.Health*10 + block.Items[0].Count - storage.discount

storage.values.append(math["$value"])

->

execute store result score $value math run data get entity @s Health 10
scoreboard players operation $value math += $points math
execute store result score $i1 bolt.expr.temp run data get block ~ ~ ~ Items[0].Count 1
scoreboard players operation $value math += $i1 bolt.expr.temp
execute store result score $i2 bolt.expr.temp run data get storage example:storage discount 1
scoreboard players operation $value math -= $i2 bolt.expr.temp
data modify storage example:storage values append value 0
execute store result storage example:storage values[-1] int 1 run scoreboard players get $value math

Features

  • Robust API supporting Scoreboards, Storage, Blocks, and Entities
  • Provides an interface to manipulate large, complex mathematical expressions simplily
  • Automatically initializes objectives and score constants
  • Allows you to interopt custom variables with normal commands

Checkout some examples over at our docs!

Contributing

Contributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project uses poetry.

$ poetry install

You can run the tests with poetry run pytest.

$ poetry run pytest

The project must type-check with pyright. If you're using VSCode the pylance extension should report diagnostics automatically. You can also install the type-checker locally with npm install and run it from the command-line.

$ npm run watch
$ npm run check

The code follows the black code style. Import statements are sorted with isort.

$ poetry run isort bolt_expressions examples tests
$ poetry run black bolt_expressions examples tests
$ poetry run black --check bolt_expressions examples tests

License - MIT

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

bolt_expressions-0.17.1.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

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

bolt_expressions-0.17.1-py3-none-any.whl (47.0 kB view details)

Uploaded Python 3

File details

Details for the file bolt_expressions-0.17.1.tar.gz.

File metadata

  • Download URL: bolt_expressions-0.17.1.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/43.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/8.2.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.16

File hashes

Hashes for bolt_expressions-0.17.1.tar.gz
Algorithm Hash digest
SHA256 7b3cf0e7d91a5c91b98d82abdd3625e3b02f494832b1d0a691ccfc22e1f818f0
MD5 e433ceda286a6d53c8ca6be189308666
BLAKE2b-256 5dcb29bc2f4a298d5eeb1d9c4ec60b418a4d7685f873e86f8ef4d139f360265b

See more details on using hashes here.

File details

Details for the file bolt_expressions-0.17.1-py3-none-any.whl.

File metadata

  • Download URL: bolt_expressions-0.17.1-py3-none-any.whl
  • Upload date:
  • Size: 47.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/43.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/8.2.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.16

File hashes

Hashes for bolt_expressions-0.17.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01a29025b89cd52d467002088e1f43a4f25596b638f97e834f4cbcad5c224097
MD5 b8e37c4d98349b3570ea8b11030fa6bf
BLAKE2b-256 4e11dd202cfe6deda118b4a9311093880d2f14b7fbf84a1d539fdcc0ddf9bc7e

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