Skip to content

Fix omerotools - #157

Open
loicsauteur wants to merge 15 commits into
imcf:masterfrom
loicsauteur:fix-omerotools
Open

loicsauteur wants to merge 15 commits into
imcf:masterfrom
loicsauteur:fix-omerotools

Conversation

@loicsauteur

Copy link
Copy Markdown

PR for issue #154

  • Removes unnecessary code in parse_url
  • Updates description of parse_url
  • Fixes some typos
  • Raises FileNotFoundError for upload_image_to_omero

All changes done with no testing. I was unable to create an env from poetry (sorry).

ehrenfeu added 2 commits June 25, 2026 14:51
Signed-off-by: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
@ehrenfeu

ehrenfeu commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thanks @loicsauteur! ❤️

🧾 An issue like this definitely reveals the need for being able to to run tests on the code.

Since we can't properly emulate the fr.igred.omero.Client behavior without a lot of potentially error-prone 🤯 mocking, I'd prefer to rewrite the entire function such that it first does all the string parsing and list assembling (in a separate function*) and only at the very end does the required client.getDataset() / client.getImage() calls.

(*that separate function should be string-based only, making it approachable for pytest 🧪)

Would you like to work on it, otherwise I'd put it onto our list for the next Coding 🧑‍💻 Session (you're welcome to join if you wish)?

Comment thread src/imcflibs/imagej/omerotools.py
Comment on lines 204 to +221
@@ -222,7 +218,7 @@ def delete_keyvalue_annotations(user_client, object_wrapper):
user_client : fr.igred.omero.Client
Client used for login to OMERO.
object_wrapper : fr.igred.omero.repositor.GenericRepositoryObjectWrapper
Wrapper to the object for the anotation.
Wrapper to the object for the annotation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer having separate commits for unrelated changes like fixing typos in docstrings as otherwise the git history if this very line will read Update parse_url description & remove unnecessary code which can be quite confusing.

Comment thread src/imcflibs/imagej/omerotools.py Outdated
Comment on lines +191 to +192
if not os.path.exists(path):
raise FileNotFoundError(f"File {path} does not exist.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be very pythonic to me - what happens if this check is not present but the importImage() call is performed on a non-existing file.

Shouldn't it raise a similar exception already, or is this something weird due to the Java stuff going on in the call?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file does not exist it throws:

File "__pyclasspath__/imcflibs/imagej/omerotools.py", line 178, in upload_image_to_omero
IndexError: index out of range: 0

importImage() should throw an IOException but not fully clear where... the library is very convoluted... see here if you like.

If by pythonic you mean something else, happy to get your inputs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, this does makes sense.

An IndexError is not what you'd expect when a file is missing. Although in this case that's simply due to the [0] at the end of that all-in-one return line.

I'm fine leaving it like this for now, but please add a comment to the if statement explaining this.

@loicsauteur

Copy link
Copy Markdown
Author

I'd welcome the opportunity to join one of your coding sessions and work on this.

As I am not really used to working on a collaborative project, I'm happy about the pointers and how-to. E.g.:

  • how-to comment on a commit with more than the commit message

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33%. Comparing base (bc94ec9) to head (8c5ac37).

Additional details and impacted files
@@          Coverage Diff          @@
##           master   #157   +/-   ##
=====================================
  Coverage      33%    33%           
=====================================
  Files          25     25           
  Lines        1806   1805    -1     
=====================================
  Hits          591    591           
+ Misses       1215   1214    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loicsauteur
loicsauteur force-pushed the fix-omerotools branch 2 times, most recently from 8c5ac37 to 87f5674 Compare October 14, 2026 10:09
@ehrenfeu ehrenfeu added this to the 2.0.0 milestone Oct 14, 2026
@ehrenfeu ehrenfeu added bug Something isn't working unit testing A unit test should be created labels Oct 14, 2026
ehrenfeu and others added 7 commits October 14, 2026 14:11
Removed 'image_ids = ...' is immediately overwriten by the subsequent line. Removed lines ('image-' URL handling) are handled in the 'elif'  before.
Clarified that it works for Dataset IDs or Image IDs URLs. Removed that it handles Dataset IDs directly (which it does not to my knowledge.
Fixed 'anotations' -> 'annotations' twice in function descriptions
Import image did not raise file error if it did not exist.
This function is part the refactoring of parse_url. It takes an URL and OMERO type to return a list of string IDs. Along with a test.
This function is part the refactoring of parse_url. It takes an URL and return a list of string IDs and the OMERO type (Project, Dataset or ID). Along with a test.
The string handling of parse_url happens now in other functions. The logic stays the same. In addition, it raises an NotImplementedError for Project-URLs.
@loicsauteur

Copy link
Copy Markdown
Author

I added the refactoring of the parse_url:

2 additional functions with their tests (in test_omerotools.py)

I also added a very basic test function for parse_url itself, but it only tests the first part of the function (for the expected risen errors).

Important: I have not tested the modified parse_url function in Fiji or similar...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working unit testing A unit test should be created

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants