diff --git a/.github/workflows/build-and-publish-manual.yml b/.github/workflows/build-and-publish-manual.yml new file mode 100644 index 0000000..a8eefef --- /dev/null +++ b/.github/workflows/build-and-publish-manual.yml @@ -0,0 +1,57 @@ +name: Build and Publish Manual + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Google Cloud credentials + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ runner.temp }}/gcloud-key.json + run: | + echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > $GOOGLE_APPLICATION_CREDENTIALS + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + + - name: Get version from pyproject.toml + id: get_version + run: | + VERSION=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml) + echo "version=$VERSION" >> $GITHUB_ENV + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --editable .[dev] + + - name: Build package + run: | + python -m build + twine check dist/* + + - name: Install package + run: | + pip install dist/*.whl + + - name: Run tests + run: | + pytest tests/ + + - name: Clean up credentials + run: rm -f $GOOGLE_APPLICATION_CREDENTIALS + + - name: Publish package + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TUTORIAL_PYPI_API_TOKEN }} + run: | + twine upload dist/* diff --git a/.github/workflows/build-and-test-pip.yml b/.github/workflows/build-and-test-pip.yml new file mode 100644 index 0000000..728e36f --- /dev/null +++ b/.github/workflows/build-and-test-pip.yml @@ -0,0 +1,48 @@ +name: Build and Test + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + id-token: write + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Authenticate to Google Cloud + id: auth + uses: google-github-actions/auth@v1 + with: + create_credentials_file: true + workload_identity_provider: 'projects/${{ secrets.GCP_PROJECT_ID }}/locations/global/workloadIdentityPools/${{ secrets.GCP_POOL_ID }}/providers/${{ secrets.GCP_PROVIDER_ID }}' + service_account: '${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }}' + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --editable .[dev] + + - name: Build package + run: | + python -m build + twine check dist/* + + - name: Install package + run: | + pip install dist/*.whl + + - name: Run tests + run: | + pytest tests/ diff --git a/environment.yml b/environment.yml index c477a92..65861f8 100644 --- a/environment.yml +++ b/environment.yml @@ -7,4 +7,4 @@ dependencies: - python>=3.7 - pip - pip: - - -e . + - -e .[dev] diff --git a/__init__.py b/lablink_client/__init__.py similarity index 100% rename from __init__.py rename to lablink_client/__init__.py diff --git a/crd_connect.py b/lablink_client/crd_connect.py similarity index 98% rename from crd_connect.py rename to lablink_client/crd_connect.py index 6fe5d08..bd6ec3c 100644 --- a/crd_connect.py +++ b/lablink_client/crd_connect.py @@ -12,7 +12,7 @@ import random import subprocess -from logging_utils import CloudAndConsoleLogger +from lablink_client.logging_utils import CloudAndConsoleLogger # Set up logging diff --git a/database.py b/lablink_client/database.py similarity index 99% rename from database.py rename to lablink_client/database.py index bdd4842..69214a4 100644 --- a/database.py +++ b/lablink_client/database.py @@ -8,7 +8,7 @@ try: # This is used when running on a VM instance - from logging_utils import CloudAndConsoleLogger + from lablink_client.logging_utils import CloudAndConsoleLogger except ImportError: # This is used when running in the main application from vmassign import CloudAndConsoleLogger diff --git a/logging_utils.py b/lablink_client/logging_utils.py similarity index 100% rename from logging_utils.py rename to lablink_client/logging_utils.py diff --git a/subscribe_instance.py b/lablink_client/subscribe_instance.py similarity index 96% rename from subscribe_instance.py rename to lablink_client/subscribe_instance.py index 79c0223..524913f 100644 --- a/subscribe_instance.py +++ b/lablink_client/subscribe_instance.py @@ -9,9 +9,9 @@ from google.cloud import pubsub_v1 -from crd_connect import connect_to_crd -from database import SpannerDatabase -from logging_utils import CloudAndConsoleLogger +from lablink_client.crd_connect import connect_to_crd +from lablink_client.database import SpannerDatabase +from lablink_client.logging_utils import CloudAndConsoleLogger def create_parser(): diff --git a/update_inuse_status.py b/lablink_client/update_inuse_status.py similarity index 98% rename from update_inuse_status.py rename to lablink_client/update_inuse_status.py index 5e58f2b..89f175f 100644 --- a/update_inuse_status.py +++ b/lablink_client/update_inuse_status.py @@ -13,8 +13,8 @@ ) raise e -from database import SpannerDatabase -from logging_utils import CloudAndConsoleLogger +from lablink_client.database import SpannerDatabase +from lablink_client.logging_utils import CloudAndConsoleLogger cnc_logger = CloudAndConsoleLogger( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5d7df1f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,49 @@ +[project] +name = "lablink-client" +version = "0.0.1a0" +authors = [ + { name = "Liezl Maree", email = "lmaree@salk.edu" }, + { name = "Andrew Park", email = "hep003@ucsd.edu" }, + { name = "Elizabeth Berrigan", email = "eberrigan@salk.edu" }, +] +description = "Scripts for VM instances of tutorial platform." +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.7" +dependencies = [ + "google-cloud-logging", + "google-cloud-pubsub", + "google-cloud-spanner==3.42.0", + "psutil", +] +keywords = [ + "tutorial", + "vm", + "gcp", + "google-cloud", + "spanner", + "pubsub", + "logging", +] +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Development Status :: 3 - Alpha", +] + +[project.optional-dependencies] +dev = ["toml", "twine", "build", "pytest", "black"] + +[project.urls] +Homepage = "https://github.com/talmolab/tutorial_vm" +Issues = "https://github.com/talmolab/tutorial_vm/issues" + +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +where = ["lablink_client"] + +[tool.pytest.ini_options] +pythonpath = ["."] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index fd0dd46..0000000 --- a/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ -# These are the requirements for each VM instance - -# There may be some overlap between the requirements for vmassign.app and vmassign.vm.local -# but it is imperative that the requirements for the VM instances (here) are kept independent - -# Google Cloud SDK -google-cloud-logging -google-cloud-pubsub -google-cloud-spanner==3.42.0 - -# To find whether SLEAP process is running -psutil - -# To run SLEAP process -sleap[pypi]==1.3.4 - diff --git a/tests/test_imports.py b/tests/test_imports.py new file mode 100644 index 0000000..47dac62 --- /dev/null +++ b/tests/test_imports.py @@ -0,0 +1,23 @@ +"""Module that tests the imports of the package.""" + + +def test_import(): + import lablink_client + + from lablink_client import crd_connect + from lablink_client import database + from lablink_client import logging_utils + from lablink_client import subscribe_instance + from lablink_client import update_inuse_status + + +if __name__ == "__main__": + + # Add the parent directory to the pythonpath (pytest setup to do this automatically) + import os + import sys + + sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + + # Run the test + test_import()