Skip to content

Move all data to standard data/ location#8413

Merged
eteq merged 12 commits into
astropy:masterfrom
astrofrog:tidy-data
Feb 20, 2019
Merged

Move all data to standard data/ location#8413
eteq merged 12 commits into
astropy:masterfrom
astrofrog:tidy-data

Conversation

@astrofrog

Copy link
Copy Markdown
Member

In our coding guidelines, we say:

Packages can include data in a directory named data inside a subpackage source directory ...

Some sub-packages stick to the convention of using a data/ sub-directory, some don't. This PR cleans things up so that data files (excluding e.g. C/header files for now) are always in a data/ sub-directory. This has the benefit that we can avoid having to use setup_package.py for all different sub-packages just to define get_package_data - instead, we add all the data in data/ sub-directories once and for all in the root setup_package.py.

Side note: the way we declare data files using get_package_data in setup_package.py files is very astropy-idiosyncratic and over-complicates things especially for packages using the package template. The better way to declare package data is through the setup.cfg file, and this PR will make it easier to do so in future for the core package (the setup.cfg file supports glob syntax such as **/data/**/*). Anyway, this is for a future PR!

@codecov

codecov Bot commented Feb 11, 2019

Copy link
Copy Markdown

Codecov Report

Merging #8413 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8413   +/-   ##
=======================================
  Coverage   86.77%   86.77%           
=======================================
  Files         387      387           
  Lines       58134    58134           
  Branches     1060     1060           
=======================================
  Hits        50446    50446           
  Misses       7073     7073           
  Partials      615      615
Impacted Files Coverage Δ
astropy/io/misc/asdf/tags/coordinates/frames.py 82.75% <ø> (ø) ⬆️
astropy/io/ascii/daophot.py 98.76% <ø> (ø) ⬆️
astropy/io/votable/validator/main.py 18.42% <ø> (ø) ⬆️
astropy/io/ascii/cds.py 96.63% <ø> (ø) ⬆️
astropy/utils/data.py 80.93% <ø> (ø) ⬆️
astropy/io/misc/asdf/extension.py 100% <ø> (ø) ⬆️
astropy/io/ascii/ipac.py 97.47% <ø> (ø) ⬆️
astropy/wcs/wcsapi/low_level_api.py 94.73% <100%> (ø) ⬆️
astropy/table/jsviewer.py 98.24% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43eb759...7f97e53. Read the comment docs.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no objections, but only some comments and questions.

There is no need to touch astropy/extern? Won't those changes be overwritten anyway when external packages get updated via straight copy-and-paste?

If we discourage use of setup_package.py, should this sentiment be propagated to astropy-helpers and package-template too, as appropriate?


def test_fk4_no_e_fk4():
lines = get_pkg_data_contents('fk4_no_e_fk4.csv').split('\n')
lines = get_pkg_data_contents('data/fk4_no_e_fk4.csv').split('\n')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this PR is all about consistency, maybe use os.path.join here too? (Same comment applies to all subsequent repeats.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

get_pkg_data_contents deals with this correctly on Windows, and in a lot of other places where we use this function we just use /, presumably for readability. So I'm inclined to leave as-is?

from astropy.wcs.utils import pixel_to_skycoord

header = get_pkg_data_contents('../../wcs/tests/maps/1904-66_TAN.hdr', encoding='binary')
header = get_pkg_data_contents('../../wcs/tests/data/maps/1904-66_TAN.hdr', encoding='binary')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes me wonder if shared data files should be in an upper level data above both wcs and coordinates.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not a bad idea - but maybe worth doing in another PR since I'm not sure what the correct location should be.

Comment thread astropy/setup_package.py
# Find all files in data/ sub-directories since this is a standard location
# for data files. We then need to adjust the paths to be relative to here
# (otherwise glob will be evaluated relative to setup.py)
data_files = glob.glob('**/data/**/*', recursive=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this is a small price to pay for overall simplicity. Does this ever need to be modified if new data files or sub-packages are added? Or when they are removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pllim - this will look a lot simpler once I move the definition of the data to setup.cfg - it will look something like:

[options.package_data]
astropy = **/data/**/*

(plus other files). We don't need to change anything if new data folders are added, or old ones are removed, or files are added/removed inside them.

@astrofrog

Copy link
Copy Markdown
Member Author

There is no need to touch astropy/extern? Won't those changes be overwritten anyway when external packages get updated via straight copy-and-paste?

The only changes in extern are that I am moving the js and css directories inside a common directory called jquery/data, so I'm only changing the top-level organization (not contents)

If we discourage use of setup_package.py, should this sentiment be propagated to astropy-helpers and package-template too, as appropriate?

Yes, but I first want to suggest this idea more formally on the mailing list so we can discuss it - the current PR still uses setup_package.py files, just more efficiently.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tests passed and my comments/questions addressed. Might want to wait for others to approve too, just in case?

@astrofrog

Copy link
Copy Markdown
Member Author

I removed a couple more setup_package.py files that were no longer needed

@bsipocz bsipocz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This deals with an issue that bothered me for a long time! Thank you @astrofrog.

@mhvk

mhvk commented Feb 17, 2019

Copy link
Copy Markdown
Contributor

This is very nice. Just a cc to @drdavella since he is working quite a bit on the asdf schemas, and might like to have a heads-up (I was at first unsure whether that move was a good idea, but ended up thinking the consistency is well worth it).

@drdavella

Copy link
Copy Markdown
Contributor

This looks really good overall. If it were totally up to me I might argue that the ASDF schemas should not be pushed into a data subdirectory and should be handled explicitly in setup.cfg. But for now this looks fine and I don't think it should hold up this PR. We can always go back to change it later.

@eteq eteq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM too. I think this means we're all set and I'll merge this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants