From 88b4755c489aecde5d8dfcbed9a5d2ee68d9fba1 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Sep 2020 14:20:15 +0900 Subject: [PATCH 1/2] fix #43: expander can handle pathsep --- expander.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/expander.py b/expander.py index 6af6f6d..77222f9 100755 --- a/expander.py +++ b/expander.py @@ -4,7 +4,7 @@ import sys import argparse from logging import Logger, basicConfig, getLogger -from os import getenv, environ +from os import getenv, environ, pathsep from pathlib import Path from typing import List, Set, Optional @@ -84,13 +84,14 @@ def expand(self, source: str) -> str: parser.add_argument('--lib', help='Path to Atcoder Library') opts = parser.parse_args() - lib_path = Path.cwd() + lib_paths = [] if opts.lib: - lib_path = Path(opts.lib) - elif 'CPLUS_INCLUDE_PATH' in environ: - lib_path = Path(environ['CPLUS_INCLUDE_PATH']) - - expander = Expander([lib_path]) + lib_paths.append(Path(opts.lib)) + if 'CPLUS_INCLUDE_PATH' in environ: + lib_paths.extend( + map(Path, filter(None, environ['CPLUS_INCLUDE_PATH'].split(pathsep)))) + lib_paths.append(Path.cwd()) + expander = Expander(lib_paths) source = open(opts.source).read() output = expander.expand(source) From d2e9598a5e7b45c0cbdfddfb3b5d86f3915b2582 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Sep 2020 14:24:59 +0900 Subject: [PATCH 2/2] refactor --- expander.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/expander.py b/expander.py index 77222f9..7173bed 100755 --- a/expander.py +++ b/expander.py @@ -18,11 +18,8 @@ class Expander: include_guard = re.compile('#.*ATCODER_[A-Z_]*_HPP') - def __init__(self, lib_paths: List[Path] = None): - if lib_paths: - self.lib_paths = lib_paths - else: - self.lib_paths = [Path.cwd()] + def __init__(self, lib_paths: List[Path]): + self.lib_paths = lib_paths included = set() # type: Set[str]