File: entry_point_context.py

package info (click to toggle)
ros2-colcon-core 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,156 kB
  • sloc: python: 10,333; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 795 bytes parent folder | download
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
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0

from colcon_core import plugin_system


class EntryPointContext:

    def __init__(self, **kwargs):
        self._kwargs = kwargs
        self._memento = None

    def __enter__(self):
        # reset entry point cache, provide new instances in each scope
        plugin_system._extension_instances.clear()

        self._memento = plugin_system.load_entry_points

        def load_entry_points(_, *, exclude_names=None):
            return {
                k: v for k, v in self._kwargs.items()
                if exclude_names is None or k not in exclude_names}

        plugin_system.load_entry_points = load_entry_points

    def __exit__(self, *_):
        plugin_system.load_entry_points = self._memento