Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function to set up standard module paths #25326

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tools/chapel-py/src/chapel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ def each_matching(node, pattern, iterator=preorder):
yield (child, variables)


def files_with_contexts(files):
def files_with_contexts(
files, setup: Optional[typing.Callable[[Context], None]] = None
):
"""
Some files might have the same name, which Dyno really doesn't like.
Stratify files into "buckets"; within each bucket, all filenames are
unique. Between each bucket, re-create the Dyno context to avoid giving
it conflicting files.

For each newly-created context, call the setup function with it.

Yields files from the argument, as well as the context created for them.
"""

Expand All @@ -354,10 +358,29 @@ def files_with_contexts(files):
ctx = Context()
to_yield = buckets[bucket]

if setup:
setup(ctx)

for filename in to_yield:
yield (filename, ctx)


def files_with_stdlib_contexts(
files, setup: Optional[typing.Callable[[Context], None]] = None
):
"""
Like files_with_contexts, but also includes the standard library in the
context.
"""

def setup_with_stdlib(ctx):
ctx.set_module_paths([], [])
if setup:
setup(ctx)

yield from files_with_contexts(files, setup_with_stdlib)


def range_to_tokens(
rng: Location, lines: List[str]
) -> List[typing.Tuple[int, int, int]]:
Expand Down
Loading