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

Refactor, better mode handling, deprecate asdf.AsdfFile.open #579

Merged
merged 19 commits into from
Oct 31, 2018

Conversation

drdavella
Copy link
Contributor

@drdavella drdavella commented Oct 26, 2018

This resolves #578 (albeit indirectly) and resolves #574.

It refactors the top-level asdf.open function into a standalone factory function in order to enable better decisions about handling file modes, particularly with respect to memory mapping. It also deprecates the use of asdf.AsdfFile.open, since this was not capable of handling such decisions.

There's still a bit more work:

  • Add a warning when explicitly giving mode='r' with copy_arrays=False (no longer applies, see below)
  • Fix any internal usage that results in the above warning
  • Update the change log

Even though this is technically a bug fix, it affects the API and is a big enough change that it should go in 2.2.0.

@stsci-bot
Copy link

stsci-bot bot commented Oct 26, 2018

Hi there @drdavella 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog. I help make sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

@drdavella drdavella added this to the v2.2.0 milestone Oct 26, 2018
@coveralls
Copy link

coveralls commented Oct 26, 2018

Coverage Status

Coverage decreased (-0.008%) to 93.684% when pulling e17a376 on drdavella:refactor-open-handling into eae035d on spacetelescope:master.

asdf/asdf.py Outdated
if asdf_mode is None:
if isinstance(fileobj, str):
parsed = generic_io.urlparse.urlparse(fileobj)
if parsed.scheme == 'http':
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the scheme is https

asdf/asdf.py Outdated
if not _compat:
mode = _check_and_set_mode(fd, mode)
if mode == 'r' and not copy_arrays:
copy_arrays = True
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 print a warning 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.

Yes, but I just pushed a new set of changes that makes this irrelevant. I think the update contains a better solution to the issue you reported.

@@ -1287,6 +1222,132 @@ def get_history_entries(self):
AsdfFile.keys.__doc__ = dict.keys.__doc__


def _check_and_set_mode(fileobj, asdf_mode):

if asdf_mode is not None and asdf_mode not in ['r', 'rw']:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have r+ or w+ modes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you just mean that we should add these and make them equivalent to the current 'rw'? Although I think to be consistent with Python's open API, 'w+' would have to overwrite an existing file. Maybe we should support that, though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure if those modes were supported but not mentioned here or not supported at all. Looks like the latter case so all is good 👍

self._make_array().__setitem__(*args)
except Exception:
self._array = None
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we've cut with 2.7:

except Exception as e:
    self._array = None
    raise e from None

seems better - it does not pollute the error trace.

@drdavella drdavella force-pushed the refactor-open-handling branch 3 times, most recently from 195a029 to 8bb7399 Compare October 30, 2018 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants