Skip to content

[MAINT] Cleanup EngineBase #2376

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

Merged
merged 7 commits into from
Jan 18, 2018
Merged

[MAINT] Cleanup EngineBase #2376

merged 7 commits into from
Jan 18, 2018

Conversation

oesteban
Copy link
Contributor

@oesteban oesteban commented Jan 17, 2018

A quick cleanup of the EngineBase class:

  • Added new tests for this base class
  • Refactored test_utils.py, and moved some tests to test_nodes.py and test_workflows.py
  • Cleaned up tests:
    • Avoid using lambdas when testing exceptions (not necessary anymore with pytest)
    • Parametrize test_workflows.py::test_outputs_removal_wf adding MultiProc and removing for loops

from ...interfaces.base import DynamicTraitedSpec
from ...utils.filemanip import loadpkl, savepkl

logger = logging.getLogger('workflow')
standard_library.install_aliases()
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the point of having this before most imports to ensure that the imports work as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The aliases would modify the behavior of imports, so I guess that is the reason. Anyways, I moved it because flake8 suggested so. I can roll back at any moment

Copy link
Member

Choose a reason for hiding this comment

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

@mgxd @satra Are you familiar enough with future.standard_library.install_aliases to know whether there's a semantic change being made by reordering here?

You can also add a # noqa comment to pacify flake8, if you do return it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

some comments on the order are here: https://pypi.python.org/pypi/future

All examples here have it at the very beginning

if name and bool(re.match(r'^[\w_]+$', name)):
self._name = name
else:
raise ValueError('[Workflow|Node] name "%s" is not valid.' % name)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer:

if not name or not re.match(r'^\w+$', name):
    raise ValueError(...)
self._name = name

Note that I simplified the regex. \w matches underscores.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we were supporting also dashes - so I'll add them.

@oesteban oesteban requested review from djarecka and mgxd January 18, 2018 04:58
@oesteban
Copy link
Contributor Author

Testing with FMRIPREP this seems to work correctly.

@@ -18,18 +18,14 @@
absolute_import)
from builtins import object

from future import standard_library
standard_library.install_aliases()
Copy link
Member

Choose a reason for hiding this comment

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

I meant not to bother removing or reordering, and just tolerate the PEP8 violation. Unless it's causing problems, let's not change this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked locally with Python 2 and this aliases are not necessary. Let's get rid of them whenever possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@oesteban @effigies I'm not sure if I understand, does standard_library.install_aliases() at the end of the import block (e.g. in node.py or workflow.py) changes anything?

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 believe it does.



def test_node_init():
with pytest.raises(Exception):
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can change change Exception to TypeError

@oesteban
Copy link
Contributor Author

Good to go!

@effigies effigies merged commit ae3fd02 into nipy:master Jan 18, 2018
@oesteban oesteban deleted the maint/engine-base branch January 18, 2018 23:02
@effigies effigies added this to the 1.0 milestone Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants