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.2-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.2-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.2-cp312-cp312-win_amd64.whl (488.9 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.13.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (631.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.13.2-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.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (637.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35f283c8458772c634c84de615d35710c816d7452d499e5297fee695fb186a0e
MD5 20c3e1f07acb982515e30853e45cbdd4
BLAKE2b-256 fe4e63ce1907496bc8fe88308af977504b0ef5b8b798a11c1f92e185aba4bc74

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.2-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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb1e2f9ff32819de88f026e6836fdac4d87fdb647f6b3f0900d5a4ba4dc59f32
MD5 6d23e2a0fb5b6803d742caae10df9991
BLAKE2b-256 bc58bc7420bc3b0f2448e99538b676bb14cd5c37c4814211027c75fa5f7c11a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f1a26f408c86cea0c42a2a024f3d62eaf88306e189616b4969d377f1efb84e2
MD5 7cda20ed7642d11823d1f9d42bd61ab9
BLAKE2b-256 2ba67a79829d43fd36f0c654d6cfb0cda6d7dae65c5e3a7806ce0e151340860a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 13a9e390a66b30a822c35aa3a6634bb6d57f4f9bd5735aa4dc998080b0c91c5e
MD5 4155c36fc35cbd0f2ab7fa8539824252
BLAKE2b-256 9536f6ff39730ff645193505fee2c199ad2216193238519d036399b9df161404

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0b1bd915bca4dba482620a8852b4b20d49d3de443ed840cad1d69f912297a04c
MD5 7b1412aba3cf5be3a9c7ba502ed82713
BLAKE2b-256 48bf09e860dbe5d4280705c9461fe804ef54b32dfc4ef3d469db0c7a5dd2ed0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e2bed8e79267b6e91604b25c92f3e6e68c0e4933aed19a14fa81deabbca15c7
MD5 5a3edd15b86ce6d4ad233460e43f1b90
BLAKE2b-256 7c5d5899f01e6e1df9271e148e2087c747679f92b78e928cf1b60a0fc6126e1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b2f08954f07687d2603fe24af71bf43df377f230db2c749a21906eef2dfcb776
MD5 fee70d413d6f9e605b1282aaac83e190
BLAKE2b-256 0402dc49204cc9b2f01b754a7c3bce6fbe3a86867ec957888c4bebff0399d15e

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.2-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.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 685c90d9029fce8234256e56e2715c5b4921d95256f30d47a8a7e14b07529305
MD5 0f0492e45b4142224007ab168c322e20
BLAKE2b-256 3093b2866f5faccc322c06ad336ec7377ac2910a6cf99d567e7ce842b3be50c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c49ced197afa3795c1324bdd888d26acd17ef5addb53d028a54f06f2f2f65f1b
MD5 b35c00d0f7dfa8fa82e412c14c4ed41d
BLAKE2b-256 ef25fb4a9df601a650f875324cd4a9d566f1451d3e38ef4cd0b50f7269f71bd6

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