def find_best_candidate( self, package_name: str, target_package_version: Union[str, None] = None) -> Union[Package, bool]: """ Given a package name and optional version, returns the latest Package that matches """ if target_package_version: constraint = self._parser.parse_constraints(target_package_version) else: constraint = None candidates = self._pool.find_packages(package_name, constraint) if not candidates: return False # Select highest version if we have many package = candidates[0] for candidate in candidates: # Select highest version of the two if less_than(package.version, candidate.version): package = candidate return package
def find_best_candidate( self, package_name, # type: str target_package_version=None, # type: Union[str, None] allow_prereleases=False # type: bool ): # type: (...) -> Union[Package, bool] """ Given a package name and optional version, returns the latest Package that matches """ if target_package_version: constraint = self._parser.parse_constraints(target_package_version) else: constraint = None candidates = self._pool.find_packages(package_name, constraint) if not candidates: return False # Select highest version if we have many package = candidates[0] for candidate in candidates: if candidate.is_prerelease() and not allow_prereleases: continue # Select highest version of the two if less_than(package.version, candidate.version): package = candidate return package
def handle(self): from poetry.__version__ import __version__ from poetry.repositories.pypi_repository import PyPiRepository from poetry.semver.comparison import less_than version = self.argument('version') if not version: version = '>=' + __version__ repo = PyPiRepository(fallback=False) packages = repo.find_packages('poetry', version, allow_prereleases=self.option('preview')) if not packages: self.line('No release found for the specified version') return packages.sort( key=cmp_to_key(lambda x, y: 0 if x.version == y.version else -1 * int(less_than(x.version, y.version) or -1))) release = None for package in reversed(packages): if package.is_prerelease(): if self.option('preview'): release = package break continue release = package break if release is None: self.line('No new release found') return if release.version == __version__: self.line('You are using the latest version') return try: self.update(release) except subprocess.CalledProcessError as e: self.line('') self.output.block([ '[CalledProcessError]', 'An error has occured: {}'.format( str(e)), e.output ], style='error') return e.returncode
def test_less_than(version1, version2, expected): if expected is True: assert less_than(version1, version2) else: assert not less_than(version1, version2)