def test_config_init(): """Config is reading from configuration""" config_path = pyblish.lib.main_package_path() config_path = os.path.join(config_path, 'config.yaml') with open(config_path) as f: manual_config = yaml.load(f) for key in manual_config: assert key in config
def test_config(): """Config works as expected""" config = pyblish.backend.config config_path = pyblish.backend.lib.main_package_path() config_path = os.path.join(config_path, 'backend', 'config.yaml') with open(config_path) as f: manual_config = yaml.load(f) variable = 'paths_environment_variable' assert manual_config.get(variable) == getattr(config, variable)
def test_config(): """Config works as expected""" config = pyblish.backend.config config_path = pyblish.backend.lib.main_package_path() config_path = os.path.join(config_path, "backend", "config.yaml") with open(config_path) as f: manual_config = yaml.load(f) variable = "paths_environment_variable" assert manual_config.get(variable) == getattr(config, variable)
def _load_data(context): """Inject context with user-supplied data""" try: with open(DATA_PATH) as f: data = yaml.load(f) for key, value in data.iteritems(): context.set_data(key, value) return True except IOError: pass return False
def test_user_config(): """User config augments default config""" config = pyblish.Config() user_config_path = config['USERCONFIGPATH'] with open(user_config_path, 'w') as f: yaml.dump({'test_variable': 'test_value'}, f) config.reset() with open(user_config_path, 'r') as f: user_config = yaml.load(f) assert user_config for key in user_config: assert key in config
def _load_config(): """Augment configuration with user-supplied config.yaml""" try: with open(CONFIG_PATH) as f: config = yaml.load(f) if config is not None: pyblish.api.config.update(config) return True except IOError: pass except pyblish.vendor.yaml.scanner.ScannerError: raise return False
def test_user_config(): """User config augments default config""" user_config_path = pyblish.backend.config.USERCONFIGPATH remove_config_file = False try: if not os.path.isfile(user_config_path): remove_config_file = True with open(user_config_path, 'w') as f: yaml.dump({'test_variable': 'test_value'}, f) # Force a reload of configuration _reload_config() with open(user_config_path, 'r') as f: user_config = yaml.load(f) assert user_config for variable in user_config: assert getattr(pyblish.backend.config, variable, None) finally: if remove_config_file: os.remove(user_config_path)
def test_user_config(): """User config augments default config""" user_config_path = pyblish.backend.config.USERCONFIGPATH remove_config_file = False try: if not os.path.isfile(user_config_path): remove_config_file = True with open(user_config_path, "w") as f: yaml.dump({"test_variable": "test_value"}, f) # Force a reload of configuration _reload_config() with open(user_config_path, "r") as f: user_config = yaml.load(f) assert user_config for variable in user_config: assert getattr(pyblish.backend.config, variable, None) finally: if remove_config_file: os.remove(user_config_path)
def main(ctx, verbose, version, paths, plugins, environment_paths, configured_paths, registered_paths, plugin_paths, add_plugin_paths, config, data, logging_level): """Pyblish command-line interface Use the appropriate sub-command to initiate a publish. Use the --help flag of each subcommand to learn more about what it can do. \b Usage: $ pyblish publish --help $ pyblish test --help """ global _ctx _ctx = ctx level = LOG_LEVEL[logging_level] log.setLevel(level) # Process top-level arguments if version: click.echo("pyblish version %s" % pyblish.__version__) # Respond to sub-commands if not ctx.obj: ctx.obj = dict() # Initialise context with data passed as argument context = pyblish.api.Context() ctx.obj["context"] = context for key, value in data: try: yaml_loaded = yaml.load(value) except Exception as err: log.error("Error: Data must be YAML formatted: " "--data %s %s" % (key, value)) ctx.obj["error"] = err else: context.set_data(str(key), yaml_loaded) # Load user data data_loaded = _load_data(context) config_loaded = _load_config() if not plugin_paths: plugin_paths = pyblish.api.plugin_paths() plugin_paths += add_plugin_paths ctx.obj["plugin_paths"] = plugin_paths available_plugins = pyblish.api.discover(paths=plugin_paths) if plugins: click.echo(_format_plugins(available_plugins)) if verbose: click.echo( intro_message.format( version=pyblish.__version__, config_path=CONFIG_PATH if config_loaded else "None", data_path=DATA_PATH if data_loaded else "None", paths=_format_paths(plugin_paths), plugins=_format_plugins(available_plugins)) ) # Visualise available paths if any([paths, environment_paths, registered_paths, configured_paths]): _paths = list() if paths: environment_paths = True registered_paths = True configured_paths = True for path in plugin_paths: # Determine the source of each path _typ = "custom" if path in pyblish.api.environment_paths(): _typ = "environment" elif path in pyblish.api.registered_paths(): _typ = "registered" elif path in pyblish.api.configured_paths(): _typ = "configured" # Only display queried paths if _typ == "environment" and not environment_paths: continue if _typ == "configured" and not configured_paths: continue if _typ == "registered" and not registered_paths: continue click.echo(PATH_TEMPLATE.format( path=path, typ=_typ)) _paths.append(path) # Pass data to sub-commands ctx.obj["verbose"] = verbose ctx.obj["plugin_paths"] = plugin_paths
_help = yaml.load(""" config: > Absolute path to custom configuration file. add-config: > Absolute path to configuration file to use in augmenting the existing configuration. plugin-path: > Replace all normally discovered paths with this This may be called multiple times. add-plugin-path: > Append to normally discovered paths. logging-level: > Specify with which level to produce logging messages. A value lower than the default "warning" will produce more messages. This can be useful for debugging. data: > Initialise context with data. This takes two arguments, key and value. verbose: > Display detailed information. Useful for debugging purposes. version: > Print the current version of Pyblish paths: > List all available paths plugins: > List all available plugins registered-paths: > Print only registered-paths environment-paths: > Print only paths added via environment configured-paths: > Print only paths added via configuration """)
import logging from pyblish.vendor import yaml log = logging.getLogger('pyblish.backend.config') # Look for configuration in users HOME home_dir = os.path.expanduser('~') package_dir = os.path.dirname(__file__) user_config_path = os.path.join(home_dir, '.pyblish') default_config_path = os.path.join(package_dir, 'config.yaml') with open(default_config_path, 'r') as f: config_dict = yaml.load(f) # Update configuration with user-configuration if os.path.isfile(user_config_path): try: with open(user_config_path, 'r') as f: config_dict.update(yaml.load(f)) except: log.warning("Could not read user configuration @ {0}".format( user_config_path)) # Append to config_dict config_dict['USERCONFIGPATH'] = user_config_path config_dict['DEFAULTCONFIGPATH'] = default_config_path # Wrap config up in a class, so that we may access
def main(ctx, verbose, version, paths, plugins, environment_paths, configured_paths, registered_paths, plugin_paths, add_plugin_paths, config, data, logging_level): """Pyblish command-line interface Use the appropriate sub-command to initiate a publish. Use the --help flag of each subcommand to learn more about what it can do. \b Usage: $ pyblish publish --help $ pyblish test --help """ global _ctx _ctx = ctx level = LOG_LEVEL[logging_level] log.setLevel(level) # Process top-level arguments if version: click.echo("pyblish version %s" % pyblish.__version__) # Respond to sub-commands if not ctx.obj: ctx.obj = dict() # Initialise context with data passed as argument context = pyblish.api.Context() ctx.obj["context"] = context for key, value in data: try: yaml_loaded = yaml.load(value) except Exception as err: log.error("Error: Data must be YAML formatted: " "--data %s %s" % (key, value)) ctx.obj["error"] = err else: context.set_data(str(key), yaml_loaded) # Load user data data_loaded = _load_data(context) config_loaded = _load_config() if not plugin_paths: plugin_paths = pyblish.api.plugin_paths() plugin_paths += add_plugin_paths ctx.obj["plugin_paths"] = plugin_paths available_plugins = pyblish.api.discover(paths=plugin_paths) if plugins: click.echo(_format_plugins(available_plugins)) if verbose: click.echo( intro_message.format( version=pyblish.__version__, config_path=CONFIG_PATH if config_loaded else "None", data_path=DATA_PATH if data_loaded else "None", paths=_format_paths(plugin_paths), plugins=_format_plugins(available_plugins))) # Visualise available paths if any([paths, environment_paths, registered_paths, configured_paths]): _paths = list() if paths: environment_paths = True registered_paths = True configured_paths = True for path in plugin_paths: # Determine the source of each path _typ = "custom" if path in pyblish.api.environment_paths(): _typ = "environment" elif path in pyblish.api.registered_paths(): _typ = "registered" elif path in pyblish.api.configured_paths(): _typ = "configured" # Only display queried paths if _typ == "environment" and not environment_paths: continue if _typ == "configured" and not configured_paths: continue if _typ == "registered" and not registered_paths: continue click.echo(PATH_TEMPLATE.format(path=path, typ=_typ)) _paths.append(path) # Pass data to sub-commands ctx.obj["verbose"] = verbose ctx.obj["plugin_paths"] = plugin_paths
import logging import pyblish.api import pyblish.lib import pyblish.util import pyblish.plugin import pyblish.version from pyblish.vendor import yaml from pyblish.vendor import click # Current Click context _ctx = None with open(os.path.join(os.path.dirname(__file__), "_help.yaml")) as f: _help = yaml.load(f) def _setup_log(root="pyblish"): log = logging.getLogger(root) log.setLevel(logging.INFO) return log log = _setup_log() main_log = pyblish.lib.setup_log(level=logging.ERROR) # Constants CONFIG_PATH = "config.yaml" DATA_PATH = "data.yaml" PATH_TEMPLATE = "{path} <{typ}>"
import logging from pyblish.vendor import yaml log = logging.getLogger("pyblish.backend.config") # Look for configuration in users HOME home_dir = os.path.expanduser("~") package_dir = os.path.dirname(__file__) user_config_path = os.path.join(home_dir, ".pyblish") default_config_path = os.path.join(package_dir, "config.yaml") with open(default_config_path, "r") as f: config_dict = yaml.load(f) # Update configuration with user-configuration if os.path.isfile(user_config_path): try: with open(user_config_path, "r") as f: config_dict.update(yaml.load(f)) except: log.warning("Could not read user configuration @ {0}".format(user_config_path)) # Append to config_dict config_dict["USERCONFIGPATH"] = user_config_path config_dict["DEFAULTCONFIGPATH"] = default_config_path # Wrap config up in a class, so that we may access # members directly, using dot-notation.