Python pip._vendor.pkg_resources.safe_name() Examples

The following are 30 code examples of pip._vendor.pkg_resources.safe_name(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pip._vendor.pkg_resources , or try the search function .
Example #1
Source File: index.py    From Flask-P2P with MIT License 6 votes vote down vote up
def fmt_ctl_handle_mutual_exclude(value, target, other):
    new = value.split(',')
    while ':all:' in new:
        other.clear()
        target.clear()
        target.add(':all:')
        del new[:new.index(':all:') + 1]
        if ':none:' not in new:
            # Without a none, we want to discard everything as :all: covers it
            return
    for name in new:
        if name == ':none:':
            target.clear()
            continue
        name = pkg_resources.safe_name(name).lower()
        other.discard(name)
        target.add(name) 
Example #2
Source File: core.py    From pdm with MIT License 6 votes vote down vote up
def get_locked_candidates(
        self, section: Optional[str] = None
    ) -> Dict[str, Candidate]:
        if not self.lockfile_file.is_file():
            return {}
        section = section or "default"
        result = {}
        for package in [dict(p) for p in self.lockfile.get("package", [])]:
            if section != "__all__" and section not in package["sections"]:
                continue
            version = package.get("version")
            if version:
                package["version"] = f"=={version}"
            package_name = package.pop("name")
            req = Requirement.from_req_dict(package_name, dict(package))
            can = Candidate(req, self.environment, name=package_name, version=version)
            can.marker = req.marker
            can.hashes = {
                item["file"]: item["hash"]
                for item in self.lockfile["metadata"].get(f"{req.key} {version}", [])
            } or None
            result[req.identify()] = can
        if section in ("default", "__all__") and self.meta.name and self.meta.version:
            result[safe_name(self.meta.name).lower()] = self.make_self_candidate(True)
        return result 
Example #3
Source File: index.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def fmt_ctl_handle_mutual_exclude(value, target, other):
    new = value.split(',')
    while ':all:' in new:
        other.clear()
        target.clear()
        target.add(':all:')
        del new[:new.index(':all:') + 1]
        if ':none:' not in new:
            # Without a none, we want to discard everything as :all: covers it
            return
    for name in new:
        if name == ':none:':
            target.clear()
            continue
        name = pkg_resources.safe_name(name).lower()
        other.discard(name)
        target.add(name) 
Example #4
Source File: index.py    From datafari with Apache License 2.0 6 votes vote down vote up
def fmt_ctl_handle_mutual_exclude(value, target, other):
    new = value.split(',')
    while ':all:' in new:
        other.clear()
        target.clear()
        target.add(':all:')
        del new[:new.index(':all:') + 1]
        if ':none:' not in new:
            # Without a none, we want to discard everything as :all: covers it
            return
    for name in new:
        if name == ':none:':
            target.clear()
            continue
        name = pkg_resources.safe_name(name).lower()
        other.discard(name)
        target.add(name) 
Example #5
Source File: index.py    From ImageFusion with MIT License 6 votes vote down vote up
def fmt_ctl_handle_mutual_exclude(value, target, other):
    new = value.split(',')
    while ':all:' in new:
        other.clear()
        target.clear()
        target.add(':all:')
        del new[:new.index(':all:') + 1]
        if ':none:' not in new:
            # Without a none, we want to discard everything as :all: covers it
            return
    for name in new:
        if name == ':none:':
            target.clear()
            continue
        name = pkg_resources.safe_name(name).lower()
        other.discard(name)
        target.add(name) 
Example #6
Source File: conftest.py    From pdm with MIT License 6 votes vote down vote up
def working_set(mocker, repository):
    from pip._internal.utils import logging

    rv = MockWorkingSet()
    mocker.patch.object(Environment, "get_working_set", return_value=rv)

    def install(candidate):
        logging._log_state.indentation = 0
        dependencies = repository.get_dependencies(candidate)[0]
        key = safe_name(candidate.name).lower()
        dist = Distribution(key, candidate.version)
        dist.dependencies = dependencies
        rv.add_distribution(dist)

    def uninstall(dist):
        del rv[dist.key]

    installer = mocker.MagicMock()
    installer.install.side_effect = install
    installer.uninstall.side_effect = uninstall
    mocker.patch("pdm.installers.synchronizers.Installer", return_value=installer)
    mocker.patch("pdm.installers.Installer", return_value=installer)

    yield rv 
Example #7
Source File: req_install.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #8
Source File: wheel.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def cached_wheel(cache_dir, link, format_control, package_name):
    if not cache_dir:
        return link
    if not link:
        return link
    if link.is_wheel:
        return link
    if not link.is_artifact:
        return link
    if not package_name:
        return link
    canonical_name = pkg_resources.safe_name(package_name).lower()
    formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
    if "binary" not in formats:
        return link
    root = _cache_for_link(cache_dir, link)
    try:
        wheel_names = os.listdir(root)
    except OSError as e:
        if e.errno in (errno.ENOENT, errno.ENOTDIR):
            return link
        raise
    candidates = []
    for wheel_name in wheel_names:
        try:
            wheel = Wheel(wheel_name)
        except InvalidWheelFilename:
            continue
        if not wheel.supported():
            # Built for a different python/arch/etc
            continue
        candidates.append((wheel.support_index_min(), wheel_name))
    if not candidates:
        return link
    candidates.sort()
    path = os.path.join(root, candidates[0][1])
    return pip.index.Link(path_to_url(path), trusted=True) 
Example #9
Source File: req_install.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #10
Source File: req_install.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #11
Source File: req_install.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #12
Source File: req_install.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #13
Source File: req_install.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #14
Source File: req_install.py    From android_universal with MIT License 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #15
Source File: req_install.py    From guildai with Apache License 2.0 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #16
Source File: req_install.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #17
Source File: req_install.py    From CogAlg with MIT License 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #18
Source File: req_install.py    From python-netsurv with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #19
Source File: req_install.py    From Hands-On-Deep-Learning-for-Games with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #20
Source File: req_install.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #21
Source File: req_install.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #22
Source File: wheel.py    From datafari with Apache License 2.0 5 votes vote down vote up
def cached_wheel(cache_dir, link, format_control, package_name):
    if not cache_dir:
        return link
    if not link:
        return link
    if link.is_wheel:
        return link
    if not link.is_artifact:
        return link
    if not package_name:
        return link
    canonical_name = pkg_resources.safe_name(package_name).lower()
    formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
    if "binary" not in formats:
        return link
    root = _cache_for_link(cache_dir, link)
    try:
        wheel_names = os.listdir(root)
    except OSError as e:
        if e.errno == errno.ENOENT:
            return link
        raise
    candidates = []
    for wheel_name in wheel_names:
        try:
            wheel = Wheel(wheel_name)
        except InvalidWheelFilename:
            continue
        if not wheel.supported():
            # Built for a different python/arch/etc
            continue
        candidates.append((wheel.support_index_min(), wheel_name))
    if not candidates:
        return link
    candidates.sort()
    path = os.path.join(root, candidates[0][1])
    return pip.index.Link(path_to_url(path), trusted=True) 
Example #23
Source File: req_install.py    From Ansible with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #24
Source File: req_install.py    From python2017 with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #25
Source File: wheel.py    From ImageFusion with MIT License 5 votes vote down vote up
def cached_wheel(cache_dir, link, format_control, package_name):
    if not cache_dir:
        return link
    if not link:
        return link
    if link.is_wheel:
        return link
    if not link.is_artifact:
        return link
    if not package_name:
        return link
    canonical_name = pkg_resources.safe_name(package_name).lower()
    formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
    if "binary" not in formats:
        return link
    root = _cache_for_link(cache_dir, link)
    try:
        wheel_names = os.listdir(root)
    except OSError as e:
        if e.errno in (errno.ENOENT, errno.ENOTDIR):
            return link
        raise
    candidates = []
    for wheel_name in wheel_names:
        try:
            wheel = Wheel(wheel_name)
        except InvalidWheelFilename:
            continue
        if not wheel.supported():
            # Built for a different python/arch/etc
            continue
        candidates.append((wheel.support_index_min(), wheel_name))
    if not candidates:
        return link
    candidates.sort()
    path = os.path.join(root, candidates[0][1])
    return pip.index.Link(path_to_url(path), trusted=True) 
Example #26
Source File: wheel.py    From ImageFusion with MIT License 5 votes vote down vote up
def cached_wheel(cache_dir, link, format_control, package_name):
    if not cache_dir:
        return link
    if not link:
        return link
    if link.is_wheel:
        return link
    if not link.is_artifact:
        return link
    if not package_name:
        return link
    canonical_name = pkg_resources.safe_name(package_name).lower()
    formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
    if "binary" not in formats:
        return link
    root = _cache_for_link(cache_dir, link)
    try:
        wheel_names = os.listdir(root)
    except OSError as e:
        if e.errno in (errno.ENOENT, errno.ENOTDIR):
            return link
        raise
    candidates = []
    for wheel_name in wheel_names:
        try:
            wheel = Wheel(wheel_name)
        except InvalidWheelFilename:
            continue
        if not wheel.supported():
            # Built for a different python/arch/etc
            continue
        candidates.append((wheel.support_index_min(), wheel_name))
    if not candidates:
        return link
    candidates.sort()
    path = os.path.join(root, candidates[0][1])
    return pip.index.Link(path_to_url(path), trusted=True) 
Example #27
Source File: req_install.py    From rules_pip with MIT License 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return six.ensure_str(pkg_resources.safe_name(self.req.name)) 
Example #28
Source File: req_install.py    From planespotter with MIT License 5 votes vote down vote up
def name(self):
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #29
Source File: req_install.py    From Weapon-Detection-And-Classification with MIT License 5 votes vote down vote up
def name(self):
        # type: () -> Optional[str]
        if self.req is None:
            return None
        return native_str(pkg_resources.safe_name(self.req.name)) 
Example #30
Source File: wheel.py    From Flask-P2P with MIT License 5 votes vote down vote up
def cached_wheel(cache_dir, link, format_control, package_name):
    if not cache_dir:
        return link
    if not link:
        return link
    if link.is_wheel:
        return link
    if not link.is_artifact:
        return link
    if not package_name:
        return link
    canonical_name = pkg_resources.safe_name(package_name).lower()
    formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
    if "binary" not in formats:
        return link
    root = _cache_for_link(cache_dir, link)
    try:
        wheel_names = os.listdir(root)
    except OSError as e:
        if e.errno in (errno.ENOENT, errno.ENOTDIR):
            return link
        raise
    candidates = []
    for wheel_name in wheel_names:
        try:
            wheel = Wheel(wheel_name)
        except InvalidWheelFilename:
            continue
        if not wheel.supported():
            # Built for a different python/arch/etc
            continue
        candidates.append((wheel.support_index_min(), wheel_name))
    if not candidates:
        return link
    candidates.sort()
    path = os.path.join(root, candidates[0][1])
    return pip.index.Link(path_to_url(path), trusted=True)