Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: apply docformatter to all files in the project
Browse files Browse the repository at this point in the history
ycexiao committed Jan 30, 2025
1 parent 93d74e5 commit 0441753
Showing 77 changed files with 439 additions and 462 deletions.
10 changes: 5 additions & 5 deletions src/regolith/broker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""API for accessing the metadata and file storage"""
"""API for accessing the metadata and file storage."""

import copy

@@ -8,15 +8,15 @@


def load_db(rc_file="regolithrc.json"):
"""Create a Broker instance from an rc file"""
"""Create a Broker instance from an rc file."""
rc = copy.copy(DEFAULT_RC)
rc._update(load_rcfile(rc_file))
filter_databases(rc)
return Broker(rc)


class Broker:
"""Interface to the database and file storage systems
"""Interface to the database and file storage systems.
Examples
--------
@@ -63,12 +63,12 @@ def add_file(self, document, name, filepath):

@classmethod
def from_rc(cls, rc_file="regolithrc.json"):
"""Return a Broker instance"""
"""Return a Broker instance."""
return load_db(rc_file)

def get_file_path(self, document, name):
"""Get a file from the file storage associated with the document and
name
name.
Parameters
----------
6 changes: 3 additions & 3 deletions src/regolith/builders/activitylogbuilder.py
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@


class ActivitylogBuilder(LatexBuilderBase):
"""Build CV from database entries"""
"""Build CV from database entries."""

btype = "annual-activity"
needed_colls = [
@@ -54,7 +54,7 @@ class ActivitylogBuilder(LatexBuilderBase):
]

def construct_global_ctx(self):
"""Constructs the global context"""
"""Constructs the global context."""
super().construct_global_ctx()
gtx = self.gtx
rc = self.rc
@@ -80,7 +80,7 @@ def construct_global_ctx(self):
gtx["zip"] = zip

def latex(self):
"""Render latex template"""
"""Render latex template."""
rc = self.rc
group = fuzzy_retrieval(self.gtx["groups"], ["_id", "aka", "name"], rc.groupname)
if not rc.people:
6 changes: 3 additions & 3 deletions src/regolith/builders/appraisalbuilder.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@


class AppraisalBuilder(LatexBuilderBase):
"""Build CV from database entries"""
"""Build CV from database entries."""

btype = "annual-activity"
needed_colls = [
@@ -45,7 +45,7 @@ class AppraisalBuilder(LatexBuilderBase):
]

def construct_global_ctx(self):
"""Constructs the global context"""
"""Constructs the global context."""
super().construct_global_ctx()
gtx = self.gtx
rc = self.rc
@@ -66,7 +66,7 @@ def construct_global_ctx(self):
gtx["zip"] = zip

def latex(self):
"""Render latex template"""
"""Render latex template."""
rc = self.rc
if not rc.people:
raise RuntimeError("ERROR: please rerun specifying --people name")
16 changes: 8 additions & 8 deletions src/regolith/builders/basebuilder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Builder Base Classes"""
"""Builder Base Classes."""

import os
from glob import glob
@@ -20,7 +20,7 @@


class BuilderBase(object):
"""Base class for builders"""
"""Base class for builders."""

def __init__(self, rc):
self.rc = rc
@@ -43,7 +43,7 @@ def __init__(self, rc):
self.cmds = []

def construct_global_ctx(self):
"""Constructs the global context"""
"""Constructs the global context."""
gtx = self.gtx
gtx["len"] = len
gtx["True"] = True
@@ -60,7 +60,7 @@ def construct_global_ctx(self):
gtx["date_to_rfc822"] = date_to_rfc822

def render(self, tname, fname, **kwargs):
"""Render the template into a file using the kwargs and global context
"""Render the template into a file using the kwargs and global context.
Parameters
----------
@@ -90,7 +90,7 @@ def build(self):


class LatexBuilderBase(BuilderBase):
"""Base class for Latex builders"""
"""Base class for Latex builders."""

def __init__(self, rc):
super().__init__(rc)
@@ -107,11 +107,11 @@ def construct_global_ctx(self):
gtx["latex_safe_url"] = latex_safe_url

def run(self, cmd):
"""Run command in build dir"""
"""Run command in build dir."""
subprocess.run(cmd, cwd=self.bldir, check=True)

def pdf(self, base):
"""Compiles latex files to PDF"""
"""Compiles latex files to PDF."""
if self.rc.pdf:
if os.name == "nt":
self.run(["pdflatex"] + LATEX_OPTS + [base + ".tex"])
@@ -120,7 +120,7 @@ def pdf(self, base):
self.run(["dvipdf", base])

def clean(self):
"""Remove files created by latex"""
"""Remove files created by latex."""
postfixes = [
"*.dvi",
"*.toc",
13 changes: 5 additions & 8 deletions src/regolith/builders/beamplanbuilder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Builder for the planning of beamtimes.
The plan contains a summary of the information for the experiments
in during a beamtime and details about how to carry out the experiments.
The plan contains a summary of the information for the experiments in
during a beamtime and details about how to carry out the experiments.
"""

from datetime import datetime
@@ -14,8 +13,7 @@


class BeamPlanBuilder(LatexBuilderBase):
"""
Build a file of experiment plans for the beamtime from database entries.
"""Build a file of experiment plans for the beamtime from database entries.
The report is in the '.tex' file. The template of the file is in the
'templates/beamplan.tex'. The data will be grouped
@@ -60,9 +58,8 @@ def _search(db, key):
return None

def _gather_info(self, bt, docs):
"""
Query information from the list of documents. Return a table as the summary of the plans and a list of
experiment plans.
"""Query information from the list of documents. Return a table as the
summary of the plans and a list of experiment plans.
Parameters
----------
36 changes: 26 additions & 10 deletions src/regolith/builders/coabuilder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Builder for Recent Collaborators.
For the specified person it returns the name and institution of all
graduate student and post-doc advisors,
all graduate student advisees, all post-doc advisees in the past 60 months
and all coauthors in the past 48 months.
graduate student and post-doc advisors, all graduate student advisees,
all post-doc advisees in the past 60 months and all coauthors in the
past 48 months.
"""

import datetime as dt
@@ -25,7 +25,10 @@


def get_advisors_name_inst(advisee, rc):
"""Get the advisee's advisor. Yield (last name, first name, institution name)."""
"""Get the advisee's advisor.
Yield (last name, first name, institution name).
"""

phd_advisors = [
{
@@ -52,7 +55,10 @@ def get_advisors_name_inst(advisee, rc):


def get_advisees_name_inst(coll, advisor, rc):
"""Get advisor's advisees. Yield (last name, first name, institutions)"""
"""Get advisor's advisees.
Yield (last name, first name, institutions)
"""
advisor_names = advisor.get("aka", []) + [advisor.get("name"), advisor.get("_id")]
advisees = []
for person in coll:
@@ -118,7 +124,10 @@ def get_since_dates(rc):


def get_coauthors_from_pubs(rc, pubs, not_person):
"""Get co-authors' names from the publication. Not include the person itself."""
"""Get co-authors' names from the publication.
Not include the person itself.
"""
not_person_akas = [not_person["_id"], not_person["name"]] + not_person["aka"]
my_collabs = list()
for pub in pubs:
@@ -313,7 +322,10 @@ def format_last_first_institution_names(rc, ppl_names, excluded_inst_name=None):


def format_to_nsf(tups, type_str):
"""Format the 3 tups to 2 tups. ('type_str', 'last, first', 'inst', ...)."""
"""Format the 3 tups to 2 tups.
('type_str', 'last, first', 'inst', ...).
"""
return [(type_str, "{}, {}".format(tup[0], tup[1])) + tup[2:] for tup in tups]


@@ -386,7 +398,10 @@ def get_person(person_id, rc):


def find_coeditors(person, rc):
"""Get the coeditors info of the person. Return (last, first, inst, journal)."""
"""Get the coeditors info of the person.
Return (last, first, inst, journal).
"""
emps = person.get("employment")
if emps is None:
return set()
@@ -409,7 +424,7 @@ def coeditor_id_journals(_emps):


class RecentCollaboratorsBuilder(BuilderBase):
"""Build recent collaborators from database entries"""
"""Build recent collaborators from database entries."""

btype = "recent-collabs"
needed_colls = ["citations", "people", "contacts", "institutions"]
@@ -516,7 +531,8 @@ def query_ppl(self, target):

@staticmethod
def fill_in_tab(ws, ppl, start_row, template_cell_style=None, cols="ABCDE"):
"""Add the information in person, institution pairs into the table 4 in nsf table."""
"""Add the information in person, institution pairs into the table 4 in
nsf table."""
nsf_mappings = {
"co-author": "A:",
"collaborator": "C:",
6 changes: 3 additions & 3 deletions src/regolith/builders/cpbuilder.py
Original file line number Diff line number Diff line change
@@ -21,13 +21,13 @@ def is_declined(status):


class CPBuilder(LatexBuilderBase):
"""Build current and pending report from database entries"""
"""Build current and pending report from database entries."""

btype = "current-pending"
needed_colls = ["groups", "people", "grants", "proposals"]

def construct_global_ctx(self):
"""Constructs the global context"""
"""Constructs the global context."""
super().construct_global_ctx()
gtx = self.gtx
rc = self.rc
@@ -45,7 +45,7 @@ def construct_global_ctx(self):
gtx["zip"] = zip

def latex(self):
"""Render latex template"""
"""Render latex template."""
rc = self.rc
for group in self.gtx["groups"]:
self.gtx["grants"] = list(sorted(all_docs_from_collection(rc.client, "grants"), key=_id_key))
6 changes: 3 additions & 3 deletions src/regolith/builders/cvbuilder.py
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@


class CVBuilder(LatexBuilderBase):
"""Build CV from database entries"""
"""Build CV from database entries."""

btype = "cv"
needed_colls = ["institutions", "people", "grants", "citations", "projects", "proposals", "presentations"]

def construct_global_ctx(self):
"""Constructs the global context"""
"""Constructs the global context."""
super().construct_global_ctx()
gtx = self.gtx
rc = self.rc
@@ -47,7 +47,7 @@ def construct_global_ctx(self):
gtx["zip"] = zip

def latex(self):
"""Render latex template"""
"""Render latex template."""
rc = self.rc
gtx = self.gtx
if rc.people:
4 changes: 2 additions & 2 deletions src/regolith/builders/figurebuilder.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@


class FigureBuilder(LatexBuilderBase):
"""Build resume from database entries"""
"""Build resume from database entries."""

btype = "figure"

@@ -27,7 +27,7 @@ def construct_global_ctx(self):
gtx["fuzzy_retrieval"] = fuzzy_retrieval

def latex(self):
"""Render latex template"""
"""Render latex template."""
for f in [ff for ff in os.listdir(".") if ff.endswith(".tex")]:
fn, ext = os.path.splitext(f)
self.render(f, fn + "_rend" + ext)
9 changes: 4 additions & 5 deletions src/regolith/builders/gradebuilder.py
Original file line number Diff line number Diff line change
@@ -130,10 +130,9 @@ def latex(self):
self.pdf(base)

def makestats(self, course):
"""Returns a dictionary of statistics for a course whose keys are
the assignments and whose values are a (mean-problem, std-problem,
mean-total, std-total) tuple.
"""
"""Returns a dictionary of statistics for a course whose keys are the
assignments and whose values are a (mean-problem, std-problem, mean-
total, std-total) tuple."""
scores = {}
course_id = course["_id"]
for grade in self.gtx["grades"]:
@@ -212,7 +211,7 @@ def maketotals(self, student_grades, grouped_assignments, course):
return sorted(totals), wtotal

def plot_letter_grades(self, students_kwargs, scale):
"""Plots the letter grades in a histogram"""
"""Plots the letter grades in a histogram."""
try:
import matplotlib.pyplot as plt
except ImportError:
Loading

0 comments on commit 0441753

Please sign in to comment.