Skip to content

Commit 41bd751

Browse files
committed
Implemente automatic installation of missing dependencies when utilizing a SOCKS proxy // Resolve platformio#4822
1 parent c74c977 commit 41bd751

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test-driven methodologies, and modern toolchains for unrivaled success.
2626
* Upgraded the build engine to the latest version of SCons (4.6.0) to improve build performance, reliability, and compatibility with other tools and systems (`release notes <https://github.com/SCons/scons/releases/tag/4.6.0>`__)
2727
* Enhanced the handling of built-in variables in |PIOCONF| during |INTERPOLATION| (`issue #4695 <https://github.com/platformio/platformio-core/issues/4695>`_)
2828
* Enhanced PIP dependency declarations for improved reliability and extended support to include Python 3.6 (`issue #4819 <https://github.com/platformio/platformio-core/issues/4819>`_)
29+
* Implemented automatic installation of missing dependencies when utilizing a SOCKS proxy (`issue #4822 <https://github.com/platformio/platformio-core/issues/4822>`_)
2930
* Implemented a fail-safe mechanism to terminate a debugging session if an unknown CLI option is passed (`issue #4699 <https://github.com/platformio/platformio-core/issues/4699>`_)
3031
* Rectified an issue where ``${platformio.name}`` erroneously represented ``None`` as the default `project name <https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/generic/name.html>`__ (`issue #4717 <https://github.com/platformio/platformio-core/issues/4717>`_)
3132
* Resolved an issue where the ``COMPILATIONDB_INCLUDE_TOOLCHAIN`` setting was not correctly applying to private libraries (`issue #4762 <https://github.com/platformio/platformio-core/issues/4762>`_)

platformio/http.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import json
16-
import os
1716
import socket
1817
from urllib.parse import urljoin
1918

@@ -23,6 +22,7 @@
2322
from platformio import __check_internet_hosts__, app, util
2423
from platformio.cache import ContentCache, cleanup_content_cache
2524
from platformio.exception import PlatformioException, UserSideException
25+
from platformio.pipdeps import is_proxy_set
2626

2727
__default_requests_timeout__ = (10, None) # (connect, read)
2828

@@ -191,9 +191,7 @@ def _internet_on():
191191
socket.setdefaulttimeout(timeout)
192192
for host in __check_internet_hosts__:
193193
try:
194-
for var in ("HTTP_PROXY", "HTTPS_PROXY"):
195-
if not os.getenv(var) and not os.getenv(var.lower()):
196-
continue
194+
if is_proxy_set():
197195
requests.get("http://%s" % host, allow_redirects=False, timeout=timeout)
198196
return True
199197
# try to resolve `host` for both AF_INET and AF_INET6, and then try to connect

platformio/pipdeps.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import platform
1617
import sys
1718

@@ -26,7 +27,7 @@ def get_pip_dependencies():
2627
"marshmallow == 3.*",
2728
"pyelftools == 0.30",
2829
"pyserial == 3.5.*", # keep in sync "device/monitor/terminal.py"
29-
"requests == 2.*",
30+
"requests%s == 2.*" % ("[socks]" if is_proxy_set(socks=True) else ""),
3031
"semantic_version == 2.10.*",
3132
"tabulate == 0.*",
3233
]
@@ -59,3 +60,12 @@ def get_pip_dependencies():
5960
pass
6061

6162
return core + home + extra
63+
64+
65+
def is_proxy_set(socks=False):
66+
for var in ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"):
67+
value = os.getenv(var, os.getenv(var.lower()))
68+
if not value or (socks and not value.startswith("socks5://")):
69+
continue
70+
return True
71+
return False

0 commit comments

Comments
 (0)