tool like `git bisect run` but checks arbitrary options and not uses git to switch versions
Project description
bisect_find_first_bad
git bisect run
can only search through commits.
This search don't use git to switch versions. You can check arbitrary options for is_bad
.
install
pip install bisect-find-first-bad
usage
you should subclass from BisectFindFirstBad
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
. Left side of options are good options and on the right are bad ones.
simple example
from bisect_find_first_bad import BisectFindFirstBad
class FirstGreaterThan3(BisectFindFirstBad):
def is_bad(self, op) -> bool:
return op > 3
# or you can use is_good:
class FirstGreaterThan3(BisectFindFirstBad):
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 bisect_find_first_bad import BisectFindFirstBad
class FirstBadDependencyVersion(BisectFindFirstBad):
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'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for bisect_find_first_bad-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dff034516850f22fecbcaca2d6dc1526f46fa65387908d5febf04249dbfa0ac |
|
MD5 | 561e89ce88256156dc150234d68b1870 |
|
BLAKE2b-256 | 31832f68ca887da3fb58f66b9922e806549da0efbf2ada3ca9c05fe0682add9b |
Close
Hashes for bisect_find_first_bad-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1355ea94eee66e89dace56832ba15cf5ddf3d8d71d4aee2ff3146e17e3d0f66c |
|
MD5 | b703ca56ebb5985c2c0af84f3f291765 |
|
BLAKE2b-256 | ecd9e6ba0924fdf6d6de5b5e7fc93e6d597dcc41362235cfc34bef090b45fa48 |