-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: dev
Are you sure you want to change the base?
Typings added #12884
Conversation
There was a problem hiding this 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!
f49271e
to
2f725bd
Compare
lib/galaxy/jobs/__init__.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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__
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done #12970
lib/galaxy/jobs/__init__.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thank you!
lib/galaxy/jobs/__init__.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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!
lib/galaxy/jobs/__init__.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
lib/galaxy/jobs/__init__.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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
lib/galaxy/jobs/__init__.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
ef06245
to
e528213
Compare
lib/galaxy/jobs/runners/local.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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 [] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
e528213
to
156b93e
Compare
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 |
Co-authored-by: Marius van den Beek <m.vandenbeek@gmail.com>
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
156b93e
to
f938bf6
Compare
Why: common-workflow-lab#137
What: Improved type hints
How to test the changes?
(Select all options that apply)
License