Skip to content

Commit

Permalink
Merge branch 'master' into cottsay/feature-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed May 31, 2024
2 parents 360024c + 485f500 commit 6edd2b5
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 43 deletions.
6 changes: 4 additions & 2 deletions colcon_core/argument_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ def decorate_argument_parser(self, *, parser):
raise NotImplementedError()


def get_argument_parser_extensions():
def get_argument_parser_extensions(*, group_name=None):
"""
Get the available argument parser extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.ARGUMENT_PARSER_DECORATOR_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
5 changes: 0 additions & 5 deletions colcon_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def register_command_exit_handler(handler):
:param handler: The callable
"""
global _command_exit_handlers
if handler not in _command_exit_handlers:
_command_exit_handlers.append(handler)

Expand All @@ -114,7 +113,6 @@ def main(*, command_name='colcon', argv=None):
:param list argv: The list of arguments
:returns: The return code
"""
global _command_exit_handlers
try:
return _main(command_name=command_name, argv=argv)
except KeyboardInterrupt:
Expand All @@ -127,7 +125,6 @@ def main(*, command_name='colcon', argv=None):


def _main(*, command_name, argv):
global colcon_logger
# default log level, for searchability: COLCON_LOG_LEVEL
colcon_logger.setLevel(logging.WARNING)
set_logger_level_from_env(
Expand Down Expand Up @@ -391,8 +388,6 @@ def create_subparser(parser, cmd_name, verb_extensions, *, attribute):
selected verb
:returns: The special action object
"""
global colcon_logger

# list of available verbs with their descriptions
verbs = []
for name, extension in verb_extensions.items():
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ def create_environment_hooks(self, prefix_path, pkg_name):
raise NotImplementedError()


def get_environment_extensions():
def get_environment_extensions(*, group_name=None):
"""
Get the available environment extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name in list(extensions.keys()):
extension = extensions[name]
extension.ENVIRONMENT_NAME = name
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/event_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def __call__(self, event):
raise NotImplementedError()


def get_event_handler_extensions(*, context):
def get_event_handler_extensions(*, context, group_name=None):
"""
Get the available event handler extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.EVENT_HANDLER_NAME = name
extension.context = context
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _flush(self):
self._event_controller.flush()


def get_executor_extensions():
def get_executor_extensions(*, group_name=None):
"""
Get the available executor extensions.
Expand All @@ -206,7 +206,9 @@ def get_executor_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.EXECUTOR_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
4 changes: 3 additions & 1 deletion colcon_core/executor/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from colcon_core.executor import ExecutorExtensionPoint
from colcon_core.executor import OnError
from colcon_core.logging import colcon_logger
from colcon_core.logging import get_effective_console_level
from colcon_core.plugin_system import satisfies_version
from colcon_core.subprocess import new_event_loop
from colcon_core.subprocess import SIGINT_RESULT
Expand All @@ -32,7 +33,8 @@ def __init__(self): # noqa: D107
def execute(self, args, jobs, *, on_error=OnError.interrupt): # noqa: D102
# avoid debug message from asyncio when colcon uses debug log level
asyncio_logger = logging.getLogger('asyncio')
asyncio_logger.setLevel(logging.INFO)
log_level = get_effective_console_level(colcon_logger)
asyncio_logger.setLevel(log_level)

rc = 0
loop = new_event_loop()
Expand Down
27 changes: 22 additions & 5 deletions colcon_core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ def filter(self, record): # noqa: A003
if isinstance(handler, logging.StreamHandler):
formatter = handler.formatter
# filter colcon specific log messages from default stream handler
handler.addFilter(Filter(colcon_logger.name))
handler.addFilter(Filter(logger.name))

# add a stream handler replacing the one filtered on the root logger
handler = logging.StreamHandler()
if formatter:
# use same formatter as for stream handler
handler.setFormatter(formatter)
handler.setLevel(colcon_logger.getEffectiveLevel())
colcon_logger.addHandler(handler)
handler.setLevel(logger.getEffectiveLevel())
logger.addHandler(handler)

# add a file handler writing all log levels
handler = logging.FileHandler(str(path))
Expand All @@ -121,9 +121,26 @@ def format_message_with_relative_time(record):
# use same formatter as for stream handler
handler.setFormatter(formatter)
handler.setLevel(1)
colcon_logger.addHandler(handler)
logger.addHandler(handler)

# change the logger to handle all levels
colcon_logger.setLevel(1)
logger.setLevel(1)

return handler


def get_effective_console_level(logger):
"""
Determine the effective log level of to the console.
On a typical logger, this is the same as getEffectiveLevel(). After a call
to add_file_handler, this will continue to return the same level though
getEffectiveLevel() will now always return ``1``.
:param logger: The logger to inspect
:returns: the log level
"""
for handler in logger.handlers:
if isinstance(handler, logging.StreamHandler):
return handler.level
return logger.getEffectiveLevel()
6 changes: 4 additions & 2 deletions colcon_core/package_augmentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ def augment_package(
raise NotImplementedError()


def get_package_augmentation_extensions():
def get_package_augmentation_extensions(*, group_name=None):
"""
Get the available package augmentation extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_AUGMENTATION_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ def discover(self, *, args, identification_extensions):
raise NotImplementedError()


def get_package_discovery_extensions():
def get_package_discovery_extensions(*, group_name=None):
"""
Get the available package discovery extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_DISCOVERY_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_identification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def identify(self, desc: PackageDescriptor):
raise NotImplementedError()


def get_package_identification_extensions():
def get_package_identification_extensions(*, group_name=None):
"""
Get the available package identification extensions.
Expand All @@ -73,7 +73,9 @@ def get_package_identification_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_IDENTIFICATION_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_selection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ def add_arguments(parser):
_add_package_selection_arguments(parser)


def get_package_selection_extensions():
def get_package_selection_extensions(*, group_name=None):
"""
Get the available package selection extensions.
The extensions are ordered by their entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_SELECTION_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/prefix_path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def extend_prefix_path(self, paths):
raise NotImplementedError()


def get_prefix_path_extensions():
def get_prefix_path_extensions(*, group_name=None):
"""
Get the available prefix path extensions.
Expand All @@ -49,7 +49,9 @@ def get_prefix_path_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PREFIX_PATH_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
13 changes: 9 additions & 4 deletions colcon_core/shell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def generate_command_environment(
raise NotImplementedError()


def get_shell_extensions():
def get_shell_extensions(*, group_name=None):
"""
Get the available shell extensions.
Expand All @@ -282,7 +282,9 @@ def get_shell_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.SHELL_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down Expand Up @@ -593,7 +595,7 @@ def find_installed_packages(self, install_base: Path):
raise NotImplementedError()


def get_find_installed_packages_extensions():
def get_find_installed_packages_extensions(*, group_name=None):
"""
Get the available package identification extensions.
Expand All @@ -602,7 +604,10 @@ def get_find_installed_packages_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__ + '.find_installed_packages')
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(
group_name + '.find_installed_packages')
for name, extension in extensions.items():
extension.PACKAGE_IDENTIFICATION_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
6 changes: 3 additions & 3 deletions colcon_core/shell/template/prefix_util.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ FORMAT_STR_SET_ENV_VAR = '@(shell_extension.FORMAT_STR_SET_ENV_VAR)'
@{assert shell_extension.FORMAT_STR_USE_ENV_VAR is not None}@
FORMAT_STR_USE_ENV_VAR = '@(shell_extension.FORMAT_STR_USE_ENV_VAR)'
@{assert shell_extension.FORMAT_STR_INVOKE_SCRIPT is not None}@
FORMAT_STR_INVOKE_SCRIPT = '@(shell_extension.FORMAT_STR_INVOKE_SCRIPT)'
FORMAT_STR_REMOVE_LEADING_SEPARATOR = '@(shell_extension.FORMAT_STR_REMOVE_LEADING_SEPARATOR)'
FORMAT_STR_REMOVE_TRAILING_SEPARATOR = '@(shell_extension.FORMAT_STR_REMOVE_TRAILING_SEPARATOR)'
FORMAT_STR_INVOKE_SCRIPT = '@(shell_extension.FORMAT_STR_INVOKE_SCRIPT)' # noqa: E501
FORMAT_STR_REMOVE_LEADING_SEPARATOR = '@(shell_extension.FORMAT_STR_REMOVE_LEADING_SEPARATOR)' # noqa: E501
FORMAT_STR_REMOVE_TRAILING_SEPARATOR = '@(shell_extension.FORMAT_STR_REMOVE_TRAILING_SEPARATOR)' # noqa: E501

DSV_TYPE_APPEND_NON_DUPLICATE = 'append-non-duplicate'
DSV_TYPE_PREPEND_NON_DUPLICATE = 'prepend-non-duplicate'
Expand Down
3 changes: 3 additions & 0 deletions colcon_core/task/python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ async def build(self, *, additional_hooks=None): # noqa: D102
python_lib = os.path.join(
args.install_base, self._get_python_lib(args))
os.makedirs(python_lib, exist_ok=True)
distutils_commands = os.path.join(
os.path.dirname(__file__), 'colcon_distutils_commands')
# and being in the PYTHONPATH
env = dict(env)
env['PYTHONPATH'] = str(prefix_override) + os.pathsep + \
distutils_commands + os.pathsep + \
python_lib + os.pathsep + env.get('PYTHONPATH', '')
# coverage capture interferes with sitecustomize
# See also: https://docs.python.org/3/library/site.html#module-site
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Metadata-Version: 2.1
Name: colcon_distutils_commands
Version: 0.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[distutils.commands]
symlink_data = colcon_core.distutils.commands.symlink_data:symlink_data
7 changes: 4 additions & 3 deletions colcon_core/task/python/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ async def step(self):
raise NotImplementedError()


def get_python_testing_step_extensions():
def get_python_testing_step_extensions(*, group_name=None):
"""
Get the available Python testing step extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(
'colcon_core.python_testing', unique_instance=False)
if group_name is None:
group_name = 'colcon_core.python_testing'
extensions = instantiate_extensions(group_name, unique_instance=False)
for name in list(extensions.keys()):
extension = extensions[name]
extension.STEP_TYPE = name
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/verb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ def main(self, *, context):
raise NotImplementedError()


def get_verb_extensions():
def get_verb_extensions(*, group_name=None):
"""
Get the available verb extensions.
The extensions are ordered by their entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.VERB_NAME = name
return order_extensions_by_name(extensions)
Expand Down
Loading

0 comments on commit 6edd2b5

Please sign in to comment.