Skip to content

Commit

Permalink
MNT #334 Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 6, 2020
1 parent b803527 commit f544e8d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions apstools/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,7 @@ def generate_datum(self, key, timestamp, datum_kwargs):
datum_kwargs["HDF5_file_name"] = hdf5_file_name

logger.debug("make_filename: %s", hdf5_file_name)
logger.debug("write_path: %s", write_path)
return super().generate_datum(key, timestamp, datum_kwargs)

def get_frames_per_point(self):
Expand Down
3 changes: 2 additions & 1 deletion apstools/filewriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
SPEC_TIME_FORMAT = "%a %b %d %H:%M:%S %Y"
SCAN_ID_RESET_VALUE = 0


def _rebuild_scan_command(doc):
"""
reconstruct the scan command for SPEC data file #S line
Expand Down Expand Up @@ -657,7 +658,7 @@ def myPlan():
#C Mon Jan 28 12:48:14 2019. exit_status = success
"""
# global specwriter # such as: specwriter = SpecWriterCallback()
global specwriter # such as: specwriter = SpecWriterCallback()
writer = writer or specwriter
if doc is None:
if writer.scanning:
Expand Down
27 changes: 15 additions & 12 deletions apstools/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def addDeviceDataAsStream(devices, label):
yield from bps.save()


def execute_command_list(filename, commands, md={}):
def execute_command_list(filename, commands, md=None):
"""
plan: execute the command list
Expand Down Expand Up @@ -206,7 +206,7 @@ def get_command_list(filename):
def lineup(
counter, axis, minus, plus, npts,
time_s=0.1, peak_factor=4, width_factor=0.8,
_md={}):
md=None):
"""
lineup and center a given axis, relative to current position
Expand Down Expand Up @@ -312,16 +312,16 @@ def peak_analysis():
bec.peaks.aligned = aligned
bec.peaks.ATTRS = ('com', 'cen', 'max', 'min', 'fwhm')

md = dict(_md)
md["purpose"] = "alignment"
yield from bp.rel_scan([counter], axis, minus, plus, npts, md=md)
_md = dict(purpose="alignment")
_md.update(md or {})
yield from bp.rel_scan([counter], axis, minus, plus, npts, md=_md)
yield from peak_analysis()

if bec.peaks.aligned:
# again, tweak axis to maximize
md["purpose"] = "alignment - fine"
_md["purpose"] = "alignment - fine"
fwhm = bec.peaks["fwhm"][counter.name]
yield from bp.rel_scan([counter], axis, -fwhm, fwhm, npts, md=md)
yield from bp.rel_scan([counter], axis, -fwhm, fwhm, npts, md=_md)
yield from peak_analysis()

if scaler is not None:
Expand Down Expand Up @@ -594,7 +594,7 @@ def register_command_handler(handler=None):
_COMMAND_HANDLER_ = handler or execute_command_list


def run_command_file(filename, md={}):
def run_command_file(filename, md=None):
"""
plan: execute a list of commands from a text or Excel file
Expand All @@ -614,8 +614,10 @@ def run_command_file(filename, md={}):
*new in apstools release 1.1.7*
"""
_md = dict(command_file=filename)
_md.update(md or {})
commands = get_command_list(filename)
yield from _COMMAND_HANDLER_(filename, commands)
yield from _COMMAND_HANDLER_(filename, commands, md=_md)


def snapshot(obj_list, stream="primary", md=None):
Expand Down Expand Up @@ -738,7 +740,7 @@ def sscan_1D(
running_stream="primary",
final_array_stream=None,
device_settings_stream="settings",
md={}):
md=None):
"""
simple 1-D scan using EPICS synApps sscan record
Expand Down Expand Up @@ -836,9 +838,10 @@ def phase_cb(value, timestamp, **kwargs):
# watch for new data to be read out
sscan.scan_phase.subscribe(phase_cb)

md["plan_name"] = "sscan_1D"
_md = dict(plan_name="sscan_1D")
_md.update(md or {})

yield from bps.open_run(md) # start data collection
yield from bps.open_run(_md) # start data collection
yield from bps.mv(sscan.execute_scan, 1) # start sscan
started = True

Expand Down
3 changes: 2 additions & 1 deletion apstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def itemizer(fmt, items):


def listruns(
num=20, keys=[], printing=True,
num=20, keys=None, printing=True,
show_command=True, db=None,
exit_status=None,
**db_search_terms):
Expand Down Expand Up @@ -308,6 +308,7 @@ def listruns(
*new in apstools release 1.1.10*
"""
db = db or ipython_shell_namespace()["db"]
keys = keys or []

if show_command:
labels = "scan_id command".split() + keys
Expand Down
2 changes: 1 addition & 1 deletion create_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def findGitConfigFile():
Needs testing for when things are wrong.
"""
path = os.getcwd()
for i in range(99):
for _ in range(99):
config_file = os.path.join(path, ".git", "config")
if os.path.exists(config_file):
return config_file # found it!
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_receiver_battery(self):
callback.file_extension,
apstools.filewriters.NEXUS_FILE_EXTENSION)

for plan_name, document_set in self.db.items():
for plan_name in self.db:
callback.clear()
callback.file_path = self.tempdir
self.assertIsNone(callback.uid, plan_name)
Expand Down

0 comments on commit f544e8d

Please sign in to comment.