def cli_profile_show(opt, profile: str) -> None: """Show a profile configuration.""" conf = Configuration(profile) if conf.current_profile is None: raise ConfigurationError("no default profile is configured") data = conf.read(conf.current_profile) print(data)
def cli_profile_default(opt, profile: str) -> None: """Show or set the default profile.""" conf = Configuration(profile) if profile is None: if conf.default_profile is not None: print(conf.default_profile) elif opt.verbose: print("Note: no default profile is configured") else: # Set default to provided value, which must exist already conf.set_default(profile)
def cli_profile_list(opt) -> None: """List all available profiles.""" conf = Configuration() for profile in conf.all_profiles: if opt.verbose: if profile == conf.default_profile: print("*", profile) else: print(" ", profile) else: print(profile)
def cli_profile_add(opt, profile: str, conanfile: str, force: bool = False, default: bool = False) -> None: """Add a new profile.""" conf = Configuration() conf.add(profile, conanfile, force=force) if default: conf.set_default(profile)
def cli_shell( opt, profile: str, profile_path: str, preserve_env: bool, conan_option: List[str], cache: bool, ) -> None: """Launch shell with the correct environment from a profile.""" deny_profile_and_path(profile, profile_path) conf = Configuration(profile) engine = Engine(conf, conanfile=profile_path) engine.preserve_env = preserve_env engine.conan_options = conan_option # Replace process with shell. engine.shell(use_cache=cache)
def cli_activate( opt, profile: str, profile_path: str, conan_arg: List[str], conan_option: List[str], conan_setting: List[str], cache: bool, ) -> None: """Launch shell with the correct environment from a profile. You can then source or evaluate these commands to activate the environment: \b 1. source <(cloe-launch activate [options]) 2. eval $(cloe-launch activate [options]) If you plan on putting this in your shell, it is /strongly/ recommended to copy the output into your shell or put it in an intermediate file instead of calling cloe-launch directly at every new shell invocation! \b 3. cloe-launch activate > ~/.config/cloe/launcher/activate.sh echo "source ~/.config/cloe/launcher/activate.sh" >> ~/.bashrc \b Warnings: - If you use method #3 and delete ~/.cache/cloe, you will get errors until you re-create the profile. - Deleting or overwriting packages in your Conan cache that are used in an activated environment is undefined behavior: it can lead to unexpected problems! - Using cloe shell in combination with cloe activate is undefined behavior: it can lead to unexpected problems. """ options.deny_profile_and_path(profile, profile_path) conf = Configuration(profile) engine = Engine(conf, conanfile=profile_path) engine.conan_args = conan_arg engine.conan_options = conan_option engine.conan_settings = conan_setting # Replace process with shell. engine.activate(use_cache=cache)
def profile_option(required: bool = False, help="Profile to select, default if absent."): conf = Configuration() def complete(ctx, args, incomplete): profiles = [] for k in conf.all_profiles: if k not in args: profiles.append(k) return [k for k in profiles if incomplete in k] return click.option( "-p", "--profile", envvar="CLOE_PROFILE", required=required, type=click.STRING, help=help, autocompletion=complete, )
def cli_exec( opt, engine_args: List[str], profile: str, profile_path: str, conan_arg: List[str], conan_option: List[str], conan_setting: List[str], preserve_env: bool, override_env: List[str], cache: bool, debug: bool, ) -> None: """Launch cloe-engine with a profile. ENGINE_ARGS are passed on to cloe-engine. """ options.deny_profile_and_path(profile, profile_path) conf = Configuration(profile) engine = Engine(conf, conanfile=profile_path) engine.conan_args = conan_arg engine.conan_options = conan_option engine.conan_settings = conan_setting engine.preserve_env = preserve_env # Prepare environment overrides: overrides = {} for line in override_env: kv = line.split("=", 1) if len(kv) == 1: kv.append(os.getenv(kv[0], "")) overrides[kv[0]] = kv[1] # Run cloe-engine and pass on returncode: # If cloe-engine is killed/aborted, subprocess will return 250. result = engine.exec(engine_args, use_cache=cache, debug=debug, override_env=overrides) sys.exit(result.returncode)
def cli_profile_remove(opt, profile: str) -> None: """Remove a profile.""" conf = Configuration() conf.remove(profile)
def cli_profile_edit(opt, profile: str, editor: str, create: bool) -> None: """Edit a profile.""" conf = Configuration(profile) if conf.current_profile is None: raise ConfigurationError("no default profile is configured") conf.edit(conf.current_profile, create)
def cli_clean(opt, profile: str, profile_path: str) -> None: """Clean launcher profile cache.""" options.deny_profile_and_path(profile, profile_path) conf = Configuration(profile) engine = Engine(conf, conanfile=profile_path) engine.clean()