diff --git a/platformio/exception.py b/platformio/exception.py index 5c8f93a6..5f7abe7f 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -227,3 +227,10 @@ class CygwinEnvDetected(PlatformioException): MESSAGE = "PlatformIO does not work within Cygwin environment. "\ "Use native Terminal instead." + + +class ZeroconfIsNotInstalled(PlatformioException): + + MESSAGE = "Python multicast DNS service discovery library has not been "\ + "installed automatically. Please open terminal and run \n"\ + "> pip install zeroconf" diff --git a/platformio/util.py b/platformio/util.py index 0669aaad..7ab4ed7a 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -32,7 +32,6 @@ from time import sleep, time import click import requests -import zeroconf from platformio import __apiurl__, __version__, exception @@ -493,6 +492,10 @@ get_logicaldisks = lambda: [{ def get_mdns_services(): + try: + import zeroconf + except ImportError: + raise exception.ZeroconfIsNotInstalled() class mDNSListener(object): diff --git a/setup.py b/setup.py index 11476caa..b0f442e0 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import subprocess +import sys +from os.path import normpath from setuptools import find_packages, setup from platformio import (__author__, __description__, __email__, __license__, @@ -25,9 +28,21 @@ install_requires = [ "lockfile>=0.9.1,<0.13", "pyserial>=3,<4,!=3.3", "requests>=2.4.0,<3", - "semantic_version>=2.5.0,<3", - "zeroconf<=0.19.1" + "semantic_version>=2.5.0,<3" ] +zeroconf_requirement = "zeroconf<=0.19.1" + +try: + import zeroconf # pylint: disable=unused-import +except ImportError: + try: + subprocess.check_call([ + normpath(sys.executable), "-m", "pip", "install", + zeroconf_requirement + ]) + install_requires.append(zeroconf_requirement) + except: # pylint: disable=bare-except + pass setup( name=__title__,