Skip to content

Commit

Permalink
main: Add TBOTPATH environment variable
Browse files Browse the repository at this point in the history
Signed-off-by: Rahix <hws@denx.de>
  • Loading branch information
Rahix committed Nov 28, 2018
1 parent 68b0c90 commit 3c92c8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,8 @@
## [Unreleased]
### Added
- `-C` parameter to allow setting a different working directory
- `${TBOTPATH}` environment variable to provide additional testcase
directories; `TBOTPATH` is a `:` separated list of directorie


## [0.6.3] - 2018-11-28
Expand Down
21 changes: 20 additions & 1 deletion tbot/loader.py
Expand Up @@ -33,20 +33,38 @@ def list_dir(


def get_file_list(
dirs: typing.Iterable[pathlib.Path], files: typing.Iterable[pathlib.Path]
env_dirs: typing.Iterable[pathlib.Path],
dirs: typing.Iterable[pathlib.Path],
files: typing.Iterable[pathlib.Path],
) -> typing.Generator[pathlib.Path, None, None]:
# Builtin testcases
builtins = pathlib.Path(__file__).parent / "tc" / "callable.py"
if builtins.is_file():
yield builtins

# tc.py file
tcpy = pathlib.Path.cwd() / "tc.py"
if tcpy.is_file():
yield tcpy

# tc/ folder
tcdir = pathlib.Path.cwd() / "tc"
if tcdir.is_dir():
for f in list_dir(tcdir):
yield f

# Paths from $TBOTPATH
for d in env_dirs:
if d.is_dir():
for f in list_dir(d, recurse=False):
yield f
else:
if d.exists():
raise NotADirectoryError(str(d))
else:
raise FileNotFoundError(str(d))

# Specified testcase folders
for d in dirs:
if d.is_dir():
for f in list_dir(d):
Expand All @@ -57,6 +75,7 @@ def get_file_list(
else:
raise FileNotFoundError(str(d))

# Specified testcase files
for f in files:
if f.is_file():
yield f
Expand Down
9 changes: 7 additions & 2 deletions tbot/main.py
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import sys
import os
import pathlib
import argparse
from tbot import __about__
Expand Down Expand Up @@ -98,8 +99,6 @@ def main() -> None: # noqa: C901
args = parser.parse_args()

if args.workdir:
import os

os.chdir(args.workdir)

from tbot import log
Expand Down Expand Up @@ -135,7 +134,13 @@ def main() -> None: # noqa: C901

from tbot import loader

if "TBOTPATH" in os.environ:
environ_paths = os.environ["TBOTPATH"].split(":")
else:
environ_paths = []

files = loader.get_file_list(
(pathlib.Path(d).resolve() for d in environ_paths),
(pathlib.Path(d).resolve() for d in args.tcdirs),
(pathlib.Path(f).resolve() for f in args.tcfiles),
)
Expand Down

0 comments on commit 3c92c8f

Please sign in to comment.