Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
π synced file(s) with WordPress/openverse (#1092)
Openverse (Bot)d92e6b6cdfda
diff --git a/.github/workflows/new_issues.yml b/.github/workflows/new_issues.ymlindex 1f3f4ce9d..e25a51d45 100644--- a/.github/workflows/new_issues.yml+++ b/.github/workflows/new_issues.yml@@ -8,7 +8,6 @@ on:env:GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} # Projects need a personal access token to work.ISSUE_ID: ${{ github.event.issue.node_id }} # The global issue ID that works in both REST and GraphQL APIs.- PROJECT_ID: "PVT_kwDOAAQ2Js4AMZdL" # The ID for the Openverse project (#75).jobs:add_issue:@@ -26,65 +25,18 @@ jobs:add_issue_to_project:name: Add new issue to projectruns-on: ubuntu-latest- env:- PRIORITY_FIELD_ID: "PVTSSF_lADOAAQ2Js4AMZdLzgH6Kbo" # The ID for the project Priority custom field.steps:- - name: Add issue to "Backlog"- run: |- # shellcheck disable=SC2016- gh api graphql -f query='- mutation($project:ID!, $issue:ID!) {- addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {- item {- id- content {- ... on Issue {- labels(first: 10) {- nodes {- name- }- }- }- }- }- }- }' -f project="$PROJECT_ID" -f issue="$ISSUE_ID" >> issue_data.json-- echo 'ITEM_ID='"$(jq '.data.addProjectV2ItemById.item.id' issue_data.json)" >> "$GITHUB_ENV"- ITEM_PRIORITY="$(jq '.data.addProjectV2ItemById.item.content.labels.nodes[] | select(.name | contains("priority")).name | split(": ")[1]' issue_data.json)" >> "$GITHUB_ENV"- # The IDs for the project's Priority custom field options.- # These IDs were manually retrieved from the GitHub API.- if [[ $ITEM_PRIORITY == "low" ]]; then- PRIORITY_VALUE_ID="279ae886"- elif [[ $ITEM_PRIORITY == "medium" ]]; then- PRIORITY_VALUE_ID="333b3c1d"- elif [[ $ITEM_PRIORITY == "high" ]]; then- PRIORITY_VALUE_ID="03fe8945"- else- PRIORITY_VALUE_ID="fb76bdbc"- fi- echo 'PRIORITY_VALUE_ID='"$PRIORITY_VALUE_ID" >> "$GITHUB_ENV"-- - name: Set issue priority- run: |- # shellcheck disable=SC2016- gh api graphql -f query='- mutation (- $project: ID!- $item: ID!- $priority_field: ID!- $priority_value: String!- ) {- set_priority_field: updateProjectV2ItemFieldValue(input: {- projectId: $project- itemId: $item- fieldId: $priority_field- value: {- singleSelectOptionId: $priority_value- }- }) {- projectV2Item {- id- }- }- }' -f project="$PROJECT_ID" -f item="$ITEM_ID" -f priority_field="$PRIORITY_FIELD_ID" -f priority_value="$PRIORITY_VALUE_ID"+ - uses: bulatt3/[email protected]+ with:+ project-url: https://github.com/orgs/WordPress/projects/75+ github-token: ${{ secrets.ACCESS_TOKEN }}+ # Exclude the issues with the following labels+ labeled: project+ label-operator: NOT+ label-map: |+ { "Priority": [+ { "label": "π₯ priority: critical", "fieldValue": "π₯ priority: critical" },+ { "label": "π§ priority: high", "fieldValue": "π§ priority: high" },+ { "label": "π¨ priority: medium", "fieldValue": "π¨ priority: medium" },+ { "label": "π© priority: low", "fieldValue": "π© priority: low" }+ ]}diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 50ce409ed..353890671 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -6,7 +6,7 @@ exclude: Pipfile\.lock|migrations|\.idea|node_modules|archive|retiredrepos:- repo: https://github.com/pre-commit/pre-commit-hooks- rev: v4.0.1+ rev: v4.4.0hooks:- id: trailing-whitespaceargs: [--markdown-linebreak-ext=md]@@ -40,26 +40,26 @@ repos:- --lines-after-imports=2- repo: https://github.com/asottile/pyupgrade- rev: v3.2.2+ rev: v3.3.1hooks:- id: pyupgradeargs:- --py310-plus- repo: https://github.com/charliermarsh/ruff-pre-commit- rev: "v0.0.257"+ rev: "v0.0.261"hooks:- id: ruff- repo: https://github.com/ambv/black- rev: 22.3.0+ rev: 23.3.0hooks:- id: blackargs:- --safe- repo: https://github.com/pycqa/pydocstyle- rev: 6.2.2 # 6.2.3 is slightly broken+ rev: 6.3.0hooks:- id: pydocstyleargs:@@ -83,11 +83,11 @@ repos:- repo: https://github.com/koalaman/shellcheck-precommit- rev: v0.8.0+ rev: v0.9.0hooks:- id: shellcheck- repo: https://github.com/rhysd/actionlint- rev: main+ rev: v1.6.24hooks:- id: actionlint-dockerdiff --git a/docker/airflow/entrypoint.sh b/docker/airflow/entrypoint.shindex 2e66cb8dc..128ba3afc 100755--- a/docker/airflow/entrypoint.sh+++ b/docker/airflow/entrypoint.sh@@ -29,9 +29,9 @@ ENDfunction header() {size=${COLUMNS:-80}# Print centered text between two dividers of length $size- printf '#%.0s' $(seq 1 $size) && echo+ printf '#%.0s' $(seq 1 "$size") && echoprintf "%*s\n" $(( (${#1} + size) / 2)) "$1"- printf '#%.0s' $(seq 1 $size) && echo+ printf '#%.0s' $(seq 1 "$size") && echo}if [ "$1" == help ] || [ "$1" == --help ]; then help_text && exit 0; fidiff --git a/openverse_catalog/dags/common/popularity/sql.py b/openverse_catalog/dags/common/popularity/sql.pyindex d5c5f53a7..702284d34 100644--- a/openverse_catalog/dags/common/popularity/sql.py+++ b/openverse_catalog/dags/common/popularity/sql.py@@ -73,7 +73,6 @@ def drop_media_popularity_relations(metrics=IMAGE_POPULARITY_METRICS_TABLE_NAME,pg_timeout: float = timedelta(minutes=10).total_seconds(),):-if media_type == AUDIO:db_view = AUDIO_VIEW_NAMEconstants = AUDIO_POPULARITY_CONSTANTS_VIEWdiff --git a/openverse_catalog/dags/common/slack.py b/openverse_catalog/dags/common/slack.pyindex df41619a0..3c872bf68 100644--- a/openverse_catalog/dags/common/slack.py+++ b/openverse_catalog/dags/common/slack.py@@ -96,7 +96,6 @@ class SlackMessage:unfurl_media: bool = True,http_conn_id: str = SLACK_NOTIFICATIONS_CONN_ID,):-self.http = HttpHook(method="POST", http_conn_id=http_conn_id)self.blocks = []self._context = {}diff --git a/openverse_catalog/dags/maintenance/check_silenced_dags.py b/openverse_catalog/dags/maintenance/check_silenced_dags.pyindex 868e0b323..3192972b7 100644--- a/openverse_catalog/dags/maintenance/check_silenced_dags.py+++ b/openverse_catalog/dags/maintenance/check_silenced_dags.py@@ -96,7 +96,7 @@ def check_configuration(github_pat: str, airflow_variable: str):" a new issue.")- for (dag, issue, predicate, task_id_pattern) in dags_to_reenable:+ for dag, issue, predicate, task_id_pattern in dags_to_reenable:dag_name = f"{dag} ({task_id_pattern})" if task_id_pattern else dagmessage += f"\n - <{issue}|{dag_name}: '{predicate}'>"diff --git a/openverse_catalog/dags/maintenance/flickr_audit_sub_provider_workflow.py b/openverse_catalog/dags/maintenance/flickr_audit_sub_provider_workflow.pyindex 81250f4ab..571831a68 100644--- a/openverse_catalog/dags/maintenance/flickr_audit_sub_provider_workflow.py+++ b/openverse_catalog/dags/maintenance/flickr_audit_sub_provider_workflow.py@@ -43,7 +43,6 @@ class SuggestedSubProvider(NamedTuple):class FlickrSubProviderAuditor:-endpoint = "https://www.flickr.com/services/rest"retries = 2@@ -162,7 +161,7 @@ def audit_flickr_sub_providers():raise AirflowSkipException("No new potential sub-providers were identified.")message = "Consider adding the following sub-providers for Flickr:"- for (name, nsid, cc_count) in potential_sub_providers:+ for name, nsid, cc_count in potential_sub_providers:message += "\n"message += f"{name}: {nsid} _({cc_count} cc-licensed images)_"diff --git a/openverse_catalog/dags/providers/provider_api_scripts/inaturalist.py b/openverse_catalog/dags/providers/provider_api_scripts/inaturalist.pyindex fa889857b..d321ac471 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/inaturalist.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/inaturalist.py@@ -53,7 +53,6 @@ OUTPUT_DIR = Path(os.getenv("OUTPUT_DIR", "/tmp/"))class INaturalistDataIngester(ProviderDataIngester):-providers = {"image": provider_details.INATURALIST_DEFAULT_PROVIDER}def get_next_query_params(self, prev_query_params=None, **kwargs):@@ -293,9 +292,7 @@ class INaturalistDataIngester(ProviderDataIngester):@staticmethoddef create_preingestion_tasks():-with TaskGroup(group_id="preingestion_tasks") as preingestion_tasks:-check_for_file_updates = PythonOperator(task_id="check_for_file_updates",python_callable=INaturalistDataIngester.compare_update_dates,@@ -365,9 +362,7 @@ class INaturalistDataIngester(ProviderDataIngester):@staticmethoddef create_ingestion_workflow():-with TaskGroup(group_id="ingest_data") as ingest_data:-preingestion_tasks = INaturalistDataIngester.create_preingestion_tasks()with TaskGroup(group_id="pull_image_data") as pull_data:@@ -380,7 +375,6 @@ class INaturalistDataIngester(ProviderDataIngester):),with TaskGroup(group_id="load_image_data") as loader_tasks:-# Using the existing set up, but the indexes on the temporary table# probably slows down the load a bit.create_loading_table = PythonOperator(diff --git a/openverse_catalog/dags/providers/provider_api_scripts/smithsonian.py b/openverse_catalog/dags/providers/provider_api_scripts/smithsonian.pyindex 04d619835..62aeff083 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/smithsonian.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/smithsonian.py@@ -150,7 +150,6 @@ class SmithsonianDataIngester(ProviderDataIngester):# Parse out the necessary info from the record data into a dictionary.images = []if image_list := self._get_image_list(data):-if (foreign_landing_url := self._get_foreign_landing_url(data)) is None:return Nonediff --git a/openverse_catalog/dags/providers/provider_api_scripts/time_delineated_provider_data_ingester.py b/openverse_catalog/dags/providers/provider_api_scripts/time_delineated_provider_data_ingester.pyindex 6f379e624..d13d89ba5 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/time_delineated_provider_data_ingester.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/time_delineated_provider_data_ingester.py@@ -159,7 +159,7 @@ class TimeDelineatedProviderDataIngester(ProviderDataIngester):# portions.hour_slices = self._get_timestamp_query_params_list(start_ts, end_ts, 24)- for (start_hour, end_hour) in hour_slices:+ for start_hour, end_hour in hour_slices:# Get the number of records in this hour intervalrecord_count = self._get_record_count(start_hour, end_hour, **kwargs)if record_count == 0:diff --git a/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py b/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.pyindex 79716be81..0a95d85e3 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py@@ -564,7 +564,7 @@ class WikimediaCommonsDataIngester(ProviderDataIngester):"map_datum": "GPSMapDatum",}geo_data = {}- for (key, value) in geo_properties.items():+ for key, value in geo_properties.items():key_value = media_data.get(value, {}).get("value")if key_value:geo_data[key] = key_valuediff --git a/tests/dags/common/popularity/test_sql.py b/tests/dags/common/popularity/test_sql.pyindex 41ca0fca2..99d9d9366 100644--- a/tests/dags/common/popularity/test_sql.py+++ b/tests/dags/common/popularity/test_sql.py@@ -345,7 +345,7 @@ def test_constants_view_adds_values_and_constants(("my_provider", "views", 0.5, 50.0, 50.0, 50.0),]sorted_rows = sorted(list(postgres_with_image_table.cursor), key=lambda x: x[0])- for (expect_row, sorted_row) in zip(expect_rows, sorted_rows):+ for expect_row, sorted_row in zip(expect_rows, sorted_rows):assert expect_row == pytest.approx(sorted_row)@@ -401,7 +401,7 @@ def test_constants_view_handles_zeros_and_missing(("my_provider", "views", 0.8, 0.0, 1.0, 0.25),]sorted_rows = sorted(list(postgres_with_image_table.cursor), key=lambda x: x[0])- for (expect_row, sorted_row) in zip(expect_rows, sorted_rows):+ for expect_row, sorted_row in zip(expect_rows, sorted_rows):assert expect_row == pytest.approx(sorted_row)diff --git a/tests/dags/providers/provider_api_scripts/resources/inaturalist/pull_sample_records.py b/tests/dags/providers/provider_api_scripts/resources/inaturalist/pull_sample_records.pyindex 5117b73d5..ac58de781 100644--- a/tests/dags/providers/provider_api_scripts/resources/inaturalist/pull_sample_records.py+++ b/tests/dags/providers/provider_api_scripts/resources/inaturalist/pull_sample_records.py@@ -96,7 +96,6 @@ def get_sample_id_list(sample_file, joined_on):if __name__ == "__main__":-# PHOTOSphoto_ids = [str(i)diff --git a/tests/dags/providers/provider_api_scripts/test_provider_data_ingester.py b/tests/dags/providers/provider_api_scripts/test_provider_data_ingester.pyindex 553227b6b..bcb333fbc 100644--- a/tests/dags/providers/provider_api_scripts/test_provider_data_ingester.py+++ b/tests/dags/providers/provider_api_scripts/test_provider_data_ingester.py@@ -193,7 +193,6 @@ def test_process_batch_halts_processing_after_reaching_ingestion_limit():patch.object(image_store, "add_item"),patch.object(ingester, "get_record_data") as get_record_data_mock,):-# Mock `get_record_data` to return a list of 2 recordsget_record_data_mock.return_value = MOCK_RECORD_DATA_LISTrecord_count = ingester.process_batch(EXPECTED_BATCH_DATA)diff --git a/tests/dags/providers/provider_api_scripts/test_time_delineated_provider_data_ingester.py b/tests/dags/providers/provider_api_scripts/test_time_delineated_provider_data_ingester.pyindex b2de058fb..cc7eab206 100644--- a/tests/dags/providers/provider_api_scripts/test_time_delineated_provider_data_ingester.py+++ b/tests/dags/providers/provider_api_scripts/test_time_delineated_provider_data_ingester.py@@ -237,7 +237,7 @@ def test_ingest_records_raises_error_if_the_total_count_has_been_exceeded():)# Assert that attempting to ingest records raises an exception when# `should_raise_error` is enabled- with (pytest.raises(Exception, match=expected_error_string)):+ with pytest.raises(Exception, match=expected_error_string):ingester.ingest_records()# get_mock should have been called 4 times, twice for each batch (once in `get_batch`