Find a version given the package handle and the version.

@param string $packageHandle
@param string $packageVersion

@return \CommunityTranslation\Entity\Package\Version|null
510238
public function findByHandleAndVersion($packageHandle, $packageVersion)
    {
        $result = null;
        $packageHandle = (string) $packageHandle;
        if ($packageHandle !== '') {
            $packageVersion = (string) $packageVersion;
            if ($packageVersion !== '') {
                $list = $this->createQueryBuilder('v')
                    ->innerJoin(Package::class, 'p', Expr\Join::WITH, 'v.package = p.id')
                    ->where('p.handle = :handle')->setParameter('handle', $packageHandle)
                    ->andWhere('v.version = :version')->setParameter('version', $packageVersion)
                    ->setMaxResults(1)
                    ->getQuery()->execute();
                if (!empty($list)) {
                    $result = $list[0];
                }
            }
        }

        return $result;
    }
936312
protected function getPackageVersions($obj)
    {
        $result = [];
        if ($obj instanceof PackageVersionEntity) {
            $result[] = $obj;
        } elseif (is_array($obj)) {
            $app = Application::getFacadeApplication();
            if (isset($obj['handle']) && isset($obj['version'])) {
                $pv = $app->make(PackageVersionRepository::class)->findByHandleAndVersion(
                    $obj['handle'],
                    $obj['version']
                );
                if ($pv === null) {
                    throw new UserMessageException(t('Invalid translated package specified'));
                }
                $result[] = $pv;
            } elseif (isset($obj[0]) && is_string($obj[1]) && isset($obj[1]) && is_string($obj[1])) {
                $pv = $app->make(PackageVersionRepository::class)->findByHandleAndVersion(
                    $obj[0],
                    $obj[1]
                );
                if ($pv === null) {
                    throw new UserMessageException(t('Invalid translated package specified'));
                }
                $result[] = $pv;
            } else {
                foreach ($obj as $item) {
                    $result = array_merge($result, $this->getPackageVersions($item));
                }
            }
        }
        if (empty($result)) {
            throw new UserMessageException(t('Invalid translated package specified'));
        }

        return $result;
    }
823023
public function getOneVersion($versionNumber, $con = null)
    {
        return ChildDealerBrandVersionQuery::create()
            ->filterByDealerBrand($this)
            ->filterByVersion($versionNumber)
            ->findOne($con);
    }
1236566
public static String getVersion() {
        Package pkg = RoseVersion.class.getPackage();
        return (pkg != null ? pkg.getImplementationVersion() : null);
    }
530014
public function findBestCandidate($packageName, $targetPackageVersion = null)
    {
        $constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
        $candidates = $this->pool->whatProvides(strtolower($packageName), $constraint, true);

        if (!$candidates) {
            return false;
        }

        // select highest version if we have many
        $package = reset($candidates);
        foreach ($candidates as $candidate) {
            if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
                $package = $candidate;
            }
        }

        return $package;
    }
1321429
function getPackageVersion() {
  var packageJson = path.join(process.cwd(), 'package.json'),
    version;
  try {
    version = require(packageJson).version;
  } catch (unused) {
    throw new Error('Could not load package.json, please make sure it exists');
  }
  if (!semver.valid(version)) {
    throw new Error('Invalid version number found in package.json, please make sure it is valid');
  }

  return [ semver.major(version), semver.minor(version), semver.patch(version) ].join('.');
}
280624
private static int getAppVersion(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            // should never happen
            throw new RuntimeException("Coult not get package name: " + e);
        }
    }
1290026
public function getServerVersion()
    {
        try {
            $stmt = $this->query('SELECT service_level, fixpack_num FROM TABLE (sysproc.env_get_inst_info()) as INSTANCEINFO');
            $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
            if (count($result)) {
                $matches = null;
                if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $result[0][0], $matches)) {
                    return $matches[1];
                } else {
                    return null;
                }
            }
            return null;
        } catch (PDOException $e) {
            return null;
        }
    }
863277
public function handleVersionedService($version, $service, $resource = null)
    {
        $request = new ServiceRequest();
        $request->setApiVersion($version);

        return $this->handleServiceRequest($request, $service, $resource);
    }
1348500
public function getVersion($version_key)
    {
        if(is_null($this->version))
        {
            //determine the version
            $headers = \getallheaders();
            if(isset($headers[$version_key]) && is_numeric($headers[$version_key]) && in_array($headers[$version_key], $this->api_versions))
            {
                $version = 'V'.str_replace('.','_',$headers[$version_key]);
            }
            else
            {
                $version = 'V1';
            }
            
            $this->version = $version;
        }
        
        return $this->version;
    }
1029577
def package_version(package_name: str) -> typing.Optional[str]:
    

    try:
        return pkg_resources.get_distribution(package_name).version
    except (pkg_resources.DistributionNotFound, AttributeError):
        return None
499981
public function mapEngineVersion(?string $engineVersion): VersionInterface
    {
        if (null === $engineVersion) {
            return new Version();
        }

        switch (mb_strtolower($engineVersion)) {
            case '':
            case 'unknown':
            case 'other':
                return new Version(0);
                break;
            default:
                // nothing to do here
                break;
        }

        return (new VersionFactory())->set($engineVersion);
    }
248605
protected function chooseVersion(Package $package)
    {
        $versions = $package->getVersions();

        if (count($versions) === 1) {
            $v = current($versions)->getVersion();
            $this->comment('Version to install: ' . $v);
            return $v;
        }

        $default = 1;
        $latest = $this->getLatestStable($package);
        $i = 1;

        $this->comment('Available versions:');
        foreach ($versions as $version) {
            $v = $version->getVersion();
            $versionsAvailable[$i] = $v;
            if ($v === $latest) {
                $default = $i;
            }

            $this->getOutput()->writeln(sprintf(
                '[%d] <info>%s</info> (%s)',
                $i,
                $v,
                Carbon::parse($version->getTime())->format('Y-m-d H:i:s')
            ));

            ++$i;
        }

        $choose = $this->ask('Select version by number [' . $default . ']:', $default);

        if (!is_numeric($choose) || !isset($versionsAvailable[$choose])) {
            $this->error('Incorrect value given!');
            return $this->chooseVersion($package);
        } else {
            $this->comment('Your choice: ' . $versionsAvailable[$choose]);
            return $versionsAvailable[$choose];
        }
    }
45660
public function getRequiredVersion(RootPackageInterface $package)
    {
        foreach (array($package->getRequires(), $package->getDevRequires()) as $requiredPackages) {
            if (isset($requiredPackages[static::PACKAGE_NAME])) {
                return $requiredPackages[static::PACKAGE_NAME]->getPrettyConstraint();
            }
        }
        throw new \RuntimeException('Can not determine required version of ' . static::PACKAGE_NAME);
    }
365584
public function getPackageSelectQuery(PackageVersionEntity $packageVersion, LocaleEntity $locale, $excludeUntranslatedStrings = false)
    {
        $cn = $this->app->make(EntityManager::class)->getConnection();
        $queryPackageVersionID = (int) $packageVersion->getID();

        return $cn->executeQuery(
            $this->getBaseSelectString($locale, true, $excludeUntranslatedStrings) .
            "
                where
                    CommunityTranslationTranslatablePlaces.packageVersion = $queryPackageVersionID
                order by
                    CommunityTranslationTranslatablePlaces.sort
            "
        );
    }
1079075
public function getPackageHandle()
    {
        if (!isset($this->pkgHandle)) {
            $this->pkgHandle = PackageList::getHandle($this->pkgID);
        }

        return $this->pkgHandle;
    }
52512
public function importPackageVersionTranslatables($packageHandle, $packageVersion, $formatHandle)
    {
        $this->start();
        try {
            $this->getUserControl()->checkRateLimit();
            $this->getUserControl()->checkGenericAccess(__FUNCTION__);
            $em = $this->app->make(EntityManager::class);
            $post = $this->request->request;
            $packageName = $post->get('packageName', '');
            if (!is_string($packageName)) {
                $packageName = '';
            }
            $packageVersion = is_string($packageVersion) ? trim($packageVersion) : '';
            if ($packageVersion === '') {
                throw new UserMessageException(t('Package version not specified'), Response::HTTP_NOT_ACCEPTABLE);
            }
            $format = $this->app->make(TranslationsConverterProvider::class)->getByHandle($formatHandle);
            if ($format === null) {
                throw new UserMessageException(t('Unable to find the specified translations format'), 404);
            }
            $package = $this->app->make(PackageRepository::class)->findOneBy(['handle' => $packageHandle]);
            if ($package === null) {
                $package = PackageEntity::create($packageHandle, $packageName);
                $em->persist($package);
                $em->flush($package);
                $version = null;
            } else {
                if ($packageName !== '' && $package->getName() !== $packageName) {
                    $package->setName($packageName);
                    $em->persist($package);
                    $em->flush($package);
                }
                $version = $this->app->make(PackageVersionRepository::class)->findByOneBy(['package' => $package, 'version' => $packageVersion]);
            }
            if ($version === null) {
                $version = PackageVersionEntity::create($package, $packageVersion);
                $em->persist($version);
                $em->flush($version);
            }
            $file = $this->request->files->get('file');
            if ($file === null) {
                throw new UserMessageException(t('The file with translatable strings has not been specified'), Response::HTTP_NOT_ACCEPTABLE);
            }
            if (!$file->isValid()) {
                throw new UserMessageException(t('The file with translatable strings has not been received correctly: %s', $file->getErrorMessage()), Response::HTTP_NOT_ACCEPTABLE);
            }
            $translations = $format->loadTranslationsFromFile($file->getPathname());
            if (count($translations) < 1) {
                throw new UserMessageException(t('No translatable strings found in uploaded file'));
            }
            $importer = $this->app->make(TranslatableImporter::class);
            $changed = $importer->importTranslations($translations, $package->getHandle(), $packageVersion->getVersion());
            $result = $this->buildJsonResponse(['changed' => $changed]);
        } catch (Exception $x) {
            $result = $this->buildErrorResponse($x);
        } catch (Throwable $x) {
            $result = $this->buildErrorResponse($x);
        }

        return $this->finish($result);
    }