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

Hide _out tables and restore metadata in Datasette #3226

Merged
merged 10 commits into from
Jan 29, 2024

Conversation

bendnorman
Copy link
Member

@bendnorman bendnorman commented Jan 9, 2024

Overview

This PR:

  • Hides _out tables from datasette
  • Removes some resources sorting logic that didn't work
  • Resolve a bug that resulted in most of our output tables not having any metadata on datasette
  • Adds to test to make sure all tables in the databases have metadata

This PR will not deal with sorting the tables on datasette.

Testing

How did you make sure this worked? How can a reviewer verify this?

To-do list

Preview Give feedback

This commit also resolves a couple of bugs in our metadata management
and datasette deployment. Pretty much all out_ tables were missing metadata on datasette
because DatasetteMetadata.from_data_source_ids() does some filtering that didn't
include the output tables. Also, the epacamd_eia Source was incorrectly renamed
to core_epa__assn_eia_epacamd during the big rename.
@@ -299,7 +299,7 @@
"license_raw": LICENSES["us-govt"],
"license_pudl": LICENSES["cc-by-4.0"],
},
"core_epa__assn_eia_epacamd": {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an oopsie from #2995

for res in pkg.resources
if res.etl_group in data_source_ids + extra_etl_groups
]
resources = Package.from_resource_ids().get_sorted_resources()
Copy link
Member Author

Choose a reason for hiding this comment

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

The resources are correctly sorted in the metadata.yml file but it doesn't have an effect on the final ordering in the datasette UI. Any idea how to do this @zaneselvans?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like I might need to adjust the HTML templates datasette uses. I think it's currently just pulling the table names from the database directly: https://github.com/simonw/datasette/blob/2ff4d4a60a348c143f79d63c48c329ffd0c1f02f/datasette/templates/database.html#L50-L82

Copy link
Member

Choose a reason for hiding this comment

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

The layout of Datasette pages (and the set of pages which exist) can be customized extensively with custom JavaScript, CSS, and Jinja templates

It seems like maybe we want a child-template that extends the database page that lists all of the tables, and sorts / filters them.

Copy link
Member

Choose a reason for hiding this comment

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

And if we want to hide all of the _out tables, then it seems like we can add them to the list of hidden_tables in the metadata that we generate.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like we need to create a directory of our own templates and create a database-pudl.html Jinja template that overrides the default database.html template, at least for the content block?

@bendnorman bendnorman added output Exporting data from PUDL into other platforms or interchange formats. datasette Issues related the accessing PUDL data via Datasette. labels Jan 12, 2024
@bendnorman bendnorman added this to the v2024.01 milestone Jan 12, 2024
devtools/datasette/publish.py Outdated Show resolved Hide resolved
devtools/datasette/publish.py Outdated Show resolved Hide resolved
devtools/datasette/publish.py Outdated Show resolved Hide resolved
devtools/datasette/publish.py Outdated Show resolved Hide resolved
devtools/datasette/publish.py Outdated Show resolved Hide resolved
src/pudl/metadata/classes.py Show resolved Hide resolved
@zaneselvans zaneselvans changed the title Sort tables on datasette deployment Hide _out tables and restore metadata in Datasette Jan 17, 2024
@bendnorman bendnorman linked an issue Jan 18, 2024 that may be closed by this pull request
Comment on lines +129 to +132
# Make sure we have the expected metadata for databases
# headed to deployment.
if deploy != "metadata":
check_tables_have_metadata(metadata_yml, databases)
Copy link
Member Author

@bendnorman bendnorman Jan 26, 2024

Choose a reason for hiding this comment

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

I think this solves the entanglement issue you mentioned @zaneselvans . We only check if all of the databases tables have datasette metadata if we are actually deploying datatsette.

Copy link
Member

Choose a reason for hiding this comment

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

The way the Datasette metadata is generated, and the checks rely on bespoke logic for constructing paths to the databases we expect to have metadata, and the dependence on the XBRL datapackage.json sometimes and the SQLite files other times and the PUDL Package other times all feels pretty fragile and janky, but that's beyond the scope of this PR.

Copy link
Member

@zaneselvans zaneselvans left a comment

Choose a reason for hiding this comment

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

Added suggestions for a docstring and a more restrictive table name regex for sorting.

Comment on lines +129 to +132
# Make sure we have the expected metadata for databases
# headed to deployment.
if deploy != "metadata":
check_tables_have_metadata(metadata_yml, databases)
Copy link
Member

Choose a reason for hiding this comment

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

The way the Datasette metadata is generated, and the checks rely on bespoke logic for constructing paths to the databases we expect to have metadata, and the dependence on the XBRL datapackage.json sometimes and the SQLite files other times and the PUDL Package other times all feels pretty fragile and janky, but that's beyond the scope of this PR.

src/pudl/helpers.py Show resolved Hide resolved
src/pudl/helpers.py Outdated Show resolved Hide resolved
src/pudl/metadata/classes.py Outdated Show resolved Hide resolved
src/pudl/metadata/classes.py Show resolved Hide resolved
test/integration/datasette_metadata_test.py Show resolved Hide resolved
src/pudl/helpers.py Outdated Show resolved Hide resolved
@zaneselvans zaneselvans added the metadata Anything having to do with the content, formatting, or storage of metadata. Mostly datapackages. label Jan 27, 2024
@bendnorman bendnorman marked this pull request as ready for review January 29, 2024 17:59
@bendnorman bendnorman enabled auto-merge (squash) January 29, 2024 18:00
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (be501da) 92.72% compared to head (b77810f) 92.83%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3226      +/-   ##
==========================================
+ Coverage   92.72%   92.83%   +0.12%     
==========================================
  Files         145      145              
  Lines       13111    13156      +45     
==========================================
+ Hits        12156    12213      +57     
+ Misses        955      943      -12     

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

@zaneselvans zaneselvans disabled auto-merge January 29, 2024 19:37
@zaneselvans zaneselvans merged commit dd80a65 into main Jan 29, 2024
20 checks passed
@zaneselvans zaneselvans deleted the order-pudl-datasette-tables branch January 29, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasette Issues related the accessing PUDL data via Datasette. metadata Anything having to do with the content, formatting, or storage of metadata. Mostly datapackages. output Exporting data from PUDL into other platforms or interchange formats.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Remove _out tables from datasette and sort tables
2 participants