mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Fix bug with parsing detached packages
This commit is contained in:
@ -229,6 +229,8 @@ class PackageSpec(object): # pylint: disable=too-many-instance-attributes
|
||||
def _parse_requirements(self, raw):
|
||||
if "@" not in raw:
|
||||
return raw
|
||||
if raw.startswith("file://") and os.path.exists(raw[7:]):
|
||||
return raw
|
||||
tokens = raw.rsplit("@", 1)
|
||||
if any(s in tokens[1] for s in (":", "/")):
|
||||
return raw
|
||||
@ -296,7 +298,10 @@ class PackageSpec(object): # pylint: disable=too-many-instance-attributes
|
||||
def _parse_name_from_url(url):
|
||||
if url.endswith("/"):
|
||||
url = url[:-1]
|
||||
for c in ("#", "?"):
|
||||
stop_chars = ["#", "?"]
|
||||
if url.startswith("file://"):
|
||||
stop_chars.append("@") # detached path
|
||||
for c in stop_chars:
|
||||
if c in url:
|
||||
url = url[: url.index(c)]
|
||||
|
||||
|
@ -80,7 +80,7 @@ def test_spec_requirements():
|
||||
assert spec == PackageSpec(id=20, requirements="!=1.2.3,<2.0")
|
||||
|
||||
|
||||
def test_spec_local_urls():
|
||||
def test_spec_local_urls(tmpdir_factory):
|
||||
assert PackageSpec("file:///tmp/foo.tar.gz") == PackageSpec(
|
||||
url="file:///tmp/foo.tar.gz", name="foo"
|
||||
)
|
||||
@ -93,6 +93,11 @@ def test_spec_local_urls():
|
||||
assert PackageSpec("file:///tmp/foo.tar.gz@~2.3.0-beta.1") == PackageSpec(
|
||||
url="file:///tmp/foo.tar.gz", name="foo", requirements="~2.3.0-beta.1"
|
||||
)
|
||||
# detached folder with "@" symbol
|
||||
pkg_dir = tmpdir_factory.mktemp("storage").join("detached@1.2.3").mkdir()
|
||||
assert PackageSpec("file://%s" % str(pkg_dir)) == PackageSpec(
|
||||
name="detached", url="file://%s" % pkg_dir
|
||||
)
|
||||
|
||||
|
||||
def test_spec_external_urls():
|
||||
|
Reference in New Issue
Block a user