Giter Site home page Giter Site logo

bisectlib's Introduction

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'

bisectlib's People

Contributors

dependabot[bot] avatar pre-commit-ci[bot] avatar tandav avatar

Watchers

 avatar

bisectlib's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.