def discover_manifest(module, global_config): """Discover all session functions in the noxfile module. Args: module (module): The Noxfile module. global_config (~nox.main.GlobalConfig): The global configuration. Returns: ~.Manifest: A manifest of session functions. """ # Find any function added to the session registry (meaning it was # decorated with @nox.session); do not sort these, as they are being # sorted by decorator call time. functions = registry.get() # Find any function conforming to the session_* naming convention. # Sort these in alphabetical order. for name in sorted(six.iterkeys(module.__dict__)): obj = module.__dict__[name] if name.startswith('session_') and inspect.isfunction(obj): session_name = name.split('session_', 1).pop() functions[session_name] = obj # Return the final dictionary of session functions. return Manifest(functions, global_config)
def test_session_decorator(cleanup_registry): # Establish that the use of the session decorator will cause the # function to be found in the registry. @registry.session_decorator def unit_tests(session): pass answer = registry.get() assert 'unit_tests' in answer assert answer['unit_tests'] is unit_tests
def test_session_decorator_name(cleanup_registry, name): @registry.session_decorator(name=name) def unit_tests(session): pass answer = registry.get() assert "unit_tests" not in answer assert name in answer assert answer[name] is unit_tests assert unit_tests.python is None
def test_session_decorator(cleanup_registry): # Establish that the use of the session decorator will cause the # function to be found in the registry. @registry.session_decorator def unit_tests(session): pass answer = registry.get() assert "unit_tests" in answer assert answer["unit_tests"] is unit_tests assert unit_tests.python is None
def test_get(cleanup_registry): # Establish that the get method returns a copy of the registry. empty = registry.get() assert empty == registry._REGISTRY assert empty is not registry._REGISTRY assert len(empty) == 0 @registry.session_decorator def unit_tests(session): pass @registry.session_decorator def system_tests(session): pass full = registry.get() assert empty != full assert len(empty) == 0 assert len(full) == 2 assert full == registry._REGISTRY assert full is not registry._REGISTRY assert full['unit_tests'] is unit_tests assert full['system_tests'] is system_tests
def test_get(cleanup_registry): # Establish that the get method returns a copy of the registry. empty = registry.get() assert empty == registry._REGISTRY assert empty is not registry._REGISTRY assert len(empty) == 0 @registry.session_decorator def unit_tests(session): pass @registry.session_decorator def system_tests(session): pass full = registry.get() assert empty != full assert len(empty) == 0 assert len(full) == 2 assert full == registry._REGISTRY assert full is not registry._REGISTRY assert full["unit_tests"] is unit_tests assert full["system_tests"] is system_tests
def discover_manifest(module, global_config): """Discover all session functions in the noxfile module. Args: module (module): The Noxfile module. global_config (~nox.main.GlobalConfig): The global configuration. Returns: ~.Manifest: A manifest of session functions. """ # Find any function added to the session registry (meaning it was # decorated with @nox.session); do not sort these, as they are being # sorted by decorator call time. functions = registry.get() # Return the final dictionary of session functions. return Manifest(functions, global_config)
def discover_manifest(module, global_config): """Discover all session functions in the noxfile module. Args: module (module): The Noxfile module. global_config (~nox.main.GlobalConfig): The global configuration. Returns: ~.Manifest: A manifest of session functions. """ # Find any function added to the session registry (meaning it was # decorated with @nox.session); do not sort these, as they are being # sorted by decorator call time. functions = registry.get() # Return the final dictionary of session functions. return Manifest(functions, global_config)
def discover_session_functions(module): """Discover all session functions in the noxfile module.""" # Find any function added to the session registry (meaning it was # decorated with @nox.session); do not sort these, as they are being # sorted by decorator call time. funcs = registry.get() # Find any function conforming to the session_* naming convention. # Sort these in alphabetical order. for name in sorted(iterkeys(module.__dict__)): obj = module.__dict__[name] if name.startswith('session_') and isfunction(obj): session_name = name.split('session_', 1).pop() funcs[session_name] = obj # Return the final dictionary of session functions. return funcs
def discover_manifest(module: types.ModuleType | int, global_config: Namespace) -> Manifest: """Discover all session functions in the Noxfile module. Args: module (module): The Noxfile module. global_config (~nox.main.GlobalConfig): The global configuration. Returns: ~.Manifest: A manifest of session functions. """ # Find any function added to the session registry (meaning it was # decorated with @nox.session); do not sort these, as they are being # sorted by decorator call time. functions = registry.get() # Get the docstring from the Noxfile module_docstring = module.__doc__ # Return the final dictionary of session functions. return Manifest(functions, global_config, module_docstring)
import importlib.util import json import sys from argparse import Namespace from nox import manifest, registry spec = importlib.util.spec_from_file_location("Noxfile", sys.argv[1]) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) manifest_obj = manifest.Manifest( registry.get(), Namespace( force_venv_backend=False, default_venv_backend="virtualenv", extra_pythons=[], posargs=[], ), ) if sys.argv[2]: manifest_obj.filter_by_keywords(sys.argv[2]) session_list = [ session.friendly_name for (session, selected) in manifest_obj.list_all_sessions() if selected ] print(f"::set-output name=matrix::{json.dumps(session_list)}")