From a0f390ab23eb19ef61089608400e749da46bc3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 5 Feb 2020 10:52:33 -0800 Subject: [PATCH] project.py: fix windows-style paths as manifest URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the manifest URL is a windows-style path, e.g. C:\Users\marti\my-manifest, then the current code produces a manifest.path configuration option set to '\Users\marti\my-manifest' instead of the expected 'my-manifest'. Fix it by using PurePath so we get PureWindowsPath on windows, instead of using the low-level posixpath. Note that PurePath is PurePosixPath on POSIX platforms, so the behavior is the same on those. Fix the import order while we are here, moving stdlib imports to their proper section. Signed-off-by: Martí Bolívar --- src/west/app/project.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index c154a05..44f8b75 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -10,12 +10,14 @@ from functools import partial, lru_cache import logging import os from os.path import join, relpath, basename, dirname, exists, isdir +from pathlib import PurePath import shutil import shlex import subprocess import sys import textwrap from time import perf_counter +from urllib.parse import urlparse from west.configuration import config, update_config from west import log @@ -27,8 +29,6 @@ from west.manifest import ImportFlag, Manifest, MANIFEST_PROJECT_INDEX, \ from west.manifest import MANIFEST_REV_BRANCH as MANIFEST_REV from west.manifest import QUAL_MANIFEST_REV_BRANCH as QUAL_MANIFEST_REV from west.manifest import QUAL_REFS_WEST as QUAL_REFS -from urllib.parse import urlparse -import posixpath # # Project-related or multi-repo commands, like "init", "update", @@ -274,7 +274,12 @@ class Init(_ProjectCommand): if manifest_project.path: manifest_path = manifest_project.path else: - manifest_path = posixpath.basename(urlparse(manifest_url).path) + # We use PurePath() here in case manifest_url is a + # windows-style path. That does the right thing in that + # case, without affecting POSIX platforms, where PurePath + # is PurePosixPath. + manifest_path = PurePath(urlparse(manifest_url).path).name + manifest_abspath = join(topdir, manifest_path) log.dbg('moving', tempdir, 'to', manifest_abspath,