Skip to content

Commit

Permalink
DEV-1483: add black and reformat (#389)
Browse files Browse the repository at this point in the history
reformat all using black
  • Loading branch information
qqiao2024 authored Oct 17, 2022
1 parent 7458504 commit 3f1058f
Show file tree
Hide file tree
Showing 35 changed files with 1,083 additions and 783 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ repos:
args: [--autofix]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/psf/black
rev: 20.8b1 # for pre-commit 1.21.0 in jenkins
hooks:
- id: black
additional_dependencies: [click==8.0.4]
- repo: https://github.com/pycqa/isort
rev: 5.6.4 # last version to support pre-commit 1.21.0 in Jenkins
hooks:
Expand Down
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "^.secrets.baseline$",
"lines": null
},
"generated_at": "2022-10-11T18:55:31Z",
"generated_at": "2022-10-14T21:28:31Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -69,7 +69,7 @@
"hashed_secret": "5d0fa74acf95d1d6bebd0d37f76a94e77d604fd9",
"is_secret": false,
"is_verified": false,
"line_number": 33,
"line_number": 36,
"type": "Basic Auth Credentials"
}
]
Expand Down
40 changes: 26 additions & 14 deletions bin/update_related_case_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ def recursive_update_related_case_caches(node, case, visited_ids=set()):
"""

logger.info("{}: | case: {} | project: {}".format(
node, case, node._props.get('project_id', '?')))
logger.info(
"{}: | case: {} | project: {}".format(
node, case, node._props.get("project_id", "?")
)
)

visited_ids.add(node.node_id)

for edge in node.edges_in:
if edge.src is None:
continue

if edge.__class__.__name__.endswith('RelatesToCase'):
if edge.__class__.__name__.endswith("RelatesToCase"):
continue

if not hasattr(edge.src, '_related_cases'):
if not hasattr(edge.src, "_related_cases"):
continue

original = set(edge.src._related_cases)
Expand All @@ -61,27 +64,36 @@ def update_project_related_case_cache(project):

def main():
parser = argparse.ArgumentParser()
parser.add_argument("-H", "--host", type=str, action="store",
required=True, help="psql-server host")
parser.add_argument("-U", "--user", type=str, action="store",
required=True, help="psql test user")
parser.add_argument("-D", "--database", type=str, action="store",
required=True, help="psql test database")
parser.add_argument("-P", "--password", type=str, action="store",
help="psql test password")
parser.add_argument(
"-H", "--host", type=str, action="store", required=True, help="psql-server host"
)
parser.add_argument(
"-U", "--user", type=str, action="store", required=True, help="psql test user"
)
parser.add_argument(
"-D",
"--database",
type=str,
action="store",
required=True,
help="psql test database",
)
parser.add_argument(
"-P", "--password", type=str, action="store", help="psql test password"
)

args = parser.parse_args()
prompt = "Password for {}:".format(args.user)
password = args.password or getpass.getpass(prompt)
g = PsqlGraphDriver(args.host, args.user, password, args.database)

with g.session_scope():
projects = g.nodes(md.Project).not_props(state='legacy').all()
projects = g.nodes(md.Project).not_props(state="legacy").all()
for p in projects:
update_project_related_case_cache(p)

print("Done.")


if __name__ == '__main__':
if __name__ == "__main__":
main()
24 changes: 13 additions & 11 deletions docs/bin/schemata_to_graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@


def build_visualization():
print('Building schema documentation...')
print ("Building schema documentation...")

# Load directory tree info
bin_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.join(os.path.abspath(
os.path.join(bin_dir, os.pardir, os.pardir)))
root_dir = os.path.join(
os.path.abspath(os.path.join(bin_dir, os.pardir, os.pardir))
)

# Create graph
dot = Digraph(
comment="High level graph representation of GDC data model", format='pdf')
dot.graph_attr['rankdir'] = 'RL'
dot.node_attr['fillcolor'] = 'lightblue'
dot.node_attr['style'] = 'filled'
comment="High level graph representation of GDC data model", format="pdf"
)
dot.graph_attr["rankdir"] = "RL"
dot.node_attr["fillcolor"] = "lightblue"
dot.node_attr["style"] = "filled"

# Add nodes
for node in m.Node.get_subclasses():
Expand All @@ -28,18 +30,18 @@ def build_visualization():

# Add edges
for edge in m.Edge.get_subclasses():
if edge.__dst_class__ == 'Case' and edge.label == 'relates_to':
if edge.__dst_class__ == "Case" and edge.label == "relates_to":
# Skip case cache edges
continue

src = m.Node.get_subclass_named(edge.__src_class__)
dst = m.Node.get_subclass_named(edge.__dst_class__)
dot.edge(src.get_label(), dst.get_label(), edge.get_label())

gv_path = os.path.join(root_dir, 'docs', 'viz', 'gdc_data_model.gv')
gv_path = os.path.join(root_dir, "docs", "viz", "gdc_data_model.gv")
dot.render(gv_path)
print('graphviz output to {}'.format(gv_path))
print ("graphviz output to {}".format(gv_path))


if __name__ == '__main__':
if __name__ == "__main__":
build_visualization()
51 changes: 35 additions & 16 deletions gdcdatamodel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import argparse
import getpass

import psqlgraph
from models import * # noqa
from models.versioned_nodes import VersionedNode # noqa
from psqlgraph import * # noqa
from sqlalchemy import * # noqa

try:
import IPython

ipython = True
except Exception as e:
print(('{}, using standard interactive console. '
'If you install IPython, then it will automatically '
'be used for this repl.').format(e))
print(
(
"{}, using standard interactive console. "
"If you install IPython, then it will automatically "
"be used for this repl."
).format(e)
)
import code

ipython = False


Expand All @@ -31,26 +36,40 @@
"""


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--database', default='test', type=str,
help='name of the database to connect to')
parser.add_argument('-i', '--host', default='localhost', type=str,
help='host of the postgres server')
parser.add_argument('-u', '--user', default='test', type=str,
help='user to connect to postgres as')
parser.add_argument('-p', '--password', default=None, type=str,
help='password for given user. If no '
'password given, one will be prompted.')
parser.add_argument(
"-d",
"--database",
default="test",
type=str,
help="name of the database to connect to",
)
parser.add_argument(
"-i",
"--host",
default="localhost",
type=str,
help="host of the postgres server",
)
parser.add_argument(
"-u", "--user", default="test", type=str, help="user to connect to postgres as"
)
parser.add_argument(
"-p",
"--password",
default=None,
type=str,
help="password for given user. If no " "password given, one will be prompted.",
)

args = parser.parse_args()

print(message.format(args.database, args.host, args.user))
if args.password is None:
args.password = getpass.getpass()

g = psqlgraph.PsqlGraphDriver(
args.host, args.user, args.password, args.database)
g = psqlgraph.PsqlGraphDriver(args.host, args.user, args.password, args.database)

with g.session_scope() as s:
rb = s.rollback
Expand Down
Loading

0 comments on commit 3f1058f

Please sign in to comment.