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

Extend Gemini to include getting file content and logging out of GOA #2851

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davner
Copy link

@davner davner commented Oct 17, 2023

This PR extends the Gemini module.

  1. get_file_content - Grabs the content of a file, does not save to disk.
  2. logout - Deletes the Gemini Observatory Archive cookie.
  3. get_file_url - helper method to get the URL for direct file download.

I have updated the documentation to include the new functions and included tests.

@pep8speaks
Copy link

pep8speaks commented Oct 17, 2023

Hello @davner! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-11-05 20:52:46 UTC

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Attention: Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 67.53%. Comparing base (701a4e3) to head (348ef14).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
astroquery/gemini/core.py 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2851      +/-   ##
==========================================
+ Coverage   67.49%   67.53%   +0.03%     
==========================================
  Files         233      233              
  Lines       18420    18444      +24     
==========================================
+ Hits        12433    12456      +23     
- Misses       5987     5988       +1     

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

@bsipocz bsipocz added the gemini label Oct 18, 2023
@bsipocz bsipocz added this to the v0.4.7 milestone Oct 18, 2023
Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

There are a lot of test failures, those need to be fixed before this can go ahead. Also, will need a changelog entry.

(run pytest -P gemini -R to run the failing remote tests)

Big picture thing, that may not be known outside of a small group is that we're working on moving adding some download utilities to pyvo and plan to use that in astroquery. So it maybe useful for this PR/work, too (but given it's not yet merged, let alone released, I would not wait for it with this PR)

Besides I left a couple of smaller review comments.

if length == 0:
log.warn(f'URL {url} has length=0')

blocksize = astropy.utils.data.conf.download_block_size
Copy link
Member

Choose a reason for hiding this comment

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

you need to explicitly import this, importing astropy above is not enough.

@@ -433,6 +434,97 @@ def get_file(self, filename, *, download_dir='.', timeout=None):
local_filepath = os.path.join(download_dir, filename)
self._download_file(url=url, local_filepath=local_filepath, timeout=timeout)

def _download_file_content(self, url, timeout=None, auth=None, method="GET", **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Make optional arguments kwarg only. Also, what are the possible keys in kwargs, explicitly list them if possible.

Suggested change
def _download_file_content(self, url, timeout=None, auth=None, method="GET", **kwargs):
def _download_file_content(self, url, *, timeout=None, auth=None, method="GET", **kwargs):

Copy link
Author

Choose a reason for hiding this comment

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

The kwargs could be any accepted keys in the underlying Session.request. I can make a note of them.

self._authenticated = False

def get_file_content(self, filename, timeout=None, auth=None, method="GET", **kwargs):
"""Wrapper around `_download_file_content`.
Copy link
Member

Choose a reason for hiding this comment

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

Use double backticks for everything that is not sphinx linkable.

str
The URL where the file can be downloaded.
"""
return f"https://archive.gemini.edu/file/{filename}"
Copy link
Member

Choose a reason for hiding this comment

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

This url is hardwired at a lot of places, couldn't ve instead use the conf value, or store it as an instance attribute and use it here and elsewhere, too?

Copy link
Author

@davner davner Nov 15, 2023

Choose a reason for hiding this comment

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

I agree. I have refactored the gemini module to use conf more and extend the module in a planned future PR.

I did not want to make much changes on this first PR so I could first confirm that the documentation and coding styling matched astroquery.

@davner
Copy link
Author

davner commented Nov 15, 2023

@bsipocz Thanks for the review. I am working on addressing your comments. I have comments below:

  1. I had a misunderstanding on the remote tests, as they pass with pytest astroquery/gemini/tests -m remote_data --remote-data=any however they fail with pytest -P gemini -R with repeated AttributeError: 'dict' object has no attribute 'extract_cookies'. I need to investigate this more.
  2. I agree that some code and constants are repeated throughout the gemini module. I will have this addressed in the next PR I make as it extends this module to include downloading and unpacking the Gemini Observatory Archive tar files and calibration data. This PR was more to get my feet wet with contributing to astroquery, but if you would like, I can combine PRs.

@bsipocz bsipocz modified the milestones: v0.4.7, v0.4.8 Mar 9, 2024
@davner davner force-pushed the gemini-download-content branch from ba2a654 to 348ef14 Compare November 5, 2024 20:52
@bsipocz bsipocz removed this from the v0.4.8 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants