Skip to content

Commit

Permalink
make backwards compatibility deps optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Dec 28, 2020
1 parent 5363e07 commit e6f279b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 28 additions & 6 deletions build/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
5 changes: 5 additions & 0 deletions build/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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',
Expand Down
19 changes: 17 additions & 2 deletions build/phonegap.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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."
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e6f279b

Please sign in to comment.