From 8c66352994c234f64dbcdae5deeb09b56e28e0f3 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 20 Jan 2022 11:19:30 +0100 Subject: [PATCH] Fixed wrong path (#4158) * Fixed wrong path On linux, "Documents" doesn't have to be the right folder. It depends on the language selected when installing the operating system. * Refactor code * Update HISTORY.rst Co-authored-by: Ivan Kravets --- HISTORY.rst | 3 ++- platformio/project/helpers.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 6992470d..e463857e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,7 +12,8 @@ PlatformIO Core 5 ~~~~~~~~~~~~~~~~~~ - Improved support for private packages in `PlatformIO Registry `__ -- Improved checking of available Internet connection for IPv6-only workstations (`pull #4151 `_) +- Improved checking of available Internet connection for IPv6-only workstations (`pull #4151 `_) +- Better detecting of default PlatformIO project directory on Linux OS (`pull #4158 `_) - Respect disabling debugging server from "platformio.ini" passing an empty value to the `debug_server `__ option 5.2.4 (2021-12-15) diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index 2736cae8..73945185 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -14,12 +14,13 @@ import json import os +import subprocess from hashlib import sha1 from click.testing import CliRunner from platformio import __version__, exception, fs -from platformio.compat import IS_WINDOWS, hashlib_encode_data +from platformio.compat import IS_MACOS, IS_WINDOWS, hashlib_encode_data from platformio.project.config import ProjectConfig @@ -75,7 +76,13 @@ def get_default_projects_dir(): ctypes.windll.shell32.SHGetFolderPathW(None, 5, None, 0, buf) docs_dir = buf.value except: # pylint: disable=bare-except - pass + if not IS_MACOS: + try: + docs_dir = subprocess.check_output( + ["xdg-user-dir", "DOCUMENTS"] + ).decode("utf-8") + except FileNotFoundError: # command not found + pass return os.path.join(docs_dir, "PlatformIO", "Projects")