grug for Python
This repository provides Python bindings, a frontend, and a backend for grug. It passes all tests in grug-lang/grug-tests.
Install this package using pip install grug-lang, and run python -c "import grug" to check that it doesn't print an error.
A minimal example program is provided in the examples/minimal/ directory on GitHub:
import grug
import time
state = grug.init()
@state.game_fn
def print_string(string: str):
print(string)
file = state.compile_grug_file("animals/labrador-Dog.grug")
dog1 = file.create_entity()
dog2 = file.create_entity()
while True:
state.update()
dog1.on_bark("woof")
dog2.on_bark("arf")
time.sleep(1)
on_bark(sound: string) {
print_string(sound)
# Print "arf" a second time
if sound == "arf" {
print_string(sound)
}
}
Run it by cloning the repository, cd-ing into it, running cd examples/minimal, and finally running python example.py.
See the examples/ directory for more interesting programs, like examples/using_grug_packages.
Dependencies
This project requires Python version 3.7 or newer. You can manage your Python versions using pyenv.
If you are on a Python version older than 3.11, you will need to install these:
pip install tomli importlib-metadata
If you want to run the tests, you will need to install pytest:
pip install pytest
pip install -e .
Tests
Run python tests.py to test all examples and package tests.
Testing grug-lang changes
Either uninstall grug-lang, if you had it installed:
pip uninstall grug-lang
Or set up a virtual environment:
rm -rf .venv
python -m venv .venv
source .venv/bin/activate
And then create an editable install of grug-lang:
pip install -e .
Building libtests.so
- Clone the grug-tests repository next to this repository
- Run
git checkout developmentin thegrug-testsrepository. - Follow the instructions in the
grug-testsrepository for buildinglibtests.so.
Running tests
In this grug-for-python repository, you can run all tests using this command:
pytest --grug-tests-path=../grug-tests -s -v
Pass --whitelisted-test=f32_too_big to only run the test called f32_too_big.
Alternatively, you can walk through the tests and set breakpoints by installing the Python Debugger VS Code extension. Hit F5 to run all tests. You can edit .vscode/launch.json to pass --whitelisted-test=f32_too_big.
Type checking
pip install -e .[dev]pip install pyright[nodejs]pyright
Updating the pypi package
python -m pip install --upgrade pip
python -m pip install --upgrade build
python -m build
python -m pip install --upgrade twine
python -m twine upload dist/*
Metadata
Release files for grug-lang 1.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| grug_lang-1.9.0.tar.gz | 31.7 kB | Without provenance | Details for grug_lang-1.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grug_lang-1.9.0-py3-none-any.whl | Python 3 | none | any | Details for grug_lang-1.9.0-py3-none-any.whl |
Total release size: 62.2 kB
Release files / grug_lang-1.9.0.tar.gz
| Download URL | grug_lang-1.9.0.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13fa8e98e65b0f218c8c861710a41b49032820d28df80e05a63922c279cc000c
|
|
BLAKE2b-256 checksum How to use checksums |
8c68f86404314e77183a5c5f7dfd95cc4288a90e6030ce2f90900bed5c32323d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / grug_lang-1.9.0-py3-none-any.whl
| Download URL | grug_lang-1.9.0-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69a3a7775f01a8d681b32c8125dad839a9f3354004d854ea8d73fce6573546bf
|
|
BLAKE2b-256 checksum How to use checksums |
bb855ee063fc89547846c935c9af4122438af5bf66826813dc374ac7e7f71254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Security for grug-lang 1.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.