From 743fc8e6365bb0b87163d012a7de397e1cec4495 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 20 Apr 2023 18:57:22 +0300 Subject: [PATCH] Improved support for projects located on Windows network drives // Resolve #3417 --- HISTORY.rst | 1 + platformio/builder/main.py | 15 +-------------- platformio/check/cli.py | 8 ++------ platformio/commands/ci.py | 6 ++---- platformio/commands/lib.py | 4 +--- platformio/debug/cli.py | 8 ++------ platformio/device/monitor/command.py | 2 +- platformio/fs.py | 21 +-------------------- platformio/package/commands/install.py | 4 ++-- platformio/package/commands/list.py | 4 ++-- platformio/package/commands/outdated.py | 2 +- platformio/package/commands/pack.py | 2 +- platformio/package/commands/publish.py | 2 +- platformio/package/commands/uninstall.py | 4 ++-- platformio/package/commands/update.py | 4 ++-- platformio/project/commands/config.py | 2 +- platformio/project/commands/init.py | 4 +--- platformio/project/commands/metadata.py | 4 ++-- platformio/project/helpers.py | 2 +- platformio/project/options.py | 2 +- platformio/remote/cli.py | 16 +++++----------- platformio/run/cli.py | 8 ++------ platformio/system/commands/completion.py | 4 ++-- platformio/test/cli.py | 12 ++++-------- tests/commands/test_test.py | 2 +- 25 files changed, 42 insertions(+), 101 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 9ff6d5f4..786634ae 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -19,6 +19,7 @@ PlatformIO Core 6 ~~~~~~~~~~~~~~~~~~ * Implemented a new feature to store device monitor logs in the project's "logs" folder, making it easier to access and review device monitor logs for your projects (`issue #4596 `_) +* Improved support for projects located on Windows network drives, including Network Shared Folder, Dropbox, OneDrive, Google Drive, and other similar services (`issue #3417 `_) * Improved source file filtering functionality for the `Static Code Analysis `__ feature, making it easier to analyze only the code you need to * Added the ability to show a detailed library dependency tree only in `verbose mode `__, which can help you understand the relationship between libraries and troubleshoot issues more effectively (`issue #4517 `_) * Added the ability to run only the `device monitor `__ when using the `pio run -t monitor `__ command, saving you time and resources by skipping the build process diff --git a/platformio/builder/main.py b/platformio/builder/main.py index f80435f2..e73489d5 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -28,7 +28,7 @@ from SCons.Script import DefaultEnvironment # pylint: disable=import-error from SCons.Script import Import # pylint: disable=import-error from SCons.Script import Variables # pylint: disable=import-error -from platformio import app, compat, fs +from platformio import app, fs from platformio.platform.base import PlatformBase from platformio.proc import get_pythonexe_path, where_is_program from platformio.project.helpers import get_project_dir @@ -139,19 +139,6 @@ if int(ARGUMENTS.get("ISATTY", 0)): # pylint: disable=protected-access click._compat.isatty = lambda stream: True -if compat.IS_WINDOWS and sys.version_info >= (3, 8) and os.getcwd().startswith("\\\\"): - click.secho("!!! WARNING !!!\t\t" * 3, fg="red") - click.secho( - "Your project is located on a mapped network drive but the " - "current command-line shell does not support the UNC paths.", - fg="yellow", - ) - click.secho( - "Please move your project to a physical drive or check this workaround: " - "https://bit.ly/3kuU5mP\n", - fg="yellow", - ) - if env.subst("$BUILD_CACHE_DIR"): if not os.path.isdir(env.subst("$BUILD_CACHE_DIR")): os.makedirs(env.subst("$BUILD_CACHE_DIR")) diff --git a/platformio/check/cli.py b/platformio/check/cli.py index d1abdfff..d99da313 100644 --- a/platformio/check/cli.py +++ b/platformio/check/cli.py @@ -38,16 +38,12 @@ from platformio.project.helpers import find_project_dir_above, get_project_dir "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=True, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=True, writable=True), ) @click.option( "-c", "--project-conf", - type=click.Path( - exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True), ) @click.option("--pattern", multiple=True, hidden=True) @click.option("-f", "--src-filters", multiple=True) diff --git a/platformio/commands/ci.py b/platformio/commands/ci.py index aebd9e7b..de346afd 100644 --- a/platformio/commands/ci.py +++ b/platformio/commands/ci.py @@ -51,15 +51,13 @@ def validate_path(ctx, param, value): # pylint: disable=unused-argument @click.option( "--build-dir", default=tempfile.mkdtemp, - type=click.Path(file_okay=False, dir_okay=True, writable=True, resolve_path=True), + type=click.Path(file_okay=False, dir_okay=True, writable=True), ) @click.option("--keep-build-dir", is_flag=True) @click.option( "-c", "--project-conf", - type=click.Path( - exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True), ) @click.option("-O", "--project-option", multiple=True) @click.option("-e", "--environment", "environments", multiple=True) diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index ed3c9e8d..1c150c09 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -65,9 +65,7 @@ def invoke_command(ctx, cmd, **kwargs): "--storage-dir", multiple=True, default=None, - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), help="Manage custom library storage", ) @click.option( diff --git a/platformio/debug/cli.py b/platformio/debug/cli.py index 7137c98d..12d6004a 100644 --- a/platformio/debug/cli.py +++ b/platformio/debug/cli.py @@ -44,16 +44,12 @@ from platformio.project.options import ProjectOptions "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), ) @click.option( "-c", "--project-conf", - type=click.Path( - exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True), ) @click.option("--environment", "-e", metavar="") @click.option("--load-mode", type=ProjectOptions["env.debug_load_mode"].type) diff --git a/platformio/device/monitor/command.py b/platformio/device/monitor/command.py index 3cf13573..3d3190fe 100644 --- a/platformio/device/monitor/command.py +++ b/platformio/device/monitor/command.py @@ -104,7 +104,7 @@ from platformio.project.options import ProjectOptions "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option( "-e", diff --git a/platformio/fs.py b/platformio/fs.py index 00055299..107e6982 100644 --- a/platformio/fs.py +++ b/platformio/fs.py @@ -24,7 +24,7 @@ import sys import click -from platformio import exception, proc +from platformio import exception from platformio.compat import IS_WINDOWS @@ -196,25 +196,6 @@ def to_unix_path(path): return re.sub(r"[\\]+", "/", path) -def normalize_path(path): - path = os.path.abspath(path) - if not IS_WINDOWS or not path.startswith("\\\\"): - return path - try: - result = proc.exec_command(["net", "use"]) - if result["returncode"] != 0: - return path - share_re = re.compile(r"\s([A-Z]\:)\s+(\\\\[^\s]+)") - for line in result["out"].split("\n"): - share = share_re.search(line) - if not share: - continue - path = path.replace(share.group(2), share.group(1)) - except OSError: - pass - return path - - def expanduser(path): """ Be compatible with Python 3.8, on Windows skip HOME and check for USERPROFILE diff --git a/platformio/package/commands/install.py b/platformio/package/commands/install.py index 6041e357..e3eb05aa 100644 --- a/platformio/package/commands/install.py +++ b/platformio/package/commands/install.py @@ -39,7 +39,7 @@ from platformio.test.runners.factory import TestRunnerFactory "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) @click.option("-p", "--platform", "platforms", metavar="SPECIFICATION", multiple=True) @@ -55,7 +55,7 @@ from platformio.test.runners.factory import TestRunnerFactory @click.option( "--storage-dir", default=None, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Custom Package Manager storage for global packages", ) @click.option("-f", "--force", is_flag=True, help="Reinstall package if it exists") diff --git a/platformio/package/commands/list.py b/platformio/package/commands/list.py index dfd2559f..c2426c9c 100644 --- a/platformio/package/commands/list.py +++ b/platformio/package/commands/list.py @@ -31,7 +31,7 @@ from platformio.project.config import ProjectConfig "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) @click.option("-p", "--platform", "platforms", metavar="SPECIFICATION", multiple=True) @@ -41,7 +41,7 @@ from platformio.project.config import ProjectConfig @click.option( "--storage-dir", default=None, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Custom Package Manager storage for global packages", ) @click.option("--only-platforms", is_flag=True, help="List only platform packages") diff --git a/platformio/package/commands/outdated.py b/platformio/package/commands/outdated.py index 5a8c1ea4..18c3783a 100644 --- a/platformio/package/commands/outdated.py +++ b/platformio/package/commands/outdated.py @@ -58,7 +58,7 @@ class OutdatedCandidate: "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) def package_outdated_cmd(project_dir, environments): diff --git a/platformio/package/commands/pack.py b/platformio/package/commands/pack.py index 038ffc15..e9cd0f03 100644 --- a/platformio/package/commands/pack.py +++ b/platformio/package/commands/pack.py @@ -26,7 +26,7 @@ from platformio.package.pack import PackagePacker "package", default=os.getcwd, metavar="", - type=click.Path(exists=True, file_okay=True, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=True, dir_okay=True), ) @click.option( "-o", "--output", help="A destination path (folder or a full path to file)" diff --git a/platformio/package/commands/publish.py b/platformio/package/commands/publish.py index 58230eef..228c1411 100644 --- a/platformio/package/commands/publish.py +++ b/platformio/package/commands/publish.py @@ -47,7 +47,7 @@ def validate_datetime(ctx, param, value): # pylint: disable=unused-argument "package", default=os.getcwd, metavar="", - type=click.Path(exists=True, file_okay=True, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=True, dir_okay=True), ) @click.option( "--owner", diff --git a/platformio/package/commands/uninstall.py b/platformio/package/commands/uninstall.py index e393d2a8..2808d491 100644 --- a/platformio/package/commands/uninstall.py +++ b/platformio/package/commands/uninstall.py @@ -33,7 +33,7 @@ from platformio.project.savedeps import pkg_to_save_spec, save_project_dependenc "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) @click.option("-p", "--platform", "platforms", metavar="SPECIFICATION", multiple=True) @@ -49,7 +49,7 @@ from platformio.project.savedeps import pkg_to_save_spec, save_project_dependenc @click.option( "--storage-dir", default=None, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Custom Package Manager storage for global packages", ) @click.option("-s", "--silent", is_flag=True, help="Suppress progress reporting") diff --git a/platformio/package/commands/update.py b/platformio/package/commands/update.py index 67fc5dd1..8788f7b5 100644 --- a/platformio/package/commands/update.py +++ b/platformio/package/commands/update.py @@ -33,7 +33,7 @@ from platformio.project.savedeps import pkg_to_save_spec, save_project_dependenc "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) @click.option("-p", "--platform", "platforms", metavar="SPECIFICATION", multiple=True) @@ -49,7 +49,7 @@ from platformio.project.savedeps import pkg_to_save_spec, save_project_dependenc @click.option( "--storage-dir", default=None, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Custom Package Manager storage for global packages", ) @click.option("-s", "--silent", is_flag=True, help="Suppress progress reporting") diff --git a/platformio/project/commands/config.py b/platformio/project/commands/config.py index b59ff005..9f218e80 100644 --- a/platformio/project/commands/config.py +++ b/platformio/project/commands/config.py @@ -28,7 +28,7 @@ from platformio.project.helpers import is_platformio_project "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("--json-output", is_flag=True) def project_config_cmd(project_dir, json_output): diff --git a/platformio/project/commands/init.py b/platformio/project/commands/init.py index 6a545df4..d8cd5b8d 100644 --- a/platformio/project/commands/init.py +++ b/platformio/project/commands/init.py @@ -47,9 +47,7 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 "--project-dir", "-d", default=os.getcwd, - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), ) @click.option("-b", "--board", multiple=True, metavar="ID", callback=validate_boards) @click.option("--ide", type=click.Choice(ProjectGenerator.get_supported_ides())) diff --git a/platformio/project/commands/metadata.py b/platformio/project/commands/metadata.py index 06457574..fbf71b8b 100644 --- a/platformio/project/commands/metadata.py +++ b/platformio/project/commands/metadata.py @@ -31,11 +31,11 @@ from platformio.project.helpers import load_build_metadata "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option("-e", "--environment", "environments", multiple=True) @click.option("--json-output", is_flag=True) -@click.option("--json-output-path", type=click.Path(resolve_path=True)) +@click.option("--json-output-path", type=click.Path()) def project_metadata_cmd(project_dir, environments, json_output, json_output_path): with fs.cd(project_dir): config = ProjectConfig.get_instance() diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index 200321f2..9dbd499c 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -24,7 +24,7 @@ from platformio.project.config import ProjectConfig def get_project_dir(): - return fs.normalize_path(os.getcwd()) + return os.getcwd() def is_platformio_project(project_dir=None): diff --git a/platformio/project/options.py b/platformio/project/options.py index 639cefe6..2e13815a 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -114,7 +114,7 @@ def validate_dir(path): path = fs.expanduser(path) if "$" in path: path = expand_dir_templates(path) - return fs.normalize_path(path) + return os.path.abspath(path) def get_default_core_dir(): diff --git a/platformio/remote/cli.py b/platformio/remote/cli.py index 91f5e29d..f9462e0f 100644 --- a/platformio/remote/cli.py +++ b/platformio/remote/cli.py @@ -56,7 +56,7 @@ def remote_agent(): "-d", "--working-dir", envvar="PLATFORMIO_REMOTE_AGENT_DIR", - type=click.Path(file_okay=False, dir_okay=True, writable=True, resolve_path=True), + type=click.Path(file_okay=False, dir_okay=True, writable=True), ) def remote_agent_start(name, share, working_dir): from platformio.remote.client.agent_service import RemoteAgentService @@ -96,9 +96,7 @@ def remote_update(agents, only_check, dry_run): "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=True, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=True, writable=True), ) @click.option("--disable-auto-clean", is_flag=True) @click.option("-r", "--force-remote", is_flag=True) @@ -186,9 +184,7 @@ def remote_run( "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), ) @click.option("-r", "--force-remote", is_flag=True) @click.option("--without-building", is_flag=True) @@ -334,7 +330,7 @@ def device_list(agents, json_output): "-d", "--project-dir", default=os.getcwd, - type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), + type=click.Path(exists=True, file_okay=False, dir_okay=True), ) @click.option( "-e", @@ -343,9 +339,7 @@ def device_list(agents, json_output): ) @click.option( "--sock", - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), ) @click.pass_obj @click.pass_context diff --git a/platformio/run/cli.py b/platformio/run/cli.py index f9f7a07a..ed2a0c7e 100644 --- a/platformio/run/cli.py +++ b/platformio/run/cli.py @@ -47,16 +47,12 @@ except NotImplementedError: "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=True, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=True, writable=True), ) @click.option( "-c", "--project-conf", - type=click.Path( - exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True), ) @click.option( "-j", diff --git a/platformio/system/commands/completion.py b/platformio/system/commands/completion.py index aac68592..5ff73bb1 100644 --- a/platformio/system/commands/completion.py +++ b/platformio/system/commands/completion.py @@ -33,7 +33,7 @@ def system_completion_cmd(): @click.argument("shell", type=click.Choice([t.value for t in ShellType])) @click.option( "--path", - type=click.Path(file_okay=True, dir_okay=False, readable=True, resolve_path=True), + type=click.Path(file_okay=True, dir_okay=False, readable=True), help="Custom installation path of the code to be evaluated by the shell. " "The standard installation path is used by default.", ) @@ -54,7 +54,7 @@ def system_completion_install(shell, path): @click.argument("shell", type=click.Choice([t.value for t in ShellType])) @click.option( "--path", - type=click.Path(file_okay=True, dir_okay=False, readable=True, resolve_path=True), + type=click.Path(file_okay=True, dir_okay=False, readable=True), help="Custom installation path of the code to be evaluated by the shell. " "The standard installation path is used by default.", ) diff --git a/platformio/test/cli.py b/platformio/test/cli.py index d0a6e53a..748580c8 100644 --- a/platformio/test/cli.py +++ b/platformio/test/cli.py @@ -48,16 +48,12 @@ from platformio.test.runners.factory import TestRunnerFactory "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), ) @click.option( "-c", "--project-conf", - type=click.Path( - exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True), ) @click.option("--without-building", is_flag=True) @click.option("--without-uploading", is_flag=True) @@ -83,8 +79,8 @@ from platformio.test.runners.factory import TestRunnerFactory help="A program argument (multiple are allowed)", ) @click.option("--list-tests", is_flag=True) -@click.option("--json-output-path", type=click.Path(resolve_path=True)) -@click.option("--junit-output-path", type=click.Path(resolve_path=True)) +@click.option("--json-output-path", type=click.Path()) +@click.option("--junit-output-path", type=click.Path()) @click.option( "--verbose", "-v", diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index 26089500..29ff20ab 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -642,7 +642,7 @@ def test_googletest_framework(clirunner, tmp_path: Path): pio_test_cmd, [ "-d", - project_dir, + str(project_dir), "-e", "native", "--json-output-path",