Skip to content

Commit 160d52a

Browse files
authored
Merge pull request #49 from atcoder/patch/issue43
fix #43: expander can handle pathsep
2 parents 9ee1f41 + d2e9598 commit 160d52a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

expander.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import argparse
66
from logging import Logger, basicConfig, getLogger
7-
from os import getenv, environ
7+
from os import getenv, environ, pathsep
88
from pathlib import Path
99
from typing import List, Set, Optional
1010

@@ -18,11 +18,8 @@ class Expander:
1818

1919
include_guard = re.compile('#.*ATCODER_[A-Z_]*_HPP')
2020

21-
def __init__(self, lib_paths: List[Path] = None):
22-
if lib_paths:
23-
self.lib_paths = lib_paths
24-
else:
25-
self.lib_paths = [Path.cwd()]
21+
def __init__(self, lib_paths: List[Path]):
22+
self.lib_paths = lib_paths
2623

2724
included = set() # type: Set[str]
2825

@@ -84,13 +81,14 @@ def expand(self, source: str) -> str:
8481
parser.add_argument('--lib', help='Path to Atcoder Library')
8582
opts = parser.parse_args()
8683

87-
lib_path = Path.cwd()
84+
lib_paths = []
8885
if opts.lib:
89-
lib_path = Path(opts.lib)
90-
elif 'CPLUS_INCLUDE_PATH' in environ:
91-
lib_path = Path(environ['CPLUS_INCLUDE_PATH'])
92-
93-
expander = Expander([lib_path])
86+
lib_paths.append(Path(opts.lib))
87+
if 'CPLUS_INCLUDE_PATH' in environ:
88+
lib_paths.extend(
89+
map(Path, filter(None, environ['CPLUS_INCLUDE_PATH'].split(pathsep))))
90+
lib_paths.append(Path.cwd())
91+
expander = Expander(lib_paths)
9492
source = open(opts.source).read()
9593
output = expander.expand(source)
9694

0 commit comments

Comments
 (0)