Skip to content

Commit

Permalink
Merge pull request #425 from dgasmith/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
dgasmith authored Oct 1, 2019
2 parents efe05c7 + 9d23105 commit 613d361
Show file tree
Hide file tree
Showing 66 changed files with 965 additions and 1,568 deletions.
4 changes: 3 additions & 1 deletion .lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ path_classifiers:
generated:
- qcfractal/_version.py
queries:
- exclude: py/not-named-self # Blocks Pydantic's @validator not accepting `self` until a better fix can be found
- exclude:
- py/not-named-self # Blocks Pydantic's @validator not accepting `self` until a better fix can be found
- py/missing-call-to-init
12 changes: 5 additions & 7 deletions qcfractal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
"""

from . import interface

# Import modules
from .storage_sockets import storage_socket_factory

# Handle versioneer
from .extras import get_information
# Handle top level object imports
from .postgres_harness import PostgresHarness, TemporaryPostgres
from .queue import QueueManager
from .server import FractalServer
from .snowflake import FractalSnowflake, FractalSnowflakeHandler
from .queue import QueueManager
# Import modules
from .storage_sockets import storage_socket_factory

# Handle versioneer
from .extras import get_information
__version__ = get_information('version')
__git_revision__ = get_information('git_revision')
del get_information
11 changes: 5 additions & 6 deletions qcfractal/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
try:
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen(
[c] + args,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr else None))
p = subprocess.Popen([c] + args,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr else None))
break
except EnvironmentError:
e = sys.exc_info()[1]
Expand Down
9 changes: 3 additions & 6 deletions qcfractal/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@

from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool
import yaml
from sqlalchemy import engine_from_config, pool

from alembic import context

from qcfractal.storage_sockets.models import Base

import yaml
from qcfractal.config import FractalConfig
from qcfractal.storage_sockets.models import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
3 changes: 2 additions & 1 deletion qcfractal/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import importlib
import json
import signal
import yaml
from functools import partial

import yaml


def import_module(module, package=None):
"""Protected import of a module
Expand Down
1 change: 1 addition & 0 deletions qcfractal/cli/qcfractal_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ def main(args=None):

dashboard_app.run_server(debug=True)


if __name__ == '__main__':
main()
364 changes: 166 additions & 198 deletions qcfractal/cli/qcfractal_manager.py

Large diffs are not rendered by default.

42 changes: 31 additions & 11 deletions qcfractal/cli/qcfractal_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def parse_args():

### Config subcommands
info = subparsers.add_parser('info', help="Manage users and permissions on a QCFractal server instance.")
info.add_argument("category", nargs="?", default="config", choices=["config", "alembic"], help="The config category to show.")
info.add_argument("category",
nargs="?",
default="config",
choices=["config", "alembic"],
help="The config category to show.")
info.add_argument("--base-folder", **FractalConfig.help_info("base_folder"))

### User subcommands
Expand All @@ -101,9 +105,16 @@ def parse_args():

user_add = user_subparsers.add_parser("add", help="Add a user to the QCFractal server.")
user_add.add_argument("username", default=None, type=str, help="The username to add.")
user_add.add_argument("--password", default=None, type=str, required=False,
user_add.add_argument("--password",
default=None,
type=str,
required=False,
help="The password for the user. If None, a default one will be created and printed.")
user_add.add_argument("--permissions", nargs='+', default=None, type=str, required=True,
user_add.add_argument("--permissions",
nargs='+',
default=None,
type=str,
required=True,
help="Permissions for the user. Allowed values: read, write, queue, compute, admin.")

user_show = user_subparsers.add_parser("info", help="Show the user's current permissions.")
Expand All @@ -112,12 +123,21 @@ def parse_args():
user_modify = user_subparsers.add_parser("modify", help="Change a user's password or permissions.")
user_modify.add_argument("username", default=None, type=str, help="The username to modify.")
user_modify_password = user_modify.add_mutually_exclusive_group()
user_modify_password.add_argument("--password", type=str, default=None, required=False,
user_modify_password.add_argument("--password",
type=str,
default=None,
required=False,
help="Change the user's password to the specified value.")
user_modify_password.add_argument("--reset-password", action='store_true',
user_modify_password.add_argument("--reset-password",
action='store_true',
help="Reset the user's password. A new password will be generated and printed.")
user_modify.add_argument("--permissions", nargs='+', default=None, type=str, required=False,
help="Change the users's permissions. Allowed values: read, write, compute, queue, admin.")
user_modify.add_argument(
"--permissions",
nargs='+',
default=None,
type=str,
required=False,
help="Change the users's permissions. Allowed values: read, write, compute, queue, admin.")

user_remove = user_subparsers.add_parser("remove", help="Remove a user.")
user_remove.add_argument("username", default=None, type=str, help="The username to remove.")
Expand Down Expand Up @@ -385,7 +405,9 @@ def server_user(args, config):
try:
if args["user_command"] == "add":
print("\n>>> Adding new user...")
success, pw = storage.add_user(args["username"], password=args["password"], permissions=args["permissions"])
success, pw = storage.add_user(args["username"],
password=args["password"],
permissions=args["permissions"])
if success:
print(f"\n>>> New user successfully added, password:\n{pw}")
if config.fractal.security is None:
Expand All @@ -404,9 +426,7 @@ def server_user(args, config):
print(permissions)
elif args["user_command"] == "modify":
print(f"\n>>> Modifying user '{args['username']}'...")
success, message = storage.modify_user(args["username"],
args["password"],
args["reset_password"],
success, message = storage.modify_user(args["username"], args["password"], args["reset_password"],
args["permissions"])
if success:
info = "Successfully modified user\n"
Expand Down
30 changes: 14 additions & 16 deletions qcfractal/cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
Tests for QCFractals CLI
"""
import os
import time
import tempfile
import time

import pytest
import yaml

import qcfractal

from qcfractal import testing
from qcfractal.cli.cli_utils import read_config_file
import yaml

# def _run_tests()
_options = {"coverage": True, "dump_stdout": True}
Expand All @@ -26,8 +25,7 @@ def qcfractal_base_init():

args = [
"qcfractal-server", "init", "--base-folder",
str(tmpdir.name), "--db-own=False", "--clear-database",
f"--db-port={storage.config.database.port}"
str(tmpdir.name), "--db-own=False", "--clear-database", f"--db-port={storage.config.database.port}"
]
assert testing.run_process(args, **_options)

Expand Down Expand Up @@ -55,8 +53,10 @@ def test_cli_user_add(qcfractal_base_init):
args = ["qcfractal-server", "user", qcfractal_base_init, "add", "test_user_add_1", "--permissions", "admin"]
assert testing.run_process(args, **_options) is False

args = ["qcfractal-server", "user", qcfractal_base_init, "add", "test_user_add_2", "--password", "foo",
"--permissions", "admin"]
args = [
"qcfractal-server", "user", qcfractal_base_init, "add", "test_user_add_2", "--password", "foo",
"--permissions", "admin"
]
assert testing.run_process(args, **_options)

args = ["qcfractal-server", "user", qcfractal_base_init, "add", "test_user_add_3"]
Expand All @@ -80,16 +80,16 @@ def test_cli_user_modify(qcfractal_base_init):
args = ["qcfractal-server", "user", qcfractal_base_init, "add", "test_user_modify", "--permissions", "read"]
assert testing.run_process(args, **_options)

args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify",
"--permissions", "read", "write", "--reset-password"]
args = [
"qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify", "--permissions", "read",
"write", "--reset-password"
]
assert testing.run_process(args, **_options)

args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify",
"--password", "foopass"]
args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify", "--password", "foopass"]
assert testing.run_process(args, **_options)

args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify",
"--permissions", "read"]
args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "test_user_modify", "--permissions", "read"]
assert testing.run_process(args, **_options)

args = ["qcfractal-server", "user", qcfractal_base_init, "modify", "badname_1234"]
Expand Down Expand Up @@ -136,8 +136,7 @@ def test_with_api_logging(postgres_server, log_apis):

args = [
"qcfractal-server", "init", "--base-folder",
str(tmpdir.name), "--db-own=False", "--clear-database",
f"--db-port={postgres_server.config.database.port}",
str(tmpdir.name), "--db-own=False", "--clear-database", f"--db-port={postgres_server.config.database.port}",
f"--log-apis={log_apis}"
]
assert testing.run_process(args, **_options)
Expand Down Expand Up @@ -272,4 +271,3 @@ def test_cli_managers_skel(tmp_path):
config = tmp_path / "config.yaml"
args = ["qcfractal-manager", "--skel", config.as_posix()]
testing.run_process(args, **_options)

11 changes: 6 additions & 5 deletions qcfractal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pathlib import Path
from typing import Optional

from pydantic import Schema, validator
import yaml
from pydantic import Schema, validator

from .interface.models import AutodocBaseSettings

Expand Down Expand Up @@ -86,10 +86,11 @@ class FractalServerSettings(ConfigSettings):
description="Compress REST responses or not, should be True unless behind a "
"proxy.")
allow_read: bool = Schema(True, description="Always allows read access to record tables.")
security: str = Schema(None, description="Optional user authentication. Specify 'local' to enable "
"authentication through locally stored usernames. "
"User permissions may be manipulated through the ``qcfractal-server "
"user`` CLI.")
security: str = Schema(None,
description="Optional user authentication. Specify 'local' to enable "
"authentication through locally stored usernames. "
"User permissions may be manipulated through the ``qcfractal-server "
"user`` CLI.")

query_limit: int = Schema(1000, description="The maximum number of records to return per query.")
logfile: Optional[str] = Schema("qcfractal_server.log", description="The logfile to write server logs.")
Expand Down
1 change: 0 additions & 1 deletion qcfractal/dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
server = app.server
app.config.suppress_callback_exceptions = True
app.server.config.from_mapping(DATABASE_URI="mongodb://localhost", DATABASE_NAME="QCFractal Server")

1 change: 1 addition & 0 deletions qcfractal/dashboard/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import current_app, g

from ..storage_sockets import storage_socket_factory


Expand Down
12 changes: 6 additions & 6 deletions qcfractal/dashboard/dash_managers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import dash_table
## Functions to call on the fly when page loads
import pandas as pd

import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_table
from dash.dependencies import Input, Output

from .app import app
from .connection import get_socket
from .navbar import navbar

## Functions to call on the fly when page loads
import pandas as pd


def managers_table(status):
socket = get_socket()
Expand Down Expand Up @@ -77,4 +77,4 @@ def overview_graph(status):
Output('manager-overview', 'figure'),
[Input('manager-overview-groupby', 'value')])
def update_overview_graph(status):
return overview_graph(status)
return overview_graph(status)
12 changes: 5 additions & 7 deletions qcfractal/dashboard/dash_queue.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import dash_table
## Functions to call on the fly when page loads
import pandas as pd

import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_table
from dash.dependencies import Input, Output

from .app import app
from .connection import get_socket
from .navbar import navbar

## Functions to call on the fly when page loads
import pandas as pd


def queue_counts(status):
socket = get_socket()
Expand All @@ -29,5 +29,3 @@ def queue_counts(status):
])

layout = lambda: html.Div([navbar, body()])


12 changes: 5 additions & 7 deletions qcfractal/dashboard/dash_service.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import dash_table
## Functions to call on the fly when page loads
import pandas as pd

import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_table
from dash.dependencies import Input, Output

from .app import app
from .connection import get_socket
from .navbar import navbar

## Functions to call on the fly when page loads
import pandas as pd


def service_counts(status):
socket = get_socket()
Expand All @@ -29,5 +29,3 @@ def service_counts(status):
])

layout = lambda: html.Div([navbar, body()])


7 changes: 2 additions & 5 deletions qcfractal/dashboard/index.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output

from . import dash_managers, dash_queue, dash_service
from .app import app
from .navbar import navbar

from . import dash_managers
from . import dash_queue
from . import dash_service

body = dbc.Container(
[
dbc.Row([
Expand Down
1 change: 0 additions & 1 deletion qcfractal/dashboard/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
brand_href="/",
sticky="top",
)

2 changes: 1 addition & 1 deletion qcfractal/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def provenance_stamp(routine):
'creator': 'QCFractal',
'version': get_information('version'),
'routine': routine,
}
}
Loading

0 comments on commit 613d361

Please sign in to comment.