avoid try except
@@ -9,26 +9,16 @@ def test_build_dependencies(en_vocab):
# check requirements.txt
req_dict = {}
- try:
- # for CLI usage
- root_dir = Path(__file__).parent.parent
- req_file = root_dir / "requirements.txt"
- with req_file.open() as f:
- lines = f.readlines()
- except FileNotFoundError as e:
- try:
- # for local usage
- root_dir = Path(__file__).parent.parent.parent
- req_file = root_dir / "requirements.txt"
- with req_file.open() as f:
- lines = f.readlines()
- except FileNotFoundError as e:
- # where areth thou ?
- root_dir = Path(__file__).parent.parent.parent.parent
+
+ root_dir = None
+ # when running tests locally, the file is 3 levels up. On the CI, it's 2 levels up.
+ roots = [Path(__file__).parent.parent, Path(__file__).parent.parent.parent] # or whatever
+ for r in roots:
req_file = root_dir / "requirements.txt"
+ if req_file.exists():
+ root_dir = r
with req_file.open() as f:
lines = f.readlines()
-
for line in lines:
line = line.strip()
if not line.startswith("#"):
