Skip to content

Commit

Permalink
Automatically build contrib-pysite package on a target machine wh…
Browse files Browse the repository at this point in the history
…en pre-built package is not compatible // Resolve #3482
  • Loading branch information
ivankravets committed Apr 29, 2020
1 parent 961049c commit 5f79ab3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Release Notes
PlatformIO Core 4
-----------------

4.3.4 (2020-??-??)
~~~~~~~~~~~~~~~~~~

* Automatically build ``contrib-pysite`` package on a target machine when pre-built package is not compatible (`issue #3482 <https://github.com/platformio/platformio-core/issues/3482>`_)

4.3.3 (2020-04-28)
~~~~~~~~~~~~~~~~~~

Expand Down
13 changes: 2 additions & 11 deletions platformio/commands/home/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

from platformio import exception
from platformio.compat import WINDOWS
from platformio.managers.core import (
build_contrib_pysite_deps,
get_core_package_dir,
inject_contrib_pysite,
)
from platformio.managers.core import get_core_package_dir, inject_contrib_pysite


@click.command("home", short_help="PIO Home")
Expand Down Expand Up @@ -55,12 +51,7 @@ def cli(port, host, no_open, shutdown_timeout):
# import contrib modules
inject_contrib_pysite()

try:
from autobahn.twisted.resource import WebSocketResource
except: # pylint: disable=bare-except
build_contrib_pysite_deps(get_core_package_dir("contrib-pysite"))
from autobahn.twisted.resource import WebSocketResource

from autobahn.twisted.resource import WebSocketResource
from twisted.internet import reactor
from twisted.web import server
from twisted.internet.error import CannotListenError
Expand Down
2 changes: 1 addition & 1 deletion platformio/commands/remote/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cli(ctx, agent):
"https://docs.platformio.org/page/core/installation.html"
)
ctx.obj = agent
inject_contrib_pysite()
inject_contrib_pysite(verify_openssl=True)


@cli.group("agent", short_help="Start a new agent or list active")
Expand Down
27 changes: 19 additions & 8 deletions platformio/managers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,26 @@ def update_core_packages(only_check=False, silent=False):
return True


def inject_contrib_pysite():
from site import addsitedir # pylint: disable=import-outside-toplevel
def inject_contrib_pysite(verify_openssl=False):
# pylint: disable=import-outside-toplevel
from site import addsitedir

contrib_pysite_dir = get_core_package_dir("contrib-pysite")
if contrib_pysite_dir in sys.path:
return
return True
addsitedir(contrib_pysite_dir)
sys.path.insert(0, contrib_pysite_dir)

if not verify_openssl:
return True

try:
from OpenSSL import SSL # pylint: disable=import-error,unused-import
except: # pylint: disable=bare-except
build_contrib_pysite_deps(get_core_package_dir("contrib-pysite"))

return True


def build_contrib_pysite_deps(target_dir):
if os.path.isdir(target_dir):
Expand Down Expand Up @@ -146,11 +157,11 @@ def get_contrib_pysite_deps():
sys_type = util.get_systype()
py_version = "%d%d" % (sys.version_info.major, sys.version_info.minor)

twisted_version = "19.7.0"
twisted_version = "19.10.0" if PY2 else "20.3.0"
result = [
"twisted == %s" % twisted_version,
"autobahn == 19.10.1",
"json-rpc == 1.12.1",
"autobahn == 20.4.3",
"json-rpc == 1.13.0",
]

# twisted[tls], see setup.py for %twisted_version%
Expand All @@ -159,12 +170,12 @@ def get_contrib_pysite_deps():
)

# zeroconf
if sys.version_info.major < 3:
if PY2:
result.append(
"https://github.com/ivankravets/python-zeroconf/" "archive/pio-py27.zip"
)
else:
result.append("zeroconf == 0.23.0")
result.append("zeroconf == 0.26.0")

if "windows" in sys_type:
result.append("pypiwin32 == 223")
Expand Down

0 comments on commit 5f79ab3

Please sign in to comment.