How to use the packaging.version function in packaging

To help you get started, we’ve selected a few packaging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circleguard / circleguard / circleguard / settings.py View on Github external
def overwrite_outdated_settings():
    last_version = version.parse(get_setting("last_version"))
    last_version = version.parse(last_version.base_version) # remove dev stuff
    for ver, changed_arr in FORCE_UPDATE.items():
        if last_version < version.parse(ver):
            for setting in changed_arr:
                if setting not in TYPES:
                    # happens if the key is in FORCE_UPDATE but was deleted in a
                    # later version, like message_cheater_found.
                    continue
                set_setting(setting, DEFAULTS[TYPES[setting][1]][setting])
    set_setting("last_version", __version__)
github jazzband-roadies / website / jazzband / projects / forms.py View on Github external
def _validate_pep440_version(form, field):
    parsed = version.parse(field.data)

    # Check that this version is a valid PEP 440 version at all.
    if not isinstance(parsed, version.Version):
        raise validators.ValidationError(
            "Must start and end with a letter or numeral and contain only "
            "ascii numeric and '.', '_' and '-'."
        )

    # Check that this version does not have a PEP 440 local segment attached
    # to it.
    if parsed.local is not None:
        raise validators.ValidationError("Cannot use PEP 440 local versions.")
github pymedphys / pymedphys / pymedphys / _dicom / collection.py View on Github external
def __eq__(self, other):
        if version.parse(pydicom.__version__) <= version.parse("1.2.1"):
            self_elems = sorted(list(self.dataset.iterall()), key=lambda x: x.tag)
            other_elems = sorted(list(other.dataset.iterall()), key=lambda x: x.tag)
            return self_elems == other_elems

        # TODO: Change for pydicom>=1.2.2?
        self_elems = sorted(list(self.dataset.iterall()), key=lambda x: x.tag)
        other_elems = sorted(list(other.dataset.iterall()), key=lambda x: x.tag)
        return self_elems == other_elems
github AruniRC / detectron-self-train / lib / core / config.py View on Github external
values that are necessary (e.g., merging a config from a file, merging
    command line config options, etc.). By default, this function will also
    mark the global cfg as immutable to prevent changing the global cfg settings
    during script execution (which can lead to hard to debug errors or code
    that's harder to understand than is necessary).
    """
    if __C.MODEL.RPN_ONLY or __C.MODEL.FASTER_RCNN:
        __C.RPN.RPN_ON = True
    if __C.RPN.RPN_ON or __C.RETINANET.RETINANET_ON:
        __C.TEST.PRECOMPUTED_PROPOSALS = False
    if __C.MODEL.LOAD_IMAGENET_PRETRAINED_WEIGHTS:
        assert __C.RESNETS.IMAGENET_PRETRAINED_WEIGHTS, \
            "Path to the weight file must not be empty to load imagenet pertrained resnets."
    if set([__C.MRCNN.ROI_MASK_HEAD, __C.KRCNN.ROI_KEYPOINTS_HEAD]) & _SHARE_RES5_HEADS:
        __C.MODEL.SHARE_RES5 = True
    if version.parse(torch.__version__) < version.parse('0.4.0'):
        __C.PYTORCH_VERSION_LESS_THAN_040 = True
        # create alias for PyTorch version less than 0.4.0
        init.uniform_ = init.uniform
        init.normal_ = init.normal
        init.constant_ = init.constant
        nn.GroupNorm = mynn.GroupNorm
    if make_immutable:
        cfg.immutable(True)
github pierky / arouteserver / pierky / arouteserver / euro_ix.py View on Github external
That's why this function takes both `member` and `vlan_ip_info` into account.

            It's called from two other functions:
            - first time by process_member, at member level only, in order to catch
              route servers on versions <= 0.6.
            - second time, it's called by process_connection, to perform the check
              at connection level (VLAN IP info), to catch route servers on versions
              >= 0.7.
            """

            schema_version = self._get_item("version", self.raw_data, str)

            # Until version 0.6, route servers were identified using a
            # specific `member_type`.
            if version.parse(schema_version) <= version.parse("0.6"):
                if self._get_item("member_type", member, str, True) == "routeserver":
                    return True
                return False

            # In version 0.7, "routeserver" was removed from the valid
            # values of `member_type`, and `service_type` was introduced, but at connection
            # level this time (VLAN IP info).
            if version.parse(schema_version) <= version.parse("0.7"):
                if vlan_ip_info:
                    service_type = self._get_item("service_type", vlan_ip_info, list, True)
                    if service_type and "ixrouteserver" in service_type:
                        return True
                return False

            # In the latest version (1.0 ATOW), the classification is still done
            # at connection level, but using a different attribute, `services`.
github voxel51 / eta / eta / core / utils.py View on Github external
else:
        pkg_str = package_name

    try:
        pkg = importlib.import_module(package_name)
    except ImportError as e:
        six.raise_from(
            ImportError(
                "The requested operation requires that '%s' is installed on "
                "your machine" % pkg_str
            ),
            e,
        )

    if has_min_ver or has_max_ver:
        pkg_version = packaging.version.parse(pkg.__version__)

        if (has_min_ver and pkg_version < min_version) or (
            has_max_ver and pkg_version >= max_version
        ):
            raise ImportError(
                "The requested operation requires that '%s' is installed "
                "on your machine; found '%s==%s'"
                % (pkg_str, package_name, pkg_version)
            )
github dagster-io / dagster / bin / publish.py View on Github external
def check_new_version(new_version):
    parsed_version = packaging.version.parse(new_version)
    module_versions = check_existing_version()
    errors = {}
    last_version = None
    for module_name, module_version in module_versions.items():
        last_version = module_version
        if packaging.version.parse(module_version['__version__']) >= parsed_version:
            errors[module_name] = module_version['__version__']
    if errors:
        raise Exception(
            'Bailing: Found modules with existing versions greater than or equal to the new '
            'version {new_version}:\n{versions}'.format(
                new_version=new_version, versions=format_module_versions(module_versions)
            )
        )

    if not (
github kiibohd / kll / kll / common / stage.py View on Github external
if apply_offsets:
                            assert (len(self.min_scan_code) > self.most_recent_connect_id)
                            assert (len(self.max_scan_code) > self.most_recent_connect_id)
                            assert (len(self.interconnect_scancode_offsets) > self.most_recent_connect_id)

                    if (
                        l_element.value == "KLL"
                            and
                        mid_element.value == "="
                    ):
                        # Rebuild version number
                        file_version = ".".join([token.value for token in tokens[2:]])

                        # Compare version to last compatible version (not running version, this is different)
                        if version.parse(file_version) < version.parse(self.control.last_compat_version):
                            print(
                                "{} {}".format(
                                    ERROR,
                                    kll_file.path,
                                )
                            )
                            print("      Contains possibly incompatible KLL expressions from \033[1m{}\033[0m".format(
                                    file_version,
                                )
                            )
                            print("      Please your configuration to KLL {} compliant code".format(
                                    self.control.last_compat_version
                                )
                            )
                            info = suggestions.Suggestions(self.control.short_version, file_version)
                            info.show()
github rodluger / starry / .ci / print_starry_version.py View on Github external
import starry
import packaging
import urllib

# Hack to figure out if we are the latest version
url = "https://raw.githubusercontent.com/rodluger/starry/gh-pages/versions.txt"
all_versions = []
for line in urllib.request.urlopen(url):
    version_string = line.decode("utf-8").replace("\n", "").strip()
    all_versions.append(packaging.version.parse(version_string))
all_versions = sorted(all_versions)
current_version = packaging.version.parse(starry.__version__)
is_latest = (current_version.is_devrelease) and (
    current_version.base_version >= all_versions[-1].base_version
)

if is_latest:
    print("latest")
else:
    print("v{}".format(current_version.base_version))