Skip to main content

Make your mods immortal.

Project description

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

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

  1. Clone the grug-tests repository next to this repository
  2. Run git checkout development in the grug-tests repository.
  3. Follow the instructions in the grug-tests repository for building libtests.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

  1. pip install -e .[dev]
  2. pip install pyright[nodejs]
  3. 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/*

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

grug_lang-1.7.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

grug_lang-1.7.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file grug_lang-1.7.0.tar.gz.

File metadata

  • Download URL: grug_lang-1.7.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for grug_lang-1.7.0.tar.gz
Algorithm Hash digest
SHA256 9a0ba7e9aa632d560ae14f2a86932301f14736036f446591c2602db95326d90f
MD5 8fbd1b6c903b8982f2433f44e12e90f9
BLAKE2b-256 914de3dcf54887620aa2e72cc6b4561331b19b02af6a5a1759679525131ceed4

See more details on using hashes here.

File details

Details for the file grug_lang-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: grug_lang-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for grug_lang-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64ff82b4ea88b39055b9f9bf48ba169045f89e7c59cefb8f11e39d58dd7d91ba
MD5 9d204aea3a24898c5c5c92068a4527ad
BLAKE2b-256 8a25e4e1cd9ae2d0f963fc6436152b20fadcdf87f03f8ef7302c1d4861026fe4

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