-
Notifications
You must be signed in to change notification settings - Fork 2
/
bundle.py
executable file
·39 lines (29 loc) · 1.35 KB
/
bundle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# This script will bundle wren-test into a single `module.wren` file which can
# be included in your project. This is done to work around the Wren module
# system which currently doesn't handle deeply nested imports very well.
import fnmatch
import os
# Directory which contains this script.
scriptRoot = os.path.dirname(os.path.realpath(__file__))
# Top-level wren-test directory.
wrenTestRoot = os.path.abspath(os.path.join(scriptRoot, ".."))
# Path to the "src" directory in wren-test.
sourcesDirectory = os.path.join(wrenTestRoot, "src")
# Get all Wren source files in the "src" directory.
sources = [os.path.join(dirpath, path)
for (dirpath, _, files) in os.walk(sourcesDirectory)
for path in fnmatch.filter(files, '*.wren')]
# Workaround for https://github.com/munificent/wren/issues/246.
a = sources.index(sourcesDirectory + '/matchers.wren')
b = len(sources) - 1
sources[b], sources[a] = sources[a], sources[b]
# List of all source lines to be written to module file.
sourceLines = []
# Iterate over every source file to add necessary lines.
for source in sources:
with open(source, 'r') as sourceFile:
linesToAdd = [l for l in sourceFile if not l.startswith("import")]
sourceLines.extend(linesToAdd)
with open(os.path.join(wrenTestRoot, "module.wren"), 'w') as moduleFile:
moduleFile.writelines(sourceLines)