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

Code migration from gemini #10

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,29 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload '${{ github.ref_name }}' dist/** --repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/${{ matrix.package }}

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ def upload_file(self, file_path: bytes, bucket_name: str, destination: str, con
blob.upload_from_filename(file_path, content_type=content_type, timeout=self.timeout)
self.logger.info(f"File uploaded to {destination}.")
return f"gs://{bucket_name}/{destination}"

def list_files_with_prefix(self, bucket_name: str, prefix: str):
mab-happtiq marked this conversation as resolved.
Show resolved Hide resolved
self.logger.info(f"Listing files in bucket {bucket_name} with prefix {prefix}")
bucket = self.client.bucket(bucket_name)
blobs = bucket.list_blobs(prefix=prefix)

file_list = [blob.name for blob in blobs]
self.logger.debug(f"Files in bucket {bucket_name} with prefix {prefix}: {file_list}")
self.logger.info(f"found {len(file_list)} files in bucket {bucket_name} with prefix {prefix}")

return file_list
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,25 @@ def test_upload_file_gzipped(gcs_api_service, monkeypatch):
gcs_api_service.client.bucket().blob.assert_called_once_with(destination)
gcs_api_service.client.bucket().blob(destination).upload_from_filename.assert_called_once_with(file_path, content_type=content_type, timeout=30)
gcs_api_service.client.bucket().blob(destination).content_encoding = "gzip"

def test_list_files_with_prefix(gcs_api_service, monkeypatch):
mock_client = MagicMock()
mock_bucket = MagicMock()
mock_blob1 = MagicMock()
mock_blob1.name = "file1.txt"
mock_blob2 = MagicMock()
mock_blob2.name = "file2.txt"
mock_blobs = [mock_blob1,mock_blob2]

mock_client.bucket.return_value = mock_bucket
mock_bucket.list_blobs.return_value = mock_blobs
monkeypatch.setattr(gcs_api_service, "client", mock_client)

bucket_name = "test-bucket"
prefix = "test-prefix/"

result = gcs_api_service.list_files_with_prefix(bucket_name, prefix)

assert result == ["file1.txt", "file2.txt"]
mock_client.bucket.assert_called_once_with(bucket_name)
mock_bucket.list_blobs.assert_called_once_with(prefix=prefix)
Loading