Skip to content

Commit

Permalink
add parts
Browse files Browse the repository at this point in the history
  • Loading branch information
interrogator committed Aug 18, 2019
1 parent 3ee719c commit eada2a2
Show file tree
Hide file tree
Showing 21 changed files with 1,900 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
Expand Down
10 changes: 6 additions & 4 deletions buzzword/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
BUZZWORD_PAGE_SIZE=25
BUZZWORD_TABLE_SIZE=2000,200
BUZZWORD_ADD_GOVERNOR=false
""".format(FULLNAME)
""".format(
FULLNAME
)

CORPORA = """
{{
Expand Down Expand Up @@ -61,11 +63,11 @@
for folder in ["csv", "uploads", "example"]:
os.makedirs(os.path.join(FULLNAME, folder))
with open(os.path.join(FULLNAME, ".env"), "w") as fo:
fo.write(ENV.strip() + '\n')
fo.write(ENV.strip() + "\n")
with open(os.path.join(FULLNAME, "corpora.json"), "w") as fo:
fo.write(CORPORA.strip() + '\n')
fo.write(CORPORA.strip() + "\n")
with open(os.path.join(CORPUS_PATH, "001-joke-lion-pun.txt"), "w") as fo:
fo.write(CORPUS.strip() + '\n')
fo.write(CORPUS.strip() + "\n")
print("Testing parser: {}->{}-parsed ...".format(CORPUS_PATH, CORPUS_PATH))
parsed = Corpus(CORPUS_PATH).parse(cons_parser=None)

Expand Down
Empty file added buzzword/parts/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions buzzword/parts/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import dash_core_components as dcc
import dash_html_components as html
from buzzword.parts.nav import navbar
import os
import buzzword


root = os.path.dirname(os.path.dirname(buzzword.__file__))

with open(os.path.join(root, "docs/about.md"), "r") as fo:
text = fo.read()

layout = html.Div([navbar, dcc.Markdown(className="documentation", children=text)])
Empty file.
Binary file added buzzword/parts/assets/bolt.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added buzzword/parts/assets/bolt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions buzzword/parts/assets/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.loading-main::after{
content: "Preparing your workspace...";
position: fixed;
margin-top: 100px;
}

/* Hide the 'Loading...' text at startup */
._dash-loading {
display:none;
}

.no-underline {
text-decoration: none;
color: blue;
}

p, ul, ol {
padding-bottom: 10px !important;
padding-top: 10px !important;
}
Binary file added buzzword/parts/assets/favicon.ico
Binary file not shown.
12 changes: 12 additions & 0 deletions buzzword/parts/building.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import dash_core_components as dcc
import dash_html_components as html
from buzzword.parts.nav import navbar
import os
import buzzword

root = os.path.dirname(os.path.dirname(buzzword.__file__))

with open(os.path.join(root, "docs/building.md"), "r") as fo:
text = fo.read()

layout = html.Div([navbar, dcc.Markdown(className="documentation", children=text)])
168 changes: 168 additions & 0 deletions buzzword/parts/configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# flake8: noqa

"""
buzz webapp: command-line and .env processing
"""

import argparse
import os

from dotenv import load_dotenv


def _from_cmdline():
"""
Command line argument parsing
"""
parser = argparse.ArgumentParser(
description="Run the buzzword app for a given corpus."
)

parser.add_argument(
"-nl",
"--load",
default=True,
action="store_true",
required=False,
help="Load corpus into memory. Longer startup, faster search.",
)

parser.add_argument(
"-r",
"--root",
default=".",
required=False,
type=str,
nargs="?",
help="Space for the tool to store CSVs, uploaded data, etc.",
)

parser.add_argument(
"-t", "--title", nargs="?", type=str, required=False, help="Title for app"
)

parser.add_argument(
"-d",
"--drop-columns",
nargs="?",
type=str,
required=False,
help="Dataset columns to remove before loading (comma-separated)",
)

parser.add_argument(
"-m",
"--max-dataset-rows",
nargs="?",
type=int,
required=False,
help="Truncate datasets at this many rows",
)

parser.add_argument(
"-s",
"--table-size",
nargs="?",
type=str,
required=False,
default="2000,200",
help="Max table dimensions as str ('nrows,ncolumns')",
)

parser.add_argument(
"-p",
"--page-size",
nargs="?",
type=int,
default=25,
required=False,
help="Rows to display per page",
)

parser.add_argument(
"-debug",
"--debug",
default=False,
action="store_true",
required=False,
help="Debug mode",
)

parser.add_argument(
"-g",
"--add-governor",
default=False,
action="store_true",
required=False,
help="Load governor attributes into dataset. Slow to load and uses more memory, but allows more kinds of searching/showing",
)

parser.add_argument(
"-e",
"--env",
nargs="?",
type=str,
required=False,
help="Use .env file to load config, rather than command line",
)

parser.add_argument(
"-c",
"--corpora-file",
default="corpora.json",
type=str,
nargs="?",
help="Path to corpora.json",
)

kwargs = vars(parser.parse_args())
if kwargs["drop_columns"] is not None:
kwargs["drop_columns"] = kwargs["drop_columns"].split(",")
if kwargs["table_size"] is not None:
kwargs["table_size"] = [int(i) for i in kwargs["table_size"].split(",")][:2]
return kwargs


def _configure_buzzword(name):
"""
Configure application. First, look at command line args.
If the user wants to use dotenv (--env flag), load from that.
If not from main, use dotenv only.
"""
env_path = os.path.join(os.getcwd(), ".env")
config = _from_cmdline()
if not config["env"]:
return config
else:
env_path = config["env"]
return _from_env(env_path)


def _from_env(env_path):
"""
Read .env. Should return same as command line, except --env argument
"""
trues = {"1", "true", "True", "Y", "y", "yes", True}
load_dotenv(dotenv_path=env_path)
drop_columns = os.getenv("BUZZWORD_DROP_COLUMNS")
if drop_columns:
drop_columns = drop_columns.split(",")
table_size = os.getenv("BUZZWORD_TABLE_SIZE")
if table_size:
table_size = [int(i) for i in table_size.split(",")]
max_dataset_rows = os.getenv("BUZZWORD_MAX_DATASET_ROWS")
if max_dataset_rows:
max_dataset_rows = int(max_dataset_rows)

return dict(
corpora_file=os.getenv("BUZZWORD_CORPORA_FILE", "corpora.json"),
root=os.getenv("BUZZWORD_ROOT", "."),
debug=os.getenv("BUZZWORD_DEBUG", True) in trues,
load=os.getenv("BUZZWORD_LOAD", True) in trues,
add_governor=os.getenv("BUZZWORD_ADD_GOVERNOR", False) in trues,
title=os.getenv("BUZZWORD_TITLE"),
page_size=int(os.getenv("BUZZWORD_PAGE_SIZE", 25)),
max_dataset_rows=max_dataset_rows,
drop_columns=drop_columns,
table_size=table_size,
)
12 changes: 12 additions & 0 deletions buzzword/parts/depgrep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import dash_core_components as dcc
import dash_html_components as html
from buzzword.parts.nav import navbar
import os
import buzzword

root = os.path.dirname(os.path.dirname(buzzword.__file__))

with open(os.path.join(root, "docs/depgrep.md"), "r") as fo:
text = fo.read()

layout = html.Div([navbar, dcc.Markdown(className="documentation", children=text)])

0 comments on commit eada2a2

Please sign in to comment.