ENH: Module methods should allow user to specify download_dir
- Dominant language
- Python
- Stars
- 791
- Forks
- 451
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 4
Description
Currently, a number of astroquery modules have methods that download data locally but do not allow the user to specify where that data goes. I.e. they just dump it in the current working directory. This is not ideal.
Some of these modules are tested, and we have to test them using a custom `tmp_cwd` pytest fixture, which does a `pushd` to a temp dir, runs the tests, and then does a `popd` back out. Ideally we shouldn't have to do that.
These are the modules that dump files in the current working directory with no apparent way for the user to specify an alternate dir:
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/cds/core.py#L59
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/esa/iso/core.py#L85-L86
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/esa/iso/core.py#L185
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/esa/xmm_newton/core.py#L50-L51
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/esa/xmm_newton/core.py#L143-L144
The following has a `path` kwarg, but it doesn't work. Still dumps a tarfile in the cwd:
https://github.com/astropy/astroquery/blob/404fa410820bc97a27fcfa18d1f10e9400651374/astroquery/esa/xmm_newton/core.py#L355-L356
A successful PR will fix the module, adding a `download_dir` or similar keyword to the method or internal code, and then replace `tmp_cwd` in the test with the standard Pytest `tmp_path` fixture.
Before:
```python
def test_module_foo(tmp_cwd)
Module.method(some_data)
```
After:
```python
def test_module_foo(tmp_path)
Module.method(some_data, download_dir=tmp_path)
```
And there should be no files dumped into the current working dir.
Contributor guide
Research direction
Start with the download code and tests in astroquery/cds/core.py, astroquery/esa/iso/core.py, and astroquery/esa/xmm_newton/core.py, focusing on the linked lines and the existing tmp_cwd fixture. Replace current-working-directory behavior with a method or internal download_dir/path option, update tests to use tmp_path, and verify that no files are created in the current working directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100