Skip to main content

bisectlib

array bisection algorithm helper

install

pip install bisectlib

usage

you should subclass from Bisect and implement 1 method is_bad or is_good. This method should return True/False which indicates is option good or bad. When instantiating your class you should provide a sequence of options to check. They should be sorted by is_bad. By default, left side of options are considered good options and on the right are bad ones. (You can change this by passing sort_order='bad-good' argument)

simple example

from bisectlib import Bisect

class FirstGreaterThan3(Bisect):
    def is_bad(self, op) -> bool:
        return op > 3

# or you can use is_good:
class FirstGreaterThan3(Bisect):
    def is_good(self, op) -> bool:
        return op <= 3

first_greater_than_3 = FirstGreaterThan3(options = (1, 2, 3, 4, 5, 6))
>>> first_greater_than_3.is_bad(2)
False

>>> first_greater_than_3.is_bad(5)
True

>>> first_greater_than_3()
4 start
4: BAD
2 start
2: GOOD
3 start
3: GOOD
====================================================================================================
first bad option is: 4
4

more complex example - find first bad version of poetry dependency

import subprocess
from bisectlib import Bisect

class FirstBadDependencyVersion(Bisect):
    def is_bad(self, op) -> bool:
        # kinda setup
        subprocess.check_call(f'git checkout HEAD -- poetry.lock pyproject.toml && poetry add "my_library=={op}"', shell=True)

        # check is_bad
        return bool(subprocess.run('make test', shell=True).returncode)

first_bad_dependency_version = FirstBadDependencyVersion(options='''\
v0.0.1
v0.0.2
v0.0.3
v0.1.0
v0.1.1
v0.1.2
v0.2.0
v0.2.1
'''.splitlines())
>>> first_bad_dependency_version()
v0.1.1 start
v0.1.1: GOOD
v0.2.0 start
v0.2.0: BAD
v0.1.2 start
v0.1.2: BAD
====================================================================================================
first bad option is: v0.1.2
'v0.1.2'

Download files

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

Source Distribution

bisectlib-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

bisectlib-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file bisectlib-0.1.0.tar.gz.

File metadata

  • Download URL: bisectlib-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for bisectlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a2e6d445d765500ab4a1e498d3cc6a3aaa09baf6b508c484e78c6f373052a2a6
MD5 af04dce3d440d163c63084b056a93231
BLAKE2b-256 eae7f6d1af5295a20c34abbd1e7d2889a21149e0b41cd31fcd8e249f2d3bf87d

See more details on using hashes here.

File details

Details for the file bisectlib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bisectlib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for bisectlib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e2e566edc9b5dd8df34baca5763168664503400534d9aa7b221c31d13525c6f
MD5 7aa529702689dcb604f1f65f1cbce2da
BLAKE2b-256 91591e8652b4bb997050bb43c58571e5aac809735e99a72b9d7484ffcd99271c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page