def _extract_packages(pearl_env: PearlEnvironment, command: PearlCommand, args) -> List[Package]: try: return [ pearl_env.lookup_package(package_name) for package_name in args.packages ] except (RepoDoesNotExistError, PackageNotInRepoError): if command != PearlCommand.REMOVE: raise if args.force: # The user can still be able to remove a package even if package does not exist in any repository. return [ pearl_env.infer_package(package_name) for package_name in args.packages ] else: messenger.info("To remove the package, use option --force.") raise
def test_infer_package(tmp_path): home_dir = create_pearl_home(tmp_path) (home_dir / 'packages').mkdir(parents=True) pearl_env = PearlEnvironment(home_dir, env_initialized=False) with pytest.raises(PackageNotInstalledError): pearl_env.infer_package('repo-test/pkg-test') with pytest.raises(PackageNotInstalledError): pearl_env.infer_package('pkg-test') (home_dir / 'packages/repo-test/pkg-test').mkdir(parents=True) actual_package = pearl_env.infer_package('repo-test/pkg-test') assert actual_package.full_name == 'repo-test/pkg-test' actual_package = pearl_env.infer_package('pkg-test') assert actual_package.full_name == 'repo-test/pkg-test'