From e6f279bf5d9b52bc45fdf61b11974714da546af3 Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Mon, 28 Dec 2020 11:30:02 +0900 Subject: [PATCH] make backwards compatibility deps optional --- .travis.yml | 2 +- build/compilers.py | 34 ++++++++++++++++++++++++++++------ build/init.py | 5 +++++ build/phonegap.py | 19 +++++++++++++++++-- setup.py | 16 ++++++++++------ 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index da31a421..32f96cb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,7 +59,7 @@ matrix: - nvm install 14 - pip install --upgrade pip - python setup.py bdist_wheel - - pip install dist/*.whl + - pip install `ls dist/*.whl`[compat] script: - cd tests - mkdir css && wq init && wq scss --indir scss --outdir css diff --git a/build/compilers.py b/build/compilers.py index eb85242b..81c8c2e4 100644 --- a/build/compilers.py +++ b/build/compilers.py @@ -3,14 +3,8 @@ import os import json - -import scss as pyScss import logging -import pystache - from .collect import readfiles -import requirejs -from babeljs import transformer as babeljs @wq.command() @@ -26,6 +20,11 @@ def optimize(config): wq.app 2.0. For full control over the compilation process, use `wq start --with-npm` instead. """ + try: + import requirejs + except ImportError: + raise NotInstalled('requirejs') + conf = config.get('optimize', None) if not conf: raise click.UsageError( @@ -55,6 +54,11 @@ def babel(config): Note that this command will be removed in wq.app 2.0 in favor of `wq start --with-npm`. """ + try: + from babeljs import transformer as babeljs + except ImportError: + raise NotInstalled('PyBabeljs') + rconf = config.get('optimize', None) if not rconf: raise click.UsageError( @@ -108,6 +112,11 @@ def scss(**conf): Note: This command will be removed in wq.app 2.0 in favor of Material UI themes. """ + try: + import scss as pyScss + except ImportError: + raise NotInstalled("pyScss") + compiler = pyScss.Scss(scss_opts={'compress': 0}) logging.getLogger("scss").addHandler(logging.StreamHandler()) @@ -168,6 +177,11 @@ def mustache(**conf): Note: This command will be removed in wq.app 2.0 in favor of JSX. """ + try: + import pystache + except ImportError: + raise NotInstalled('pystache') + template = conf['template'] if template is None: return @@ -196,3 +210,11 @@ def mustache(**conf): f = open(conf['output'], 'w') f.write(html) f.close() + + +class NotInstalled(click.ClickException): + def __init__(self, dep): + super().__init__( + "Could not find {}. Install compat dependencies via:" + "\n pip install wq.app[compat]".format(dep) + ) diff --git a/build/init.py b/build/init.py index 394997e4..480d6238 100644 --- a/build/init.py +++ b/build/init.py @@ -2,6 +2,7 @@ from wq.core import wq from os.path import exists, join, dirname from os import symlink, mkdir +from .compilers import NotInstalled @wq.command() @@ -66,6 +67,10 @@ def maybe_symlink(source, dest): maybe_symlink(join(wqpath, 'wq'), join(projpath, 'wq')) if name == "scss" and not exists(join(projpath, 'compass')): # myapp/scss/lib/compass -> compass_stylesheets/stylesheets/compass + try: + import compass_stylesheets # noqa + except ImportError: + raise NotInstalled("compass_stylesheets") import pkg_resources compass = pkg_resources.resource_filename( 'compass_stylesheets', diff --git a/build/phonegap.py b/build/phonegap.py index f43a7d08..94a7ec76 100644 --- a/build/phonegap.py +++ b/build/phonegap.py @@ -1,13 +1,12 @@ -import requests from wq.core import wq import click import os import yaml import json import shutil -import pystache from .icons import icons, SIZES import time +from .compilers import NotInstalled @wq.command() @@ -55,6 +54,16 @@ def phonegap(ctx, config, version, **conf): React Native and/or Expo, together with @wq/react and @wq/material. """ + try: + import requests # noqa + except ImportError: + raise NotInstalled('requests') + + try: + import pystache # noqa + except ImportError: + raise NotInstalled('pystache') + click.echo( "Warning: PhoneGap Build is offline; this command will likely fail." ) @@ -117,6 +126,8 @@ def phonegap(ctx, config, version, **conf): def create_zipfile(directory, source, version, context, icon=None, splash=None, config_xml=None, index_html=None): + import pystache + folder = os.path.join(directory, 'build') if os.path.exists(folder): shutil.rmtree(folder) @@ -198,6 +209,8 @@ def get_height(size): def upload_zipfile(directory, filename, token, pgb_api): + import requests + pgb_url = pgb_api + "{path}?auth_token={token}" app_id = get_pgb_config(directory, 'app_id') if app_id: @@ -268,6 +281,8 @@ def check_error(response): def get_token(directory, token_url): + import requests + token = get_pgb_config(directory, 'token') if token: return token diff --git a/setup.py b/setup.py index d8155328..2913d06a 100644 --- a/setup.py +++ b/setup.py @@ -77,15 +77,19 @@ def create_wq_namespace(): include_package_data=True, install_requires=[ 'wq.core', - 'pyScss>=1.3', - 'compass-stylesheets==0.12.6', 'PyYAML', - 'requests', - 'pystache', 'Pillow', - 'requirejs>=0.2.0', - 'PyBabeljs', ], + extras_require={ + 'compat': [ + 'pyScss>=1.3', + 'compass-stylesheets==0.12.6', + 'requests', + 'pystache', + 'requirejs>=0.2.0', + 'PyBabeljs', + ] + }, namespace_packages=['wq'], description=LONG_DESCRIPTION.strip(), long_description=readme(),