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.0-cp313-cp313-win_amd64.whl (488.0 kB view details)

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.13.0-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.0-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.0-cp312-cp312-win_amd64.whl (489.3 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.13.0-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.0-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.0-cp312-cp312-macosx_11_0_arm64.whl (632.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.13.0-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.0-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.0-cp311-cp311-macosx_11_0_arm64.whl (638.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7e28e652b986ae19533478366d2ea3d3dfae6d77c0e4688009f94342ff5480d3
MD5 14c9a6f4908af45ebbe344808407ddd0
BLAKE2b-256 7d9e96b312d6094670b2c0a8f50b9a03d264800723ca84cc288c9102cddfa288

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f4ac2725f457a0ff7979edd3915e3ca9040c2ff6a6200e55b1743ec0b843ee47
MD5 c78d69042d9ed213a32b8b9b772f8ff7
BLAKE2b-256 ba5b3c96c6034f723570d594f1efea6bc99bde5ef954b2f47dcb1f2c15285c2c

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a9f7315b9e2b1f84d7c8797c50b8e7c63bdaf467ec4741c3967f04e43ed07c1
MD5 2bea76976cdbb19b6ef81fbd14651095
BLAKE2b-256 8b74df17d8b8265a23afa292b7b1ac25943272fb6d1e30165742a9a3a80af2a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 41bd61cd03805b4af424cdb8f8db9728c0eb00180a2ff4ea04e42287a4bd348e
MD5 18d08d0d89d59c541823abaefc6c5cdb
BLAKE2b-256 e60e0ffb8fc537e930878f8c7bdec583ba98898514ca032a920d92ffef034156

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9ec59c54d0decc18a8248464e0b1b645ff6e85e090599779145e467992838735
MD5 afa63f60310588e385f42a39d662ba49
BLAKE2b-256 7a041ed4b7d1f7a3279f782c69b3d8bab92943bc5383d073f6deeb08ab92ea12

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ffa043fe65b8c6397af8672125432a3eaec9c07d85fad3fe6b3641c67a41d79a
MD5 3070e13a4b92236ac63afebec202c7aa
BLAKE2b-256 e33ce85a9aee770277ab8b673df80fb5577536c762d1885dbcdf99cbb5b741c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d8a1e78197173d982d901f1b694c3d2ee1580cc34c69a398a06a412b61ca2f72
MD5 865bc7adf42e9044354d0bf3ab9fb290
BLAKE2b-256 8d47473c4735370e6786507453abc38ed4c978b516bf2874ee06b26b7298ee90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4ddd328b20504d045565b755b300eba30333ac185d44d6c09c7e0356717fcd4b
MD5 d6b2f6b550f4bb2966d0b09848b14653
BLAKE2b-256 4640fac78e1022c0b710eec7fdb682a168bfd92efc19512b46bcdcdb74b8407b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 909f6bdbd8fddd4f552799be95a5d20509b94c67162c7f54f9d6490930ff0b35
MD5 be9a1050a0753085bea27ef4289186f3
BLAKE2b-256 72db474b8d468c10485739a65d4afc529527a43bad47b84035836268a8694140

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 146a7a8993e914234570e5d7d369c27f0a894a25ed430c8ea10847eacd403f69
MD5 7fe75ba392340c71cf1ca2136b482d63
BLAKE2b-256 7f8d395c651a77125547a0072a1e1e682a033849eecec04f327afa497fd0d111

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25245361ea1e10df7636a8bde5928ee83f188fad8b2a817947661405595d977b
MD5 918f49e7f966b85d2449bc10c6a26c36
BLAKE2b-256 5a688590c8d99154c9b79be9c76961366f5e300dd28f2240e8eb7c79e8346892

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