Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pypi decorator handling packages with special characters #1643

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions metaflow/plugins/pypi/conda_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from metaflow.metaflow_profile import profile

from . import MAGIC_FILE, _datastore_packageroot
from .utils import conda_platform
from .utils import conda_platform, generate_cache_path, parse_filename_from_url


class CondaEnvironmentException(MetaflowException):
Expand Down Expand Up @@ -107,7 +107,7 @@ def cache(storage, results, type_):
local_packages = {
url: {
# Path to package in datastore.
"path": urlparse(url).netloc + urlparse(url).path,
"path": generate_cache_path(url, local_path),
# Path to package on local disk.
"local_path": local_path,
}
Expand All @@ -122,9 +122,8 @@ def cache(storage, results, type_):
# Cache only those packages that manifest is unaware of
local_packages.pop(package["url"], None)
else:
package["path"] = (
urlparse(package["url"]).netloc
+ urlparse(package["url"]).path
package["path"] = generate_cache_path(
package["url"], parse_filename_from_url(package["url"])
)
dirty.add(id_)

Expand Down
4 changes: 2 additions & 2 deletions metaflow/plugins/pypi/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from metaflow.util import which

from .micromamba import Micromamba
from .utils import pip_tags
from .utils import parse_filename_from_url, pip_tags


class PipException(MetaflowException):
Expand Down Expand Up @@ -118,7 +118,7 @@ def download(self, id_, packages, python, platform):
for package in packages:
cmd.append("{url}".format(**package))
metadata["{url}".format(**package)] = "{prefix}/.pip/wheels/{wheel}".format(
prefix=prefix, wheel=package["url"].split("/")[-1]
prefix=prefix, wheel=parse_filename_from_url(package["url"])
)
self._call(prefix, cmd)
# write the url to wheel mappings in a magic location
Expand Down
15 changes: 15 additions & 0 deletions metaflow/plugins/pypi/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import platform
import sys

Expand All @@ -13,6 +14,7 @@ class Tags:
from metaflow._vendor.packaging import tags

from metaflow.exception import MetaflowException
from urllib.parse import unquote, urlparse


def conda_platform():
Expand Down Expand Up @@ -73,3 +75,16 @@ def pip_tags(python_version, mamba_platform):
supported.extend(tags.cpython_tags(py_version, abis, platforms))
supported.extend(tags.compatible_tags(py_version, interpreter, platforms))
return supported


def parse_filename_from_url(url):
# Separate method as it might require additional checks for the parsing.
filename = url.split("/")[-1]
return unquote(filename)


def generate_cache_path(url, local_path):
base, _ = os.path.split(urlparse(url).path)
_, localfile = os.path.split(local_path)
unquoted_base = unquote(base)
return urlparse(url).netloc + os.path.join(unquoted_base, localfile)
Loading