Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PEP8 fixes automated with pep8ify
  • Loading branch information
mfitzp committed Sep 8, 2015
1 parent a973a73 commit 90e0601
Show file tree
Hide file tree
Showing 53 changed files with 112 additions and 83 deletions.
12 changes: 5 additions & 7 deletions docs/conf.py
Expand Up @@ -20,16 +20,17 @@

class Mock(MagicMock):
__all__ = []

def __init__(self, *args, **kwargs):
super(Mock, self).__init__()

@classmethod
def __getattr__(cls, name):
if name in ('__file__', '__path__'):
return os.devnull
else:
return Mock()

@classmethod
def __setattr__(*args, **kwargs):
pass
Expand All @@ -52,14 +53,13 @@ def __getitem__(self, *args, **kwargs):
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()


os.environ['DJANGO_SETTINGS_MODULE'] = 'wooey.docs_settings'

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..') )
sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------

Expand All @@ -69,7 +69,7 @@ def __getitem__(self, *args, **kwargs):
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc','sphinx.ext.viewcode']
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -219,8 +219,6 @@ def __getitem__(self, *args, **kwargs):

# Output file base name for HTML help builder.
htmlhelp_basename = 'Wooeydoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -12,7 +12,7 @@
version='0.2.6',
packages=find_packages(),
scripts=['scripts/wooify'],
entry_points={'console_scripts': ['wooify = wooey.backend.command_line:bootstrap',]},
entry_points={'console_scripts': ['wooify = wooey.backend.command_line:bootstrap', ]},
install_requires = ['Django>=1.6', 'django-autoslug', 'django-celery', 'six', 'clinto>=0.1.1'],
include_package_data=True,
description='A Django app which creates a web GUI and task interface for argparse scripts',
Expand All @@ -33,4 +33,3 @@
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)

3 changes: 2 additions & 1 deletion tests/test_project.py
Expand Up @@ -16,6 +16,7 @@
env['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(WOOEY_TEST_PROJECT_NAME)
env['TESTING'] = 'True'


class TestProject(TestCase):
def setUp(self):
os.chdir(BASE_DIR)
Expand All @@ -37,4 +38,4 @@ def test_bootstrap(self):
# the project already exists
proc = subprocess.Popen([PYTHON_INTERPRETTER, WOOEY_SCRIPT_PATH, '-p', WOOEY_TEST_PROJECT_NAME])
stdout, stderr = proc.communicate()
self.assertEqual(proc.returncode, 1, stderr)
self.assertEqual(proc.returncode, 1, stderr)
8 changes: 8 additions & 0 deletions wooey/admin.py
Expand Up @@ -5,6 +5,7 @@

from .models import Script, ScriptVersion, ScriptGroup, ScriptParameter, WooeyJob, ScriptParameterGroup, WooeyFile


class ScriptVersionForm(ModelForm):
class Meta:
model = ScriptVersion
Expand All @@ -16,29 +17,36 @@ def clean(self):
current_defaults = ScriptVersion.objects.filter(script=cleaned['script'], default_version=True)
current_defaults.update(default_version=False)


class JobAdmin(ModelAdmin):
list_display = ('user', 'job_name', 'script_version', 'status', 'created_date')


class ScriptVersionInline(TabularInline):
model = ScriptVersion
extra = 0
form = ScriptVersionForm


class ScriptAdmin(ModelAdmin):
list_display = ('script_name', 'script_group', 'is_active')
inlines = [
ScriptVersionInline
]


class ParameterAdmin(ModelAdmin):
list_display = ('script_version', 'parameter_group', 'short_param')


class GroupAdmin(ModelAdmin):
list_display = ('group_name', 'is_active')


class ParameterGroupAdmin(ModelAdmin):
list_display = ('script_version', 'group_name')


class FileAdmin(ModelAdmin):
pass

Expand Down
1 change: 1 addition & 0 deletions wooey/apps.py
Expand Up @@ -6,6 +6,7 @@
except ImportError:
AppConfig = object


class WooeyConfig(AppConfig):
name = 'wooey'
verbose_name = 'Wooey'
Expand Down
7 changes: 5 additions & 2 deletions wooey/backend/command_line.py
Expand Up @@ -7,14 +7,16 @@
import wooey
from .. import django_compat


def which(pgm):
# from http://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command
path=os.getenv('PATH')
for p in path.split(os.path.pathsep):
p=os.path.join(p,pgm)
p=os.path.join(p, pgm)
if os.path.exists(p) and os.access(p, os.X_OK):
return p


def walk_dir(templates, dest, filter=None):
l = []
for root, folders, files in os.walk(templates):
Expand All @@ -25,6 +27,7 @@ def walk_dir(templates, dest, filter=None):
l.append((os.path.join(root, filename), os.path.join(dest, relative_dir)))
return l


def bootstrap(env=None, cwd=None):
if env is None:
env = os.environ
Expand Down Expand Up @@ -89,4 +92,4 @@ def bootstrap(env=None, cwd=None):
subprocess.call(['python', os.path.join(project_root, 'manage.py'), 'collectstatic', '--noinput'], env=env)
sys.stdout.write("Please enter the project directory {0}, and run python manage.py createsuperuser and"
" python manage.py runserver to start. The admin can be found at localhost:8000/admin. You may also want to set your "
"DJANGO_SETTINGS_MODULE environment variable to {0}.settings \n".format(project_name))
"DJANGO_SETTINGS_MODULE environment variable to {0}.settings \n".format(project_name))
15 changes: 9 additions & 6 deletions wooey/backend/utils.py
Expand Up @@ -44,6 +44,7 @@ def get_storage(local=True):
storage = default_storage
return storage


def purge_output(job=None):
from ..models import WooeyFile
# cleanup the old files, we need to be somewhat aggressive here.
Expand All @@ -60,6 +61,7 @@ def purge_output(job=None):
if local_storage.exists(path):
local_storage.delete(path)


def get_job_commands(job=None):
script_version = job.script_version
com = [sys.executable] if sys.executable else []
Expand Down Expand Up @@ -113,12 +115,12 @@ def get_form_groups(script_version=None, pk=None, initial_dict=None, render_fn=N
from ..forms.factory import DJ_FORM_FACTORY
return DJ_FORM_FACTORY.get_group_forms(script_version=script_version, pk=pk, initial_dict=initial_dict, render_fn=render_fn)


def reset_form_factory(script_version=None):
from ..forms.factory import DJ_FORM_FACTORY
DJ_FORM_FACTORY.reset_forms(script_version=script_version)



def validate_form(form=None, data=None, files=None):
form.add_wooey_fields()
form.data = data if data is not None else {}
Expand Down Expand Up @@ -163,13 +165,13 @@ def get_storage_object(path, local=False):
obj.path = storage.path(path)
return obj


def add_wooey_script(script_version=None, script_path=None, group=None):
# There is a class called 'Script' which contains the general information about a script. However, that is not where the file details
# of the script lie. That is the ScriptVersion model. This allows the end user to tag a script as a favorite/etc. and set
# information such as script descriptions/names that do not constantly need to be updated with every version change. Thus,
# a ScriptVersion stores the file info and such.
from ..models import Script, ScriptGroup, ScriptParameter, ScriptParameterGroup, ScriptVersion

# if we are adding through the admin, at this point the file will be saved already and this method will be receiving
# the scriptversion object. Otherwise, we are adding through the managementment command. In this case, the file will be
# a location and we need to setup the Script and ScriptVersion in here.
Expand Down Expand Up @@ -293,6 +295,7 @@ def add_wooey_script(script_version=None, script_path=None, group=None):
parameter_group=param_group)
return {'valid': True, 'errors': None, 'script': script_version}


def valid_user(obj, user):
ret = {'valid': False, 'error': '', 'display': ''}
from ..models import Script
Expand All @@ -314,6 +317,7 @@ def valid_user(obj, user):
ret['display'] = 'disabled' if wooey_settings.WOOEY_SHOW_LOCKED_SCRIPTS else 'hide'
return ret


def mkdirs(path):
try:
os.makedirs(path)
Expand Down Expand Up @@ -367,7 +371,6 @@ def test_delimited(filepath):
# ? this might not be a great idea for massive files
if len(rows) > 10:
rows = rows[:5] + [None] + rows[-5:]

# FIXME: This should be more intelligent:
# for small files (<1000 rows?) we should take top and bottom preview 10
# for large files we should give up and present top 10 (11)
Expand Down Expand Up @@ -406,7 +409,7 @@ def test_fastx(filepath):
sequences[header] = ''.join(seq)
if sequences:
rows = []
[rows.extend([i, v]) for i,v in six.iteritems(sequences)]
[rows.extend([i, v]) for i, v in six.iteritems(sequences)]
return True, rows
return False, None

Expand Down Expand Up @@ -570,10 +573,10 @@ def get_query(query_string, search_fields):
search fields.
"""

query = None # Query to search for every search term
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
Expand Down
1 change: 1 addition & 0 deletions wooey/conf/project_template/middleware.py
Expand Up @@ -2,6 +2,7 @@
import traceback
import sys


class ProcessExceptionMiddleware(object):
def process_response(self, request, response):
if response.status_code != 200:
Expand Down
3 changes: 0 additions & 3 deletions wooey/conf/project_template/settings/user_settings.py
@@ -1,6 +1,5 @@
from os import environ
from .wooey_settings import *

# This file is where the user can override and customize their installation of wooey

# Wooey Apps - add additional apps here after the initial install (remember to follow everything by a comma)
Expand Down Expand Up @@ -35,7 +34,6 @@
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# the url mapping
STATIC_URL = '/static/'

## Here is a setup example for production servers

## A postgres database -- for multiple users a sqlite based database is asking for trouble
Expand Down Expand Up @@ -116,5 +114,4 @@
# STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'wooey.wooeystorage.CachedS3BotoStorage'
# WOOEY_EPHEMERAL_FILES = True


AUTHENTICATION_BACKEND = 'django.contrib.auth.backends.ModelBackend'
3 changes: 3 additions & 0 deletions wooey/django_compat.py
Expand Up @@ -11,11 +11,13 @@
import json
from django.http import HttpResponse


class JsonResponse(HttpResponse):
"""
JSON response
# from https://gist.github.com/philippeowagner/3179eb475fe1795d6515
"""

def __init__(self, content, mimetype='application/json', status=None, content_type=None, **kwargs):
super(JsonResponse, self).__init__(
content=json.dumps(content),
Expand All @@ -34,6 +36,7 @@ def __init__(self, content, mimetype='application/json', status=None, content_ty
else:
from django.template import Template


class Engine(object):
@staticmethod
def from_string(code):
Expand Down
2 changes: 1 addition & 1 deletion wooey/forms/config.py
@@ -1,2 +1,2 @@
WOOEY_MULTI_WIDGET_ATTR = 'data-wooey-multiple'
WOOEY_MULTI_WIDGET_ANCHOR = 'wooey-multi-input'
WOOEY_MULTI_WIDGET_ANCHOR = 'wooey-multi-input'
4 changes: 2 additions & 2 deletions wooey/forms/factory.py
Expand Up @@ -32,7 +32,7 @@ def render(name, values, attrs=None):
# build the attribute dict
data_attrs = flatatt(appender_data_dict if appender_data_dict is not None else {})
pieces.append(format_html('<a href="#{anchor}"{data}><span class="glyphicon glyphicon-plus"></span></a>', anchor=config.WOOEY_MULTI_WIDGET_ANCHOR
,data=data_attrs))
, data=data_attrs))
return mark_safe('\n'.join(pieces))
return render

Expand Down Expand Up @@ -94,7 +94,7 @@ def get_field(param, initial=None):
if not isinstance(initial, (list, tuple)):
initial = [initial]
initial = [os.path.split(i.name)[1] for i in initial]
elif initial is not None and list(filter(None, initial)): # for python3, we need to evaluate the filter object
elif initial is not None and list(filter(None, initial)): # for python3, we need to evaluate the filter object
if isinstance(initial, (list, tuple)):
initial = [utils.get_storage_object(value) if not hasattr(value, 'path') else value for value in initial if value is not None]
else:
Expand Down
1 change: 0 additions & 1 deletion wooey/forms/scripts.py
Expand Up @@ -9,4 +9,3 @@ def add_wooey_fields(self):
# form rendering
self.fields['job_name'] = forms.CharField()
self.fields['job_description'] = forms.CharField(required=False)

2 changes: 1 addition & 1 deletion wooey/management/commands/addscript.py
Expand Up @@ -23,7 +23,7 @@ def handle(self, *args, **options):
script = options.get('script')
if not script:
if len(args):
script = args[0]
script = args[0]
else:
raise CommandError('You must provide a script path or directory containing scripts.')
if not os.path.exists(script):
Expand Down
1 change: 1 addition & 0 deletions wooey/migrations/0009_script_versioning.py
Expand Up @@ -4,6 +4,7 @@
from django.db import models, migrations
import wooey.models.mixins


class Migration(migrations.Migration):

dependencies = [
Expand Down
3 changes: 2 additions & 1 deletion wooey/migrations/0010_script_versioning_data_migration.py
Expand Up @@ -3,6 +3,7 @@

from django.db import models, migrations


def make_script_versions(apps, schema_editor):
Script = apps.get_model("wooey", "Script")
ScriptVersion = apps.get_model("wooey", "ScriptVersion")
Expand All @@ -20,7 +21,7 @@ def make_script_versions(apps, schema_editor):
for i, v in enumerate(ordered_scripts):
script = v[1]
version_kwargs = {'script_version': '1', 'script_iteration': script.script_version,
'script_path': script.script_path, 'script': last_script,}
'script_path': script.script_path, 'script': last_script, }
if v[1] == last_script:
version_kwargs.update({'default_version': True})
script_version = ScriptVersion(**version_kwargs)
Expand Down
1 change: 0 additions & 1 deletion wooey/migrations/0012_wooeyjob_uuid.py
Expand Up @@ -20,4 +20,3 @@ class Migration(migrations.Migration):
field=models.CharField(default=uuid.uuid4, unique=False, max_length=255),
),
]

1 change: 0 additions & 1 deletion wooey/migrations/0013_wooeyjob_uuid_populate.py
Expand Up @@ -22,4 +22,3 @@ class Migration(migrations.Migration):
# Set the uuids for existing records
migrations.RunPython(gen_uuid),
]

1 change: 0 additions & 1 deletion wooey/migrations/0014_wooeyjob_uuid_finalise.py
Expand Up @@ -19,4 +19,3 @@ class Migration(migrations.Migration):
field=models.CharField(default=uuid.uuid4, unique=True, max_length=255),
),
]

1 change: 0 additions & 1 deletion wooey/models/__init__.py
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from .core import *
from .favorite import *

0 comments on commit 90e0601

Please sign in to comment.