Skip to content

Commit f91413c

Browse files
committed
Significant refactoring of grdata.py
I also added documentation and integrated the tool into the testing framework.
1 parent 986a773 commit f91413c

File tree

8 files changed

+872
-274
lines changed

8 files changed

+872
-274
lines changed

doc/source/Python.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ If your build directory was located in the root level of the grackle repository
5555
.. note:: Pygrackle can only be run when Grackle is compiled without OpenMP.
5656
See :ref:`openmp`.
5757

58+
Installing DataFiles
59+
++++++++++++++++++++
60+
61+
To install the datafiles in a location usable for automatic usage in the Pygrackle examples (and tests) we recommend invoking the following command (from any directory):
62+
63+
.. code-block:: shell-session
64+
65+
$ python -m pygrackle fetch
66+
67+
:ref:`This section <manage-data-files>` for more details about customizing the the location where data is stored and about managing datafiles in general.
68+
5869
.. _pygrackle-dev:
5970

6071
Installing Pygrackle Development Requirements

doc/source/Tools.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
.. _manage-data-files:
3+
4+
Datafile Management
5+
===================
6+
7+
We provide a command line tool to optionally manage Grackle's datafiles.
8+
9+
At a Quick Glance
10+
-----------------
11+
12+
Currently, this command line tool is only accessible when :ref:`pygrackle is installed <install-pygrackle>`.
13+
To execute the tool execute
14+
15+
.. code-block:: shell-session
16+
17+
$ python -m pygrackle <args>...
18+
19+
Where ``<args>...`` is replaced with one or more command-line arguments.
20+
For example, ``fetch`` will invoke a subcommand that downloads all associated files (if they aren't already downloaded).
21+
You can use the ``--help`` option to get a list of all subcommands.
22+
You can also pass the ``--help`` option after the name of a subcommand (e.g. you can use ``fetch --help``) to get more details about subcommand-specific options.
23+
24+
.. note::
25+
26+
At the moment, this functionality is most useful for pygrackle.
27+
In the near future [#df1]_\ , it will be possible install pygrackle without manually downloading the grackle repository.
28+
At that time, this will be the most efficient way to retrieve the files.
29+
The pygrackle examples and some of the pygrackle tests rely upon this functionality.
30+
However, you are free to completely ignore this functionality for your own purposes.
31+
32+
There is ongoing work to implement functionality for the Grackle C library to directly access the datafiles managed by this tool.
33+
When these efforts are finished, we plan to additionally provide this command-line-tool as a standalone program that is always installed alongside Grackle (so that you can access this functionality without installing pygrackle)
34+
35+
Description
36+
-----------
37+
38+
.. include:: ../../src/python/pygrackle/utilities/grdata.py
39+
:start-after: [[[BEGIN-SECTION:DESCRIPTION]]]
40+
:end-before: [[[END-SECTION:DESCRIPTION]]]
41+
42+
43+
44+
Motivation
45+
----------
46+
47+
.. include:: ../../src/python/pygrackle/utilities/grdata.py
48+
:start-after: [[[BEGIN-SECTION:MOTIVATION]]]
49+
:end-before: [[[END-SECTION:MOTIVATION]]]
50+
51+
52+
How it works
53+
------------
54+
55+
.. include:: ../../src/python/pygrackle/utilities/grdata.py
56+
:start-after: [[[BEGIN-SECTION:INTERNALS-OVERVIEW]]]
57+
:end-before: [[[END-SECTION:INTERNALS-OVERVIEW]]]
58+
59+
60+
Sample Directory Structure
61+
++++++++++++++++++++++++++
62+
63+
Down below, we sketch out what the directory-structure might look like:
64+
65+
66+
.. literalinclude:: ../../src/python/pygrackle/utilities/grdata.py
67+
:language: none
68+
:start-after: [[[BEGIN:DIRECTORY-CARTOON]]]
69+
:end-before: [[[END:DIRECTORY-CARTOON]]]
70+
71+
72+
.. rubric:: Footnotes
73+
74+
.. [#df1] Once `GH-#208 <https://github.com/grackle-project/grackle/pull/208>`__ is merged, you will be able to instruct pip to install pygrackle by just specifying the URL of the GitHub repository.
75+
We also have plans to upload pygrackle to pip.

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Contents:
4747
Reference.rst
4848
Versioning.rst
4949
Python.rst
50+
Tools.rst
5051
Conduct.rst
5152
Contributing.rst
5253
Help.rst

src/python/pygrackle/file_registry/file_registry.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// -> ``<outpath>`` with a path to the output file
77
// -> ``<dir>`` with a path to the directory containing all files that are
88
// to be included in the registry
9-
{"CloudyData_UVB=FG2011.h5", "5b3423fb5cb96d6f8fae65655e204f1f82a276fa"},
10-
{"CloudyData_UVB=FG2011_shielded.h5", "60d13b4632f074fcb295f7adea85843046c0d4ef"},
11-
{"CloudyData_UVB=HM2012.h5", "3ae95f71926aa9543964fbd41c5e53a42345c19c"},
12-
{"CloudyData_UVB=HM2012_high_density.h5", "6db93abf8cb818975e8d751776328c5dab44d4ee"},
13-
{"CloudyData_UVB=HM2012_shielded.h5", "16cab5b5bd0bf5ef87db717dd5e8901be11812c2"},
14-
{"CloudyData_noUVB.h5", "55fed7c4bfd10e35d60660ca1adc5ceb411befb2"},
15-
{"cloudy_metals_2008_3D.h5", "ade563216d1102e8befab822cbb60c418b130aa1"}
9+
{"CloudyData_UVB=FG2011.h5", "sha1:5b3423fb5cb96d6f8fae65655e204f1f82a276fa"},
10+
{"CloudyData_UVB=FG2011_shielded.h5", "sha1:60d13b4632f074fcb295f7adea85843046c0d4ef"},
11+
{"CloudyData_UVB=HM2012.h5", "sha1:3ae95f71926aa9543964fbd41c5e53a42345c19c"},
12+
{"CloudyData_UVB=HM2012_high_density.h5", "sha1:6db93abf8cb818975e8d751776328c5dab44d4ee"},
13+
{"CloudyData_UVB=HM2012_shielded.h5", "sha1:16cab5b5bd0bf5ef87db717dd5e8901be11812c2"},
14+
{"CloudyData_noUVB.h5", "sha1:55fed7c4bfd10e35d60660ca1adc5ceb411befb2"},
15+
{"cloudy_metals_2008_3D.h5", "sha1:ade563216d1102e8befab822cbb60c418b130aa1"}

src/python/pygrackle/utilities/data_path.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111
# software.
1212
########################################################################
1313

14-
from functools import partial
14+
import io
1515
import os
1616
import sys
1717

1818
from pygrackle.grackle_wrapper import get_grackle_version
19-
from pygrackle.utilities.grdata import make_config_objects, get_version_dir
19+
from pygrackle.utilities.grdata import (
20+
make_config_objects,
21+
VersionDataManager,
22+
_parse_file_registry,
23+
)
2024
from pygrackle.utilities.misc import dirname
2125

26+
# maybe it would be better to export nothing?
27+
__all__ = ["grackle_data_dir"]
28+
2229

2330
# when we shift to scikit-build-core we can do something more robust here
2431
def _is_editable_install():
@@ -55,4 +62,13 @@ def _get_file_registry_contents(editable_install):
5562
file_registry_file=_get_file_registry_contents(is_editable_install),
5663
)
5764

58-
grackle_data_dir = get_version_dir(*_CONFIG_PAIR)
65+
_MANAGER = VersionDataManager.create(*_CONFIG_PAIR)
66+
67+
68+
def _download_all_datafiles():
69+
"""Download all datafiles if it hasn't been downloaded already."""
70+
registry = _parse_file_registry(_CONFIG_PAIR[1].file_registry_file)
71+
return _MANAGER.fetch_all(registry)
72+
73+
74+
grackle_data_dir = _MANAGER.version_dir

0 commit comments

Comments
 (0)