Python.py (scons-4.2.0) | : | Python.py (SCons-4.3.0) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
PYTHONPATH. To do otherwise would have required code to determine where the | PYTHONPATH. To do otherwise would have required code to determine where the | |||
Python installation is, which is outside of the scope of a scanner like this. | Python installation is, which is outside of the scope of a scanner like this. | |||
If consumers want to pick up dependencies upon these packages, they must put | If consumers want to pick up dependencies upon these packages, they must put | |||
those directories in PYTHONPATH. | those directories in PYTHONPATH. | |||
""" | """ | |||
import itertools | import itertools | |||
import os | import os | |||
import re | import re | |||
import SCons.Scanner | ||||
import SCons.Node.FS | ||||
import SCons.Util | ||||
from . import ScannerBase | ||||
# Capture python "from a import b" and "import a" statements. | # Capture python "from a import b" and "import a" statements. | |||
from_cre = re.compile(r'^\s*from\s+([^\s]+)\s+import\s+(.*)', re.M) | from_cre = re.compile(r'^\s*from\s+([^\s]+)\s+import\s+(.*)', re.M) | |||
import_cre = re.compile(r'^\s*import\s+([^\s]+)', re.M) | import_cre = re.compile(r'^\s*import\s+([^\s]+)', re.M) | |||
def path_function(env, dir=None, target=None, source=None, argument=None): | def path_function(env, dir=None, target=None, source=None, argument=None): | |||
"""Retrieves a tuple with all search paths.""" | """Retrieves a tuple with all search paths.""" | |||
paths = env['ENV'].get('PYTHONPATH', '').split(os.pathsep) | paths = env['ENV'].get('PYTHONPATH', '').split(os.pathsep) | |||
if source: | if source: | |||
paths.append(source[0].dir.abspath) | paths.append(source[0].dir.abspath) | |||
skipping to change at line 196 | skipping to change at line 199 | |||
import_dirs = module_components | import_dirs = module_components | |||
for i in range(len(import_dirs)): | for i in range(len(import_dirs)): | |||
init_path = '/'.join(import_dirs[:i+1] + ['__init__.py']) | init_path = '/'.join(import_dirs[:i+1] + ['__init__.py']) | |||
init_node = SCons.Node.FS.find_file(init_path, [hit_dir]) | init_node = SCons.Node.FS.find_file(init_path, [hit_dir]) | |||
if init_node and init_node not in nodes: | if init_node and init_node not in nodes: | |||
nodes.append(init_node) | nodes.append(init_node) | |||
return sorted(nodes) | return sorted(nodes) | |||
PythonSuffixes = ['.py'] | PythonSuffixes = ['.py'] | |||
PythonScanner = SCons.Scanner.Base(scan, name='PythonScanner', | PythonScanner = ScannerBase( | |||
skeys=PythonSuffixes, | scan, | |||
path_function=path_function, recursive=1) | name='PythonScanner', | |||
skeys=PythonSuffixes, | ||||
path_function=path_function, | ||||
recursive=True, | ||||
) | ||||
# Local Variables: | # Local Variables: | |||
# tab-width:4 | # tab-width:4 | |||
# indent-tabs-mode:nil | # indent-tabs-mode:nil | |||
# End: | # End: | |||
# vim: set expandtab tabstop=4 shiftwidth=4: | # vim: set expandtab tabstop=4 shiftwidth=4: | |||
End of changes. 2 change blocks. | ||||
4 lines changed or deleted | 11 lines changed or added |