-
Notifications
You must be signed in to change notification settings - Fork 2
Add version information to data locations #105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
684f860
Add version information to data locations
nikhilwoodruff 664cc93
Set metadata in versioning
nikhilwoodruff b0481c6
Address comments
nikhilwoodruff c620229
Refactor to split up HF and GCS
nikhilwoodruff 4d218aa
Only publish after tests run
nikhilwoodruff 2652888
Remove redundant make step
nikhilwoodruff 062cbab
Fix typo in HF repo name
nikhilwoodruff c329895
Fix typos in names
nikhilwoodruff d5da660
Catch super tiny bug
nikhilwoodruff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Versioning | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| check-changelog-entry: | ||
| name: Changelog entry check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Check for changelog entry | ||
| run: | | ||
| if [ ! -f "changelog_entry.yaml" ]; then | ||
| echo "Error: changelog_entry.yaml file is missing." | ||
| echo "Please add a changelog_entry.yaml file at the root of the repository." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if the file is empty | ||
| if [ ! -s "changelog_entry.yaml" ]; then | ||
| echo "Error: changelog_entry.yaml file is empty." | ||
| echo "Please add content to the changelog_entry.yaml file." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Changelog entry found and is not empty." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Workflow that runs on versioning metadata updates. | ||
|
|
||
| name: Versioning updates | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| paths: | ||
| - changelog_entry.yaml | ||
| - "!pyproject.toml" | ||
|
nikhilwoodruff marked this conversation as resolved.
|
||
|
|
||
| jobs: | ||
| Versioning: | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| (!(github.event.head_commit.message == 'Update package version')) | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
| ref: ${{ github.event.pull_request.head.ref }} | ||
| token: ${{ secrets.POLICYENGINE_GITHUB }} | ||
|
nikhilwoodruff marked this conversation as resolved.
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.12 | ||
| - name: Build changelog | ||
| run: pip install yaml-changelog && make changelog | ||
| - name: Preview changelog update | ||
| run: ".github/get-changelog-diff.sh" | ||
| - name: Update changelog | ||
| uses: EndBug/add-and-commit@v9 | ||
| with: | ||
| add: "." | ||
| message: Update package version | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 14 additions & 54 deletions
68
policyengine_uk_data/storage/upload_completed_datasets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| from typing import List | ||
| from huggingface_hub import HfApi, CommitOperationAdd | ||
| from huggingface_hub.errors import RevisionNotFoundError | ||
| from google.cloud import storage | ||
| from pathlib import Path | ||
| from importlib import metadata | ||
| import google.auth | ||
| import logging | ||
|
|
||
|
|
||
| def upload_data_files( | ||
| files: List[str], | ||
| gcs_bucket_name: str = "policyengine-uk-data-private", | ||
| hf_repo_name: str = "policyengine/policyengine-uk-data", | ||
| hf_repo_type: str = "model", | ||
| version: str = None, | ||
| ): | ||
| if version is None: | ||
| version = metadata.version("policyengine-uk-data") | ||
|
nikhilwoodruff marked this conversation as resolved.
|
||
|
|
||
| upload_files_to_hf( | ||
| files=files, | ||
| version=version, | ||
| hf_repo_name=hf_repo_name, | ||
| hf_repo_type=hf_repo_type, | ||
| ) | ||
|
|
||
| upload_files_to_gcs( | ||
| files=files, | ||
| version=version, | ||
| gcs_bucket_name=gcs_bucket_name, | ||
| ) | ||
|
|
||
|
|
||
| def upload_files_to_hf( | ||
| files: List[str], | ||
| version: str, | ||
| hf_repo_name: str = "policyengine/policyengine-uk-data-private", | ||
| hf_repo_type: str = "model", | ||
| ): | ||
| """ | ||
| Upload files to Hugging Face repository and tag the commit with the version. | ||
| """ | ||
| api = HfApi() | ||
| hf_operations = [] | ||
|
|
||
| for file_path in files: | ||
| file_path = Path(file_path) | ||
| if not file_path.exists(): | ||
| raise ValueError(f"File {file_path} does not exist.") | ||
| hf_operations.append( | ||
| CommitOperationAdd( | ||
| path_in_repo=file_path.name, | ||
| path_or_fileobj=str(file_path), | ||
| ) | ||
| ) | ||
| commit_info = api.create_commit( | ||
|
nikhilwoodruff marked this conversation as resolved.
|
||
| repo_id=hf_repo_name, | ||
| operations=hf_operations, | ||
| repo_type=hf_repo_type, | ||
| commit_message=f"Upload data files for version {version}", | ||
| ) | ||
| logging.info(f"Uploaded files to Hugging Face repository {hf_repo_name}.") | ||
|
|
||
| # Tag commit with version | ||
| api.create_tag( | ||
| repo_id=hf_repo_name, | ||
| tag=version, | ||
| revision=commit_info.oid, | ||
| repo_type=hf_repo_type, | ||
| ) | ||
| logging.info( | ||
| f"Tagged commit with {version} in Hugging Face repository {hf_repo_name}." | ||
| ) | ||
|
|
||
|
|
||
| def upload_files_to_gcs( | ||
| files: List[str], | ||
| version: str, | ||
| gcs_bucket_name: str = "policyengine-uk-data-private", | ||
| ): | ||
| """ | ||
| Upload files to Google Cloud Storage and set metadata with the version. | ||
| """ | ||
| credentials, project_id = google.auth.default() | ||
| storage_client = storage.Client( | ||
| credentials=credentials, project=project_id | ||
| ) | ||
| bucket = storage_client.bucket(gcs_bucket_name) | ||
|
|
||
| for file_path in files: | ||
| file_path = Path(file_path) | ||
| blob = bucket.blob(file_path.name) | ||
| blob.upload_from_filename(file_path) | ||
| logging.info( | ||
| f"Uploaded {file_path.name} to GCS bucket {gcs_bucket_name}." | ||
| ) | ||
|
|
||
| # Set metadata | ||
| blob.metadata = {"version": version} | ||
| blob.patch() | ||
| logging.info( | ||
| f"Set metadata for {file_path.name} in GCS bucket {gcs_bucket_name}." | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.