-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib_examples.py
executable file
·52 lines (38 loc) · 1.18 KB
/
lib_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
#
# Example invocations demonstrating lib/API interface
#
import sys
from src.marco.marco import parse_args, enumerate_with_args
def example1():
# Example 1:
# Basic usage, specifying arguments and receiving results as printable strings
print("Example 1")
args_list = ['tests/test1.cnf', '--threads', '4']
args_list.extend(sys.argv[1:])
args = parse_args(args_list)
for result in enumerate_with_args(args, print_results=True):
print(result)
def example2():
# Example 2:
# Filter results by type, end early based on a specific condition.
# Receive results as tuples.
print("Example 2")
results = []
args_list = ['tests/c10.cnf']
args_list.extend(sys.argv[1:])
args = parse_args(args_list)
# generator can be saved in a variable to call .close() later
gen = enumerate_with_args(args)
for result in gen:
if result[0] == 'U':
results.append(result)
if len(results) >= 2:
# gen.close() will end the enumeration early and clean up
gen.close()
print(results)
def main():
example1()
example2()
if __name__ == '__main__':
main()