Skip to content

Commit

Permalink
Update cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Sep 29, 2023
1 parent 513876a commit b3998cf
Show file tree
Hide file tree
Showing 115 changed files with 1,180 additions and 1,376 deletions.
76 changes: 38 additions & 38 deletions bin/bootstrax
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,11 @@ def keep_target(targets, compare_with, n_fails):


def infer_target(rd: dict) -> dict:
"""Check if the target should be overridden based on the mode of the DAQ
for this run :param rd: rundoc :return: dict with the targets and the
targets for post processing."""
"""Check if the target should be overridden based on the mode of the DAQ for this run :param rd:
rundoc :return: dict with the targets and the targets for post processing.
"""
targets = args.targets.copy()
post_process = args.post_process.copy()

Expand Down Expand Up @@ -653,6 +655,7 @@ def set_state(state, update_fields=None):
"""Inform the bootstrax collection we're in a different state.
if state is None, leave state unchanged, just update heartbeat time
"""
# Find the last message of this host
previous_entry = bs_coll.find_one({"host": hostname}, sort=[("_id", pymongo.DESCENDING)])
Expand Down Expand Up @@ -685,8 +688,8 @@ def set_state(state, update_fields=None):


def send_heartbeat(update_fields=None):
"""Inform the bootstrax collection we're still here Use during long-running
tasks where state doesn't change."""
"""Inform the bootstrax collection we're still here Use during long-running tasks where state
doesn't change."""
# Same as set_state, just don't change state
set_state(None, update_fields=update_fields)

Expand All @@ -703,14 +706,14 @@ def log_warning(message, priority="warning", run_id=None):


def eb_can_process():
""""The new ebs (eb3-5) should be sufficient to process all data. In
exceptional circumstances eb3-5 cannot keep up. Only let eb0-2 also process
data in such cases.
""""The new ebs (eb3-5) should be sufficient to process all data. In exceptional circumstances
eb3-5 cannot keep up. Only let eb0-2 also process data in such cases.
Before eb0-2 are also used for processing two criteria have to be fulfilled:
- There should be runs waiting to be processed
- Eb3-5 should be busy processing for a substantial time.
:returns: bool if this host should process a run
"""

# eb3-5 always process.
Expand Down Expand Up @@ -761,14 +764,14 @@ def eb_can_process():


def infer_mode(rd):
"""Infer a safe operating mode of running bootstrax based on the
uncompressed redax rate.
"""Infer a safe operating mode of running bootstrax based on the uncompressed redax rate.
Estimating save parameters for running
bootstrax from:
https://xe1t-wiki.lngs.infn.it/doku.php?id=xenon:xenonnt:dsg:daq:eb_speed_tests_2021update
:returns: dictionary of how many cores, max_messages and compressor
should be used based on an estimated data rate.
"""
# Get data rate from dispatcher
data_rate = 0
Expand Down Expand Up @@ -892,8 +895,7 @@ def infer_records_compressor(rd, datarate, n_fails):


def sufficient_diskspace():
"""Check if there is sufficient space available on the local disk to write
to."""
"""Check if there is sufficient space available on the local disk to write to."""
for i in range(wait_diskspace_n_max):
du = disk_usage(output_folder)
disk_pct = du.percent
Expand Down Expand Up @@ -937,8 +939,7 @@ def delete_live_data(rd, live_data_path):


def _delete_data(rd, path, data_type):
"""After completing the processing and updating the runsDB, remove the
live_data."""
"""After completing the processing and updating the runsDB, remove the live_data."""

if data_type == "live" and not args.delete_live and args.production:
message = "Unsafe operation. Trying to delete live data!"
Expand Down Expand Up @@ -974,8 +975,7 @@ def _delete_data(rd, path, data_type):


def wait_on_delete_thread():
"""Check that the thread with the delete_thread_name is finished before
continuing."""
"""Check that the thread with the delete_thread_name is finished before continuing."""
threads = threading.enumerate()
for thread in threads:
if thread.name == delete_thread_name:
Expand Down Expand Up @@ -1020,11 +1020,11 @@ def ping_dbs():


def get_run(*, mongo_id=None, number=None, full_doc=False):
"""Find and return run doc matching mongo_id or number The bootstrax state
is left unchanged.
"""Find and return run doc matching mongo_id or number The bootstrax state is left unchanged.
:param full_doc: If true (default is False), return the full run doc rather than just fields
used by bootstrax.
:param full_doc: If true (default is False), return the full run doc
rather than just fields used by bootstrax.
"""
if number is not None:
query = {"number": number}
Expand Down Expand Up @@ -1062,9 +1062,9 @@ def set_run_state(rd, state, return_new_doc=True, **kwargs):


def check_data_written(rd):
"""Checks that the data as written in the runs-database is actually
available on this machine :param rd: rundoc :return: type bool, False if
not all paths exist or if there are no files on this host."""
"""Checks that the data as written in the runs-database is actually available on this machine
:param rd: rundoc :return: type bool, False if not all paths exist or if there are no files on
this host."""
files_written = 0

# Fetch the rd again -> to see status of 'data' field
Expand All @@ -1089,13 +1089,11 @@ def check_data_written(rd):
def all_files_saved(rd, wait_max=600, wait_per_cycle=10):
"""Check that all files are written.
It might be that the savers are still in the process of renaming
from folder_temp to folder. Hence allow some wait time to allow the
savers to finish
:param rd: rundoc
:param wait_max: max seconds to wait for data to save
:param wait_per_cycle: wait this many seconds if the data is not yet
there
It might be that the savers are still in the process of renaming from folder_temp to folder.
Hence allow some wait time to allow the savers to finish :param rd: rundoc :param wait_max: max
seconds to wait for data to save :param wait_per_cycle: wait this many seconds if the data is
not yet there
"""
start = time.time()
while not check_data_written(rd):
Expand Down Expand Up @@ -1153,8 +1151,8 @@ def abandon(*, mongo_id=None, number=None):


def consider_run(query, return_new_doc=True, test_counter=0):
"""Return one run doc matching query, and simultaneously set its bootstrax
state to 'considering'."""
"""Return one run doc matching query, and simultaneously set its bootstrax state to
'considering'."""
# We must first do an atomic find-and-update to set the run's state
# to "considering", to ensure the run doesn't get picked up by a
# bootstrax on another host.
Expand Down Expand Up @@ -1356,10 +1354,11 @@ def run_strax(


def last_file_write_time(match_location: str) -> datetime:
"""Get the datetime in UTC of the last file that was written in raw-
records* :param match_location: Location where runs are written to :return:
"""Get the datetime in UTC of the last file that was written in raw- records* :param
match_location: Location where runs are written to :return:
TZ aware timestamp.
"""
last_time = datetime.fromtimestamp(0).replace(tzinfo=pytz.utc)
matched_folders = glob(match_location)
Expand Down Expand Up @@ -1653,11 +1652,11 @@ def process_run(rd, send_heartbeats=args.production):


def clean_run(*, mongo_id=None, number=None, force=False):
"""Removes all data on this host associated with a run that was previously
registered in the run db.
"""Removes all data on this host associated with a run that was previously registered in the run
db.
Does NOT remove temporary folders, nor data that isn't registered to the run db.
Does NOT remove temporary folders, nor data that isn't registered to
the run db.
"""
# We need to get the full data docs here, since I was too lazy to write
# a surgical update below
Expand Down Expand Up @@ -1698,6 +1697,7 @@ def cleanup_db():
"""Find various pathological runs and clean them from the db.
Also cleans the bootstrax collection for stale entries
"""
# Check mongo connection
ping_dbs()
Expand Down
3 changes: 1 addition & 2 deletions docs/source/build_context_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@


def main():
"""Maybe we one day want to expend this, but for now, let's start with
this."""
"""Maybe we one day want to expend this, but for now, let's start with this."""
out = base_doc
with open(this_dir + f"/reference/context.rst", mode="w") as f:
f.write(out)
Expand Down
19 changes: 10 additions & 9 deletions docs/source/build_datastructure_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
and configuration options that apply to each plugins.
For extra credit, the SVGs are clickable.
"""
from collections import defaultdict
import os
Expand Down Expand Up @@ -137,6 +138,7 @@ def add_spaces(x):
"""Add four spaces to every line in x.
This is needed to make html raw blocks in rst format correctly
"""
y = ""
if isinstance(x, str):
Expand All @@ -147,12 +149,11 @@ def add_spaces(x):


def get_plugins_deps(st):
"""For a given Strax.Context return the dependencies per plugin split by
the known tree_suffices.
"""For a given Strax.Context return the dependencies per plugin split by the known
tree_suffices.
:param st: Strax.Context :return: dict of default dicts containing the number of dependencies.
:param st: Strax.Context
:return: dict of default dicts containing the number of
dependencies.
"""
plugins_by_deps = {k: defaultdict(list) for k in tree_suffices}
for det_suffix in tree_suffices:
Expand All @@ -169,11 +170,11 @@ def get_plugins_deps(st):


def get_context(is_nt):
"""Need to init a context without initializing the runs_db as that requires
the appropriate passwords.
"""Need to init a context without initializing the runs_db as that requires the appropriate
passwords.
:return: straxen context that mimics the xenonnt_online context without the rundb init
:return: straxen context that mimics the xenonnt_online context
without the rundb init
"""
if is_nt:
st = straxen.contexts.xenonnt_online(_database_init=False)
Expand Down
90 changes: 19 additions & 71 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,82 +1,30 @@
[aliases]
test=pytest

[mypy]
disable_error_code = attr-defined

[flake8]
# Copied from https://github.com/XENONnT/straxen/blob/master/setup.cfg
# Set maximum width of the line to 100
max-line-length = 100

# docstring-style = SPHINX
# E203 whitespace before ':'
# F401 imported but unused
# F403 unable to detect undefined names
# W503 line break before binary operator

# Excluding some directories:
exclude =
.git
.github
docs*
notebooks*
*.yml
__pycache__
.venv
.eggs
*.egg
dist
ignore = E203, W503

# Some pep8 checks we are not interested in. List of codes ignored:
# C409 Unnecessary list passed to tuple() - rewrite as a tuple literal.
# C819 trailing comma prohibited
# D100 Missing docstring in public module
# D205 1 blank line required between summary line and description
# D400 First line should end with a period
# D401 First line should be in imperative mood
# D403 First word of the first line should be properly capitalized
# DAR101 Missing parameter(s) in Docstring: - min_hits
# DAR201 Missing "Returns" in Docstring: - return
# DAR401 Missing exception(s) in Raises section: -r ValueError
# E128 continuation line under-indented for visual indent
# E226 missing whitespace around arithmetic operator
# E251 unexpected spaces around keyword / parameter equals
# F403 'from .veto_events import *' used; unable to detect undefined names
# F541 f-string is missing placeholders
# I001 isort found an import in the wrong position
# I003 isort expected 1 blank line in imports, found 0
# I004 isort found an unexpected blank line in imports
# I005 isort found an unexpected missing import
# P101 format string does contain unindexed parameters
# WPS110 Found wrong variable name: result
# WPS111 Found too short name: m < 2
# WPS211 Found too many arguments: 7 > 5
# WPS122 Found all unused variables definition: _time_zone_widget
# WPS210 Found too many local variables: 8 > 5
# WPS218 Found too many assert statements: 6 > 5
# WPS229 Found too long try body length: 2 > 1
# WPS231 Found function with too much cognitive complexity: 13 > 12
# WPS237 Found a too complex f string
# WPS336 Found explicit string concatenation
# WPS300 Found local folder import
# WPS303 Found underscored number: 35_000
# WPS304 Found partial float
# WPS305 Found `f` string
# WPS306 Found class without a base class: TimeWidgets
# WPS317 Found incorrect multi-line parameters
# WPS318 Found extra indentation
# WPS319 Found bracket in wrong position
# WPS326 Found implicit string concatenation
# WPS331 Found variables that are only used for return: _time_zone_widget
# WPS335 Found incorrect for loop iter type
# WPS420 Found wrong keyword: del
# WPS421 Found wrong function call: print
# WPS432 Found magic number: 2e-05
# WPS433 Found nested import
# WPS435 Found list multiply
# WPS437 Found protected attribute usage: _plugin_class_registry
# WPS440 Found block variables overlap: *
# WPS503 Found useless returning else statement
# WPS504 Found negated condition
# WPS519 Found implicit sum() call
# WPS602 Found using @staticmethod
# Q000 Remove bad quotes
ignore = C409, C819, D100, D205, D400, D401, D403, DAR101, DAR201, DAR401, E128, E226, E251, F403, F541, I001, I003, I004, I005, P101, WPS110, WPS111, WPS211, WPS122, WPS210, WPS218, WPS229, WPS231, WPS237, WPS237, WPS300, WPS303, WPS304, WPS305, WPS306, WPS317, WPS318, WPS319, WPS326, WPS331, WPS335, WPS336, WPS420, WPS421, WPS432, WPS433, WPS440, WPS435, WPS437, WPS503, WPS504, WPS519, WPS602, Q000
per-file-ignores =
straxen/*__init__.py: F401, F403

[docformatter]
in-place = true
blank = true
style = numpy
wrap-summaries = 100
wrap-descriptions = 100

per-file-ignores =
# There are multiple `assert`s in tests, we allow them:
tests/*.py: S101
[doc8]
max-line-length = 100
Loading

0 comments on commit b3998cf

Please sign in to comment.