Skip to content

Commit

Permalink
black --line-length=79
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Sep 22, 2020
1 parent b5f4da9 commit 757a7b4
Show file tree
Hide file tree
Showing 51 changed files with 2,272 additions and 710 deletions.
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ repos:
rev: 20.8b1
hooks:
- id: black
args: [--target-version=py35]
args: [
--target-version=py35,
# default black line length is 88
--line-length=79,
]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args: [
# default black line length is 88
--max-line-length=88,
# Conflicts with black: E203 whitespace before ':'
--extend-ignore=E203,
]
72 changes: 54 additions & 18 deletions omero/plugins/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def wrapper(self, *args, **kwargs):
mismatch = False
if args[0].system:
self.ctx.die(
683, "ERROR: --system is no longer supported, " "see --help"
683,
"ERROR: --system is no longer supported, " "see --help",
)
if settings.APPLICATION_SERVER in ("development",):
mismatch = True
Expand Down Expand Up @@ -155,7 +156,9 @@ def _configure(self, parser):
self._add_diagnostics(parser, sub)

parser.add(sub, self.help, "Extended help")
start = parser.add(sub, self.start, "Primary start for the OMERO.web server")
start = parser.add(
sub, self.start, "Primary start for the OMERO.web server"
)
parser.add(sub, self.stop, "Stop the OMERO.web server")
restart = parser.add(sub, self.restart, "Restart the OMERO.web server")
parser.add(sub, self.status, "Status for the OMERO.web server")
Expand Down Expand Up @@ -199,7 +202,9 @@ def _configure(self, parser):
nginx_group = config.add_argument_group(
"Nginx arguments", "Optional arguments for nginx templates."
)
nginx_group.add_argument("--http", type=int, help="HTTP port for web server")
nginx_group.add_argument(
"--http", type=int, help="HTTP port for web server"
)
nginx_group.add_argument(
"--servername",
type=str,
Expand All @@ -213,7 +218,9 @@ def _configure(self, parser):
help="Maximum allowed size of the client request body."
"Default: 0 (disabled)",
)
nginx_group.add_argument("--system", action="store_true", help=SUPPRESS)
nginx_group.add_argument(
"--system", action="store_true", help=SUPPRESS
)

parser.add(
sub,
Expand Down Expand Up @@ -250,22 +257,29 @@ def _configure(self, parser):
call.add_argument("arg", nargs="*")

enableapp = parser.add(
sub, self.enableapp, "Developer use: runs enable.py and then syncdb"
sub,
self.enableapp,
"Developer use: runs enable.py and then syncdb",
)
enableapp.add_argument("appname", nargs="*")

parser.add(
sub,
self.gateway,
"Developer use: Loads the blitz gateway into a Python" " interpreter",
"Developer use: Loads the blitz gateway into a Python"
" interpreter",
)

@config_required
def help(self, args, settings):
"""Return extended help"""
try:
CONFIG_TABLE_FMT = " %-35.35s %-8s %r\n"
CONFIG_TABLE = CONFIG_TABLE_FMT % ("Key", "Default?", "Current value")
CONFIG_TABLE = CONFIG_TABLE_FMT % (
"Key",
"Default?",
"Current value",
)

for key in sorted(settings.CUSTOM_SETTINGS_MAPPINGS):
(
Expand All @@ -276,10 +290,15 @@ def help(self, args, settings):
using_default,
) = settings.CUSTOM_SETTINGS_MAPPINGS[key]
global_value = getattr(settings, global_name, "(unset)")
CONFIG_TABLE += CONFIG_TABLE_FMT % (key, using_default, global_value)
CONFIG_TABLE += CONFIG_TABLE_FMT % (
key,
using_default,
global_value,
)
except Exception:
CONFIG_TABLE = (
"INVALID OR LOCKED CONFIGURATION!" " Cannot display default values"
"INVALID OR LOCKED CONFIGURATION!"
" Cannot display default values"
)

self.ctx.err(LONGHELP % CONFIG_TABLE)
Expand Down Expand Up @@ -352,7 +371,9 @@ def config(self, args, settings):
)

if settings.APPLICATION_SERVER not in settings.WSGI_TYPES:
self.ctx.die(679, "Web template configuration requires" "wsgi or wsgi-tcp.")
self.ctx.die(
679, "Web template configuration requires" "wsgi or wsgi-tcp."
)

template_file = "%s.conf.template" % server
c = bytes_to_native_str(
Expand All @@ -370,7 +391,8 @@ def enableapp(self, args, settings):
apps = [
x.name
for x in filter(
lambda x: x.isdir() and (x / "scripts" / "enable.py").exists(),
lambda x: x.isdir()
and (x / "scripts" / "enable.py").exists(),
location.listdir(unreadable_as_empty=True),
)
]
Expand All @@ -379,10 +401,15 @@ def enableapp(self, args, settings):
settings.INSTALLED_APPS,
)
apps = filter(lambda x: x not in iapps, apps)
self.ctx.out("[enableapp] available apps:\n - " + "\n - ".join(apps) + "\n")
self.ctx.out(
"[enableapp] available apps:\n - " + "\n - ".join(apps) + "\n"
)
else:
for app in args.appname:
args = [sys.executable, location / app / "scripts" / "enable.py"]
args = [
sys.executable,
location / app / "scripts" / "enable.py",
]
rv = self.ctx.call(args, cwd=location)
if rv != 0:
self.ctx.die(121, "Failed to enable '%s'.\n" % app)
Expand Down Expand Up @@ -416,7 +443,9 @@ def call(self, args):
scriptname = " ".join(scriptname[1:])
else:
scriptname = scriptname[0]
cargs.extend([location / appname / "scripts" / scriptname] + args.arg)
cargs.extend(
[location / appname / "scripts" / scriptname] + args.arg
)
os.environ["DJANGO_SETTINGS_MODULE"] = "omeroweb.settings"
self.set_environ()
self.ctx.call(cargs, cwd=location)
Expand All @@ -436,7 +465,8 @@ def collectstatic(self, settings):
def clearsessions(self, args, settings):
"""Clean out expired sessions."""
self.ctx.out(
"Clearing expired sessions. This may take some time... ", newline=False
"Clearing expired sessions. This may take some time... ",
newline=False,
)
location = self._get_python_dir() / "omeroweb"
cmd = [sys.executable, "manage.py", "clearsessions"]
Expand Down Expand Up @@ -516,7 +546,9 @@ def _build_run_cmd(self, settings):
if settings.WSGI_WORKER_CLASS == "sync":
cmd += " --threads %d" % settings.WSGI_THREADS
elif settings.WSGI_WORKER_CLASS == "gevent":
cmd += " --worker-connections %d" % settings.WSGI_WORKER_CONNECTIONS
cmd += (
" --worker-connections %d" % settings.WSGI_WORKER_CONNECTIONS
)
cmd += " --worker-class %s " % settings.WSGI_WORKER_CLASS
else:
self.ctx.die(
Expand Down Expand Up @@ -658,7 +690,9 @@ def status(self, args, settings):
elif deploy in (settings.WSGI,):
self.ctx.err(APACHE_MOD_WSGI_ERR)
elif deploy in (settings.DEVELOPMENT,):
self.ctx.err("DEVELOPMENT: You will have to kill processes by hand!")
self.ctx.err(
"DEVELOPMENT: You will have to kill processes by hand!"
)
else:
self.ctx.err(
"Invalid APPLICATION_SERVER "
Expand Down Expand Up @@ -696,7 +730,9 @@ def stop(self, args, settings):
self.ctx.err(APACHE_MOD_WSGI_ERR)
return False
elif deploy in settings.DEVELOPMENT:
self.ctx.err("DEVELOPMENT: You will have to kill processes by hand!")
self.ctx.err(
"DEVELOPMENT: You will have to kill processes by hand!"
)
return False
else:
self.ctx.err(
Expand Down
3 changes: 2 additions & 1 deletion omeroweb/api/api_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def get_wellsample_indices(conn, plate_id=None, plateacquisition_id=None):
ctx.setOmeroGroup(-1)
params = ParametersI()
query = (
"select minIndex(ws), maxIndex(ws) from Well well " "join well.wellSamples ws"
"select minIndex(ws), maxIndex(ws) from Well well "
"join well.wellSamples ws"
)
if plate_id is not None:
query += " where well.plate.id=:plate_id "
Expand Down
6 changes: 5 additions & 1 deletion omeroweb/api/api_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"""Settings for the OMERO JSON api app."""

import sys
from omeroweb.settings import process_custom_settings, report_settings, str_slash
from omeroweb.settings import (
process_custom_settings,
report_settings,
str_slash,
)

# load settings
API_SETTINGS_MAPPING = {
Expand Down
52 changes: 36 additions & 16 deletions omeroweb/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,36 @@

api_versions = url(r"^$", views.api_versions, name="api_versions")

api_base = url(r"^v(?P<api_version>%s)/$" % versions, views.api_base, name="api_base")
api_base = url(
r"^v(?P<api_version>%s)/$" % versions, views.api_base, name="api_base"
)
"""
GET various urls listed below
"""

api_token = url(
r"^v(?P<api_version>%s)/token/$" % versions, views.api_token, name="api_token"
r"^v(?P<api_version>%s)/token/$" % versions,
views.api_token,
name="api_token",
)
"""
GET the CSRF token for this session. Needs to be included
in header with all POST, PUT & DELETE requests
"""

api_servers = url(
r"^v(?P<api_version>%s)/servers/$" % versions, views.api_servers, name="api_servers"
r"^v(?P<api_version>%s)/servers/$" % versions,
views.api_servers,
name="api_servers",
)
"""
GET list of available OMERO servers to login to.
"""

api_login = url(
r"^v(?P<api_version>%s)/login/$" % versions, LoginView.as_view(), name="api_login"
r"^v(?P<api_version>%s)/login/$" % versions,
LoginView.as_view(),
name="api_login",
)
"""
Login to OMERO. POST with 'username', 'password' and 'server' index
Expand Down Expand Up @@ -94,7 +102,8 @@
"""

api_project_datasets = url(
r"^v(?P<api_version>%s)/m/projects/" "(?P<project_id>[0-9]+)/datasets/$" % versions,
r"^v(?P<api_version>%s)/m/projects/"
"(?P<project_id>[0-9]+)/datasets/$" % versions,
views.DatasetsView.as_view(),
name="api_project_datasets",
)
Expand All @@ -121,7 +130,8 @@
"""

api_dataset_images = url(
r"^v(?P<api_version>%s)/m/datasets/" "(?P<dataset_id>[0-9]+)/images/$" % versions,
r"^v(?P<api_version>%s)/m/datasets/"
"(?P<dataset_id>[0-9]+)/images/$" % versions,
views.ImagesView.as_view(),
name="api_dataset_images",
)
Expand All @@ -130,7 +140,8 @@
"""

api_dataset_projects = url(
r"^v(?P<api_version>%s)/m/datasets/" "(?P<dataset_id>[0-9]+)/projects/$" % versions,
r"^v(?P<api_version>%s)/m/datasets/"
"(?P<dataset_id>[0-9]+)/projects/$" % versions,
views.ProjectsView.as_view(),
name="api_dataset_projects",
)
Expand All @@ -148,7 +159,8 @@
"""

api_image_datasets = url(
r"^v(?P<api_version>%s)/m/images/" "(?P<image_id>[0-9]+)/datasets/$" % versions,
r"^v(?P<api_version>%s)/m/images/"
"(?P<image_id>[0-9]+)/datasets/$" % versions,
views.DatasetsView.as_view(),
name="api_image_datasets",
)
Expand Down Expand Up @@ -184,7 +196,8 @@
"""

api_screen_plates = url(
r"^v(?P<api_version>%s)/m/screens/" "(?P<screen_id>[0-9]+)/plates/$" % versions,
r"^v(?P<api_version>%s)/m/screens/"
"(?P<screen_id>[0-9]+)/plates/$" % versions,
views.PlatesView.as_view(),
name="api_screen_plates",
)
Expand All @@ -193,7 +206,8 @@
"""

api_well_plates = url(
r"^v(?P<api_version>%s)/m/wells/" "(?P<well_id>[0-9]+)/plates/$" % versions,
r"^v(?P<api_version>%s)/m/wells/"
"(?P<well_id>[0-9]+)/plates/$" % versions,
views.PlatesView.as_view(),
name="api_well_plates",
)
Expand Down Expand Up @@ -230,7 +244,8 @@
"""

api_plateacquisition = url(
r"^v(?P<api_version>%s)/m/plateacquisitions/" "(?P<object_id>[0-9]+)/$" % versions,
r"^v(?P<api_version>%s)/m/plateacquisitions/"
"(?P<object_id>[0-9]+)/$" % versions,
views.PlateAcquisitionView.as_view(),
name="api_plateacquisition",
)
Expand Down Expand Up @@ -261,7 +276,8 @@
"""

api_plate_wells = url(
r"^v(?P<api_version>%s)/m/plates/" "(?P<plate_id>[0-9]+)/wells/$" % versions,
r"^v(?P<api_version>%s)/m/plates/"
"(?P<plate_id>[0-9]+)/wells/$" % versions,
views.WellsView.as_view(),
name="api_plate_wells",
)
Expand Down Expand Up @@ -289,7 +305,8 @@
"""

api_plate_screens = url(
r"^v(?P<api_version>%s)/m/plates/" "(?P<plate_id>[0-9]+)/screens/$" % versions,
r"^v(?P<api_version>%s)/m/plates/"
"(?P<plate_id>[0-9]+)/screens/$" % versions,
views.ScreensView.as_view(),
name="api_plate_screens",
)
Expand All @@ -316,7 +333,8 @@
"""

api_image_rois = url(
r"^v(?P<api_version>%s)/m/images/" "(?P<image_id>[0-9]+)/rois/$" % versions,
r"^v(?P<api_version>%s)/m/images/"
"(?P<image_id>[0-9]+)/rois/$" % versions,
views.RoisView.as_view(),
name="api_image_rois",
)
Expand All @@ -334,7 +352,8 @@
"""

api_experimenter = url(
r"^v(?P<api_version>%s)/m/experimenters/" "(?P<object_id>[0-9]+)/$" % versions,
r"^v(?P<api_version>%s)/m/experimenters/"
"(?P<object_id>[0-9]+)/$" % versions,
views.ExperimenterView.as_view(),
name="api_experimenter",
)
Expand Down Expand Up @@ -362,7 +381,8 @@
"""

api_group = url(
r"^v(?P<api_version>%s)/m/experimentergroups/" "(?P<object_id>[0-9]+)/$" % versions,
r"^v(?P<api_version>%s)/m/experimentergroups/"
"(?P<object_id>[0-9]+)/$" % versions,
views.ExperimenterGroupView.as_view(),
name="api_experimentergroup",
)
Expand Down
Loading

0 comments on commit 757a7b4

Please sign in to comment.