Skip to main content

No project description provided

Project description

Testing Deploy Documentation

cython-extensions-sc2

API Documentation - for a full list of included functions.

cython-extensions-sc2 is a library designed for the python-sc2 API. Its purpose is to offer optimized Cython alternatives for commonly used functions, along with additional useful custom functions.

Note: This library is included for ares-sc2 users by default, no further setup is required.

This library also supports python-sc2 and sharpy-sc2 bots, see Getting Started below.

Example speedups, results may vary depending on machine and exact scenario. This is by no means a list of all functionality offered.

python-sc2 function cython speedup
units.closest_to 6.85 - 13x speedup depending on scenario
distance_to 3 to 7x speedup depending on scenario
position.center 2x speedup
already_pending for units 6.62x speedup
already_pending for structures 4x speedup
units.in_attack_range 2.05x speedup
units.sorted_by_distance_to 8.62x speedup
unit.is_facing 9.1x speedup
Point2.towards 14.29x speedup
has_creep 4 - 5x speedup
in_pathing_grid 4 - 5x speedup
closer_than 12x speedup
further_than 12x speedup

Tip: use cy_distance_to_squared where possible for extra 1.3x speedup.

Getting started

To quickly get up and running locally (for python versions 3.11, 3.12), install cython-extensions-sc2 with:

pip install cython-extensions-sc2

Type Safety

cython-extensions-sc2 includes type safety checking to prevent your bot failing with silent errors. This is disabled by default for pure performance reasons, to enable it call enable_safe_mode(True).

from cython_extensions import enable_safe_mode
# immediately after importing any cython functions
enable_safe_mode(True)

Even with safe mode disabled, there will still be some function overhead, but it should be negligible. However, if you want to squeeze every last bit of performance out of your bot, you can import cython functions directly from the cython files to avoid using the type checker functionality all together.

Example using cy_closest_to turning off safe mode for some performance:

from cython_extensions import cy_closest_to, enable_safe_mode
enable_safe_mode(False)

You could instead import cy_closest_to directly:

from cython_extensions.units_utils import cy_closest_to

Shipping to ladder

When shipping to ladder, grab ubuntu-latest_python3.12.zip from releases in this repo and extract cython_extensions directory within the zip to the root of your bot's directory, like so:

MyBot
└───cython_extensions
│   └───cython-extensions library files
└───your bot files and directories

Alternative local setup

If you already have a python-sc2, or sharpy-sc2 development environment setup, then cython-extensions should work out the box with your bot without the need to install extra requirements. Simply check out the releases on this repo and download the correct zip for your system.

release

For example a Windows user should download windows-latest_python3.12.zip.

Inside this zip you will find a cython_extensions directory, this should be placed in your bot's root directory like so:

MyBot
└───cython_extensions
│   └───cython-extensions library files
└───your bot files and directories

Start using cython-extensions-sc2

For ease of use all cython functions are importable via the main module, for example:

from cython_extensions import cy_distance_to, cy_attack_ready, cy_closest_to

note: in this project all library functions have a cy_ prefix to prevent confusion with python alternatives.

Contributor / Cloning the project

Install poetry if you do not already have it installed.

Then to setup a full development environment run: poetry install --with dev,test,docs,semver

This will set up a new environment, install all required dependencies and compile the cython code for your system.

If you modify the cython code, run poetry build to compile it.

Jupyter Notebooks

Run poetry run jupyter notebook to open jupyter notebook in the environment. See the notebooks directory for examples. Use template_notebook.ipynb as a starting point for your own notebooks.

Updating ids

ability_mapping.pyx ids are generated via a script, these should be updated after a new SC2 version is released. Run poetry run python scripts/update_ability_mapping to update the ids.

Run Test Bot

Edit the map in bot_test.py and run with: poetry run python tests/bot_test.py

Contributing

Contributors are very welcome! There are many missing alternative python-sc2 functions, and if you're into optimization, the existing functions could likely be improved.

Adding new functions

If you want to add a new function, please add it to the relevant '.pyx' and '.pyi' files. See existing functions for examples. Please also add tests for your function in the tests directory.

Additionally, the new function should be added to the type checking system in cython_extensions/type_checking First add a validation function inside cython_extensions/type_checking/validators.py using the existing examples as guidance.

Then add a safe_wrapper function inside cython_extensions/type_checking/safe_wrappers.py using the existing examples as an example. Ensure your new function is exported at the bottom of this file. Preferably check the new function works in a real bot before submitting a PR. You can use tests/bot_test.py to test your function.`

Commit messages

Please use conventional commits if you choose to contribute, it helps the automatic releases detect a new version and generates an accurate changelog.

Example git messages:

feat: add new cython function

fix: fixed buggy function

test: add new test

ci: update github workflow

docs: add new docs

chore: add dependency

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

cython_extensions_sc2-0.13.1-cp313-cp313-win_amd64.whl (487.9 kB view details)

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.13.1-cp313-cp313-musllinux_1_2_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.13.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.13.1-cp312-cp312-win_amd64.whl (489.3 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.13.1-cp312-cp312-musllinux_1_2_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.13.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.13.1-cp312-cp312-macosx_11_0_arm64.whl (632.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.13.1-cp311-cp311-win_amd64.whl (501.7 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.13.1-cp311-cp311-musllinux_1_2_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.13.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.13.1-cp311-cp311-macosx_11_0_arm64.whl (638.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cython_extensions_sc2-0.13.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 22fb834023b42716dfadfdcb587e2d3763702e2728685b2df4456afbcb9942be
MD5 7d406754643ed9bb2048e6d07baae38b
BLAKE2b-256 4308e7c378d7a7c82fc2e277359c5a79cc5bffc9552d6c613d165e42a28dee88

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 051153b45bd4d00755b25a22467fd362e2d4d6e95d8c594f73ff497bc6bf22b2
MD5 d31b05a5170e8701a64067094224aeb5
BLAKE2b-256 99048a8a7084e9e9db68ff51e870d8369977f4d74cb79a33c6fb19eb09662073

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 49e443179abd96cc5d1b0478ec5679acf83190a2ad3c4f7514524f764cd6e407
MD5 da0ce349f9323f2eea728eb8363e326d
BLAKE2b-256 a2da657f81d1930262618fd21587ffb018130bab7e45beaa2718f09ef4c5f89e

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a2a8afbde3e29cd5542342033a0ce11966bedb9cd191091c8c9cf62be5a3492
MD5 825b1d49647a8f73ce5a6b64586f795f
BLAKE2b-256 5234ad15ee18bb9c7c51de60e562014b96f3327c74c7c1bdf099467f4cc68fe3

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d8aab216653f3262f9cfd2388bab002647c24555550513a38d2693fecf611776
MD5 e478ccda6febc3ca9056fbc78d53b2a1
BLAKE2b-256 8d9512d58e2b0f646755f821aa69b60b43bd3c87bd49fa9b68c082c671465206

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b59c9cfbb96a8c8591da0cd224b0ecfaafc9091102be0f3fc545af4fbccb8d41
MD5 af490198a03fada3237c31482784582d
BLAKE2b-256 75ffc4829cc8b7faeb89980e5fd869526a91fc41083d8e72b24981650d17276d

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c22ac6ec399d4acedb81c4be346d8b5dc5b7ffd070d279210f387b2639523e8f
MD5 2e9c6182896ec767b274cb8a14dc7968
BLAKE2b-256 584d30083a7a76bc1ada15909ce3af126103af0351d2b9f40246cd1ec0263826

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5cca813aa16d5c7091f0e832b8a866028d754d67035c59ad8f898e7903fe8af9
MD5 c0824b5c779ad6a19eb4f0adaf1b2302
BLAKE2b-256 3bd865a22f0b773c6a86e54a637cee5f0d52e6e12b12b34c48f4a5b9c45e9da4

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 43abbc999cb7f7b33da3d400e2e3d950c586688fafaf943e80a443f615d20cf5
MD5 dbd97b5df0e9942231891e238675806a
BLAKE2b-256 fe53cc1ee49066453e194c7a5a9009c4214c6c386ce2078945d2c4d94453431d

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 350737a3ea9f13caf7df94fb98db647355c582f9f0cb9f6ddfcf287ac1f2b409
MD5 875880c1936bfdd6e268979f34159c3e
BLAKE2b-256 d9c6475e2b9d7d9e142a01dc6598a365f1c7ba05cc73a1bf4962bd029a9e8eaf

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 206435b64e5afc1afcc6f969c11409b9dfe6a636b4b914ae0bcac82b2ed82a65
MD5 8fa56f0d0ae0a6cfeac0357bcb2214ed
BLAKE2b-256 f040dc7162ffa7c1651b639f3e4ecc3f3b885e7664be792a2f76c0146457ec1d

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