From 783da088eac9429852b48af38e32c4e219a95d57 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Sun, 23 Feb 2020 16:21:21 +0100 Subject: [PATCH] avoid try except --- spacy/tests/test_requirements.py | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/spacy/tests/test_requirements.py b/spacy/tests/test_requirements.py index 23ba792df..644e6f8f9 100644 --- a/spacy/tests/test_requirements.py +++ b/spacy/tests/test_requirements.py @@ -9,32 +9,22 @@ 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 - req_file = root_dir / "requirements.txt" - with req_file.open() as f: - lines = f.readlines() - for line in lines: - line = line.strip() - if not line.startswith("#"): - lib, v = _parse_req(line) - if lib and lib not in libs_ignore_requirements: - req_dict[lib] = v + 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("#"): + lib, v = _parse_req(line) + if lib and lib not in libs_ignore_requirements: + req_dict[lib] = v # check setup.cfg and compare to requirements.txt # also fails when there are missing or additional libs