Skip to content

Commit 8e561c3

Browse files
committed
Upgrade to latest click 8.3.1
1 parent f00ef57 commit 8e561c3

File tree

4 files changed

+88
-9
lines changed

4 files changed

+88
-9
lines changed

platformio/compat.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,84 @@ def is_proxy_set(socks=False):
146146
continue
147147
return True
148148
return False
149+
150+
151+
def click_launch(url, wait=False, locate=False) -> int:
152+
return _click_open_url(url, wait=wait, locate=locate)
153+
154+
155+
def _click_open_url(
156+
url, wait=False, locate=False
157+
): # pylint: disable=too-many-branches, too-many-return-statements, consider-using-with
158+
"""
159+
Issue https://github.com/pallets/click/issues/2868
160+
Keep in sync with https://github.com/pallets/click/blob/main/src/click/_termui_impl.py
161+
"""
162+
import subprocess
163+
164+
def _unquote_file(url) -> str:
165+
from urllib.parse import unquote
166+
167+
if url.startswith("file://"):
168+
url = unquote(url[7:])
169+
170+
return url
171+
172+
if IS_MACOS:
173+
args = ["open"]
174+
if wait:
175+
args.append("-W")
176+
if locate:
177+
args.append("-R")
178+
args.append(_unquote_file(url))
179+
null = open("/dev/null", "w")
180+
try:
181+
return subprocess.Popen(args, stderr=null).wait()
182+
finally:
183+
null.close()
184+
elif IS_WINDOWS:
185+
if locate:
186+
url = _unquote_file(url)
187+
args = ["explorer", f"/select,{url}"]
188+
else:
189+
args = ["start"]
190+
if wait:
191+
args.append("/WAIT")
192+
args.append("")
193+
args.append(url)
194+
try:
195+
return subprocess.call(args, shell=True)
196+
except OSError:
197+
# Command not found
198+
return 127
199+
elif IS_CYGWIN:
200+
if locate:
201+
url = _unquote_file(url)
202+
args = ["cygstart", os.path.dirname(url)]
203+
else:
204+
args = ["cygstart"]
205+
if wait:
206+
args.append("-w")
207+
args.append(url)
208+
try:
209+
return subprocess.call(args)
210+
except OSError:
211+
# Command not found
212+
return 127
213+
214+
try:
215+
if locate:
216+
url = os.path.dirname(_unquote_file(url)) or "."
217+
else:
218+
url = _unquote_file(url)
219+
c = subprocess.Popen(["xdg-open", url])
220+
if wait:
221+
return c.wait()
222+
return 0
223+
except OSError:
224+
if url.startswith(("http://", "https://")) and not locate and not wait:
225+
import webbrowser
226+
227+
webbrowser.open(url)
228+
return 0
229+
return 1

platformio/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_core_dependencies():
2929
def get_pip_dependencies():
3030
core = [
3131
"bottle == 0.13.*",
32-
"click >=8.0.4, <8.1.8",
32+
"click >=8.0.4, <8.4",
3333
"colorama",
3434
"marshmallow == 3.*",
3535
"pyelftools >=0.27, <1",

platformio/home/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import click
1919

20-
from platformio.compat import IS_WINDOWS
20+
from platformio.compat import IS_WINDOWS, click_launch
2121
from platformio.home.run import run_server
2222
from platformio.package.manager.core import get_core_package_dir
2323

@@ -86,7 +86,7 @@ def cli(port, host, no_open, shutdown_timeout, session_id):
8686
"PlatformIO Home server is already started in another process.", fg="yellow"
8787
)
8888
if not no_open:
89-
click.launch(home_url)
89+
click_launch(home_url)
9090
return
9191

9292
run_server(

platformio/home/rpc/handlers/os.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import shutil
1919
from functools import cmp_to_key
2020

21-
import click
22-
2321
from platformio import fs
2422
from platformio.cache import ContentCache
25-
from platformio.compat import aio_to_thread
23+
from platformio.compat import aio_to_thread, click_launch
2624
from platformio.device.list.util import list_logical_devices
2725
from platformio.home.rpc.handlers.base import BaseRPCHandler
2826
from platformio.http import HTTPSession, ensure_internet_on
@@ -84,15 +82,15 @@ async def request_content(self, uri, data=None, headers=None, cache_valid=None):
8482

8583
@staticmethod
8684
def open_url(url):
87-
return click.launch(url)
85+
return click_launch(url)
8886

8987
@staticmethod
9088
def reveal_file(path):
91-
return click.launch(path, locate=True)
89+
return click_launch(path, locate=True)
9290

9391
@staticmethod
9492
def open_file(path):
95-
return click.launch(path)
93+
return click_launch(path)
9694

9795
@staticmethod
9896
def call_path_module_func(name, args, **kwargs):

0 commit comments

Comments
 (0)