Skip to content

Commit 939994a

Browse files
committed
fix(external): make upload_plot and upload_asset private
Methods on job controller that shouldn't be used directly
1 parent 3a01fba commit 939994a

File tree

2 files changed

+9
-54
lines changed

2 files changed

+9
-54
lines changed

cryosparc/controllers/job.py

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def log_plot(
670670
Returns:
671671
str: Created log event ID
672672
"""
673-
imgfiles = self.upload_plot(
673+
imgfiles = self._upload_plot(
674674
figure,
675675
name=text,
676676
formats=formats,
@@ -820,7 +820,7 @@ def upload(
820820
target_path = PurePosixPath(self.uid) / target_path
821821
return self.cs.upload(self.project_uid, target_path, source, overwrite=overwrite)
822822

823-
def upload_asset(
823+
def _upload_asset(
824824
self,
825825
file: Union[str, PurePath, IO[bytes]],
826826
filename: Optional[str] = None,
@@ -834,26 +834,7 @@ def upload_asset(
834834
If a binary IO object is specified, either a filename or file format
835835
must be specified.
836836
837-
Unlike the ``upload`` method which saves files to the job directory,
838-
this method saves images to the database and exposes them for use in the
839-
job log.
840-
841-
If specifying arbitrary binary I/O, specify either a filename or a file
842-
format.
843-
844-
Args:
845-
file (str | Path | IO): Source asset file path or handle.
846-
filename (str, optional): Filename of asset. If ``file`` is a handle
847-
specify one of ``filename`` or ``format``. Defaults to None.
848-
format (AssetFormat, optional): Format of filename. If ``file`` is
849-
a handle, specify one of ``filename`` or ``format``. Defaults to
850-
None.
851-
852-
Raises:
853-
ValueError: If incorrect arguments specified
854-
855-
Returns:
856-
EventLogAsset: Dictionary including details about uploaded asset.
837+
Do not use directly; use e.g., ``log_plot`` instead.
857838
"""
858839
ext = None
859840
if format:
@@ -870,7 +851,7 @@ def upload_asset(
870851
raise ValueError(f"Invalid asset format {ext}")
871852
return self.cs.api.assets.upload(self.project_uid, self.uid, Stream.load(file), filename=filename, format=ext)
872853

873-
def upload_plot(
854+
def _upload_plot(
874855
self,
875856
figure: FileOrFigure,
876857
name: Optional[str] = None,
@@ -884,32 +865,6 @@ def upload_plot(
884865
Upload the given figure. Returns a list of the created asset objects.
885866
Avoid using directly; use ``log_plot`` instead. See ``log_plot``
886867
additional details.
887-
888-
Args:
889-
figure (str | Path | IO | Figure): Image file path, file handle or
890-
matplotlib figure instance
891-
name (str): Associated name for given figure
892-
formats (list[ImageFormat], optional): Image formats to save plot
893-
into. If a ``figure`` is a file handle, specify
894-
``formats=['<format>']``, where ``<format>`` is a valid image
895-
extension such as ``png`` or ``pdf``. Assumes ``png`` if not
896-
specified. Defaults to ["png", "pdf"].
897-
raw_data (str | bytes, optional): Raw text data for associated plot,
898-
generally in CSV, XML or JSON format. Cannot be specified with
899-
``raw_data_file``. Defaults to None.
900-
raw_data_file (str | Path | IO, optional): Path to raw text data.
901-
Cannot be specified with ``raw_data``. Defaults to None.
902-
raw_data_format (TextFormat, optional): Format for raw text data.
903-
Defaults to None.
904-
savefig_kw (dict, optional): If a matplotlib figure is specified
905-
optionally specify keyword arguments for the ``savefig`` method.
906-
Defaults to dict(bbox_inches="tight", pad_inches=0).
907-
908-
Raises:
909-
ValueError: If incorrect argument specified
910-
911-
Returns:
912-
list[EventLogAsset]: Details about created uploaded job assets
913868
"""
914869
figdata = []
915870
basename = name or "figure"
@@ -952,9 +907,9 @@ def upload_plot(
952907
raise ValueError(f"Invalid raw data filename {raw_data_file}")
953908
raw_data_format = ext
954909

955-
assets = [self.upload_asset(data, filename, fmt) for data, filename, fmt in figdata]
910+
assets = [self._upload_asset(data, filename, fmt) for data, filename, fmt in figdata]
956911
if raw_data_file:
957-
asset = self.upload_asset(raw_data_file, raw_data_filename, raw_data_format or "txt")
912+
asset = self._upload_asset(raw_data_file, raw_data_filename, raw_data_format or "txt")
958913
assets.append(asset)
959914

960915
return assets
@@ -1657,7 +1612,7 @@ def set_output_image(
16571612
assets = (
16581613
[image]
16591614
if isinstance(image, GridFSAsset)
1660-
else self.upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
1615+
else self._upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
16611616
)
16621617
self.model = self.cs.api.jobs.set_output_image(self.project_uid, self.uid, name, assets[0])
16631618

@@ -1677,7 +1632,7 @@ def set_tile_image(
16771632
assets = (
16781633
[image]
16791634
if isinstance(image, GridFSAsset)
1680-
else self.upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
1635+
else self._upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
16811636
)
16821637
self.model = self.cs.api.jobs.set_tile_image(self.project_uid, self.uid, assets[0])
16831638

cryosparc/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def save_external_result(
736736
job.save_output(name, dataset)
737737
if image:
738738
try:
739-
assets = job.upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
739+
assets = job._upload_plot(image, name=name, formats=["png"], savefig_kw=savefig_kw)
740740
job.set_output_image(name, assets[0])
741741
job.set_tile_image(assets[0])
742742
except Exception as e:

0 commit comments

Comments
 (0)