Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typings added #12884

Draft
wants to merge 18 commits into
base: dev
Choose a base branch
from
Draft

Typings added #12884

wants to merge 18 commits into from

Conversation

dakariakin
Copy link

Why: common-workflow-lab#137
What: Improved type hints

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

Copy link
Member

@mvdbeek mvdbeek left a comment

Choose a reason for hiding this comment

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

Thanks a lot @dakariakin!

lib/galaxy/model/dataset_collections/matching.py Outdated Show resolved Hide resolved
lib/galaxy/job_execution/output_collect.py Outdated Show resolved Hide resolved
lib/galaxy/jobs/__init__.py Outdated Show resolved Hide resolved
lib/galaxy/util/bunch.py Outdated Show resolved Hide resolved
test/unit/app/jobs/test_mapper.py Outdated Show resolved Hide resolved
@mvdbeek mvdbeek mentioned this pull request Nov 10, 2021
5 tasks
@@ -579,9 +588,7 @@ def __set_default_job_conf(self):
self._set_default_handler_assignment_methods()
else:
self.app.application_stack.init_job_handling(self)
Copy link
Author

Choose a reason for hiding this comment

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

these two lines moved to __init__

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that works ... it is definitely a code smell and we should have this in __init__, but the handler setup is really complicated.

Copy link
Author

Choose a reason for hiding this comment

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

Should we create a ticket to refactor this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create a ticket to refactor this?

Yes, please

Copy link
Author

Choose a reason for hiding this comment

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

Done #12970

@@ -1228,7 +1238,7 @@ def working_directory(self):

def working_directory_exists(self):
job = self.get_job()
return self.app.object_store.exists(job, base_dir='job_work', dir_only=True, obj_dir=True)
Copy link
Author

Choose a reason for hiding this comment

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

from lib/galaxy/objectstore/init.py

class ObjectStore
...
def exists(self, obj, base_dir=None, dir_only=False, extra_dir=None, extra_dir_at_root=False, alt_name=None):

does not have obj_dir

Copy link
Member

Choose a reason for hiding this comment

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

That's the abstractmethod, but the implementation accepts **kwargs and defers to _exists, which calls _construct_path which does accept obj_dir. I think the fix here is to change the abstractmethod's signature

Copy link
Author

Choose a reason for hiding this comment

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

Updated, thank you!

@@ -1970,28 +1980,28 @@ def get_output_basenames(self):
return [os.path.basename(str(fname)) for fname in self.get_output_fnames()]

def get_output_fnames(self):
if self.output_paths is None:
Copy link
Author

Choose a reason for hiding this comment

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

output_paths is [] now instead of None

Copy link
Member

Choose a reason for hiding this comment

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

This is a caching technique: You set the unset value to None, and then you call an expensive method that generates something that is not None and you store the result of that method. Next time you call the method you know you don't need to re-run the method because self.output_paths is not None. But there may be cases where compute_outputs generates an empty list, in which case we don't want to re-run compute_paths, and that breaks here.

Copy link
Author

Choose a reason for hiding this comment

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

Got it, thank you! I've changed it back, please take a look

@@ -105,7 +105,6 @@ def queue_job(self, job_wrapper):
env=self._environ,
preexec_fn=os.setpgrp)

proc.terminated_by_shutdown = False
Copy link
Author

Choose a reason for hiding this comment

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

subprocess.Popen doesn't have terminated_by_shutdown
and only 1 usage:
if proc.terminated_by_shutdown:

Copy link
Author

Choose a reason for hiding this comment

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

Actually, after rebase on the latest galaxy#dev branch I found that terminated_by_shutdown is used more than once. and also I have a failed test because of that. so I returned it back and ignore the type because I'm not sure how I can add type to terminated_by_shutdown

@@ -117,7 +117,7 @@ def _attach_file(upload_payload, uri, index=0):
elif isinstance(upload_target, DirectoryUploadTarget):
fetch_payload = _fetch_payload(history_id, file_type="directory")
fetch_payload["targets"][0].pop("elements")
tar_path = upload_target.path
Copy link
Author

Choose a reason for hiding this comment

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

DirectoryUploadTarget have only tar_path

@@ -134,7 +138,7 @@ def _parse_output(self, tool, output_instance):
output.metadata_source = ""
output.parent = None
output.label = None
output.count = None
output.count = 1
Copy link
Author

Choose a reason for hiding this comment

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

count initialized as output_dict.get("count", 1) in other places, probably good here too

@@ -220,7 +224,11 @@ def _parse_test(i, test_dict):
name = output["name"]
value = output.get("file", None)
attributes = output
new_outputs.append((name, value, attributes))
Copy link
Author

Choose a reason for hiding this comment

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

@dakariakin dakariakin changed the title WIP: Added types Typings added Nov 11, 2021
@dakariakin dakariakin marked this pull request as ready for review November 11, 2021 20:56
Copy link
Member

@mvdbeek mvdbeek left a comment

Choose a reason for hiding this comment

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

Very nice, thanks so much @dakariakin!

@@ -579,9 +588,7 @@ def __set_default_job_conf(self):
self._set_default_handler_assignment_methods()
else:
self.app.application_stack.init_job_handling(self)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that works ... it is definitely a code smell and we should have this in __init__, but the handler setup is really complicated.

@@ -1228,7 +1238,7 @@ def working_directory(self):

def working_directory_exists(self):
job = self.get_job()
return self.app.object_store.exists(job, base_dir='job_work', dir_only=True, obj_dir=True)
Copy link
Member

Choose a reason for hiding this comment

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

That's the abstractmethod, but the implementation accepts **kwargs and defers to _exists, which calls _construct_path which does accept obj_dir. I think the fix here is to change the abstractmethod's signature

@@ -1970,28 +1980,28 @@ def get_output_basenames(self):
return [os.path.basename(str(fname)) for fname in self.get_output_fnames()]

def get_output_fnames(self):
if self.output_paths is None:
Copy link
Member

Choose a reason for hiding this comment

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

This is a caching technique: You set the unset value to None, and then you call an expensive method that generates something that is not None and you store the result of that method. Next time you call the method you know you don't need to re-run the method because self.output_paths is not None. But there may be cases where compute_outputs generates an empty list, in which case we don't want to re-run compute_paths, and that breaks here.

@@ -105,7 +105,7 @@ def queue_job(self, job_wrapper):
env=self._environ,
preexec_fn=os.setpgrp)

proc.terminated_by_shutdown = False
proc.terminated_by_shutdown = False # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

now that we have show_error_codes = True under [mypy] in setup.cfg, you can refine these # type: ignore to include the specific error code being ignored. Example: # type: ignore[attr-defined]

Copy link
Author

Choose a reason for hiding this comment

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

I've updated it, thank you!

if self.linked_structure:
return self.linked_structure.walk_collections(self.collections)
else:
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

I think raising an Exception would be better instead of silently returning an empty set, yes?

Copy link
Author

Choose a reason for hiding this comment

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

Changed back to assert. I think it could break some tests, but let's see

@mvdbeek mvdbeek modified the milestones: 22.01, 22.05 Jan 14, 2022
@mvdbeek mvdbeek removed this from the 22.05 milestone May 25, 2022
@nsoranzo nsoranzo marked this pull request as draft September 16, 2022 00:09
@dakariakin
Copy link
Author

The original issue is closed common-workflow-lab#137

@dakariakin dakariakin closed this Oct 10, 2022
@mr-c
Copy link
Contributor

mr-c commented Oct 10, 2022

The original issue is closed common-workflow-lab#137

Oh, I didn't mean that this PR was no longer needed! Can you reopen this?

@nsoranzo nsoranzo reopened this Oct 10, 2022
@dakariakin
Copy link
Author

The original issue is closed common-workflow-lab#137

Oh, I didn't mean that this PR was no longer needed! Can you reopen this?

Sorry, I thought it was done in some other PR. I'll rebase this PR and prepare it for a code review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants