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

Pip package for tutorial-vm #5

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0da3bb2
make pip package
eberrigan Nov 5, 2024
21128ca
Rename project urls
roomrys Nov 5, 2024
d6cef2f
Add more keywords
roomrys Nov 5, 2024
1bb89b0
Add pytest and black to dev extras
roomrys Nov 5, 2024
343a8ad
Specifiy location of source code
roomrys Nov 5, 2024
98e15fd
Test the imports
roomrys Nov 5, 2024
68d1f8d
Lint
roomrys Nov 5, 2024
ad291d8
Reorganize pyproject
roomrys Nov 5, 2024
9f36b5f
Remove unneccessary requirements
roomrys Nov 5, 2024
8aa7ca8
Merge branch 'main' of https://github.com/talmolab/cosyne_vm into eli…
roomrys Nov 5, 2024
9063357
Install dev extras via environment.yml
roomrys Nov 5, 2024
407fd17
make imports backwards compatible
eberrigan Nov 6, 2024
2a6b079
add ci for pip package tests but not upload
eberrigan Nov 6, 2024
3ddd310
update andrews email
eberrigan Nov 6, 2024
56fb3fe
ci was in wrong folder
eberrigan Nov 6, 2024
95db597
import from tutorial_vm again
eberrigan Nov 6, 2024
0737499
add setup for google cloud credentials to ci
eberrigan Nov 6, 2024
cd85066
fix indentation
eberrigan Nov 6, 2024
57282bc
add manual publish action
eberrigan Nov 6, 2024
b3caf03
rename package to lablink-client
eberrigan Nov 8, 2024
0e9da40
rename package directory to lablink_client
eberrigan Nov 8, 2024
97937a5
rename package directory to lablink_client
eberrigan Nov 8, 2024
311c63a
pip package source code is now in lablink_client folder
eberrigan Nov 14, 2024
a990f77
use workload identity provider instead of service account
eberrigan Nov 19, 2024
9e8fa84
authenticate using auth
eberrigan Nov 19, 2024
596b681
add quotes
eberrigan Nov 19, 2024
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
57 changes: 57 additions & 0 deletions .github/workflows/build-and-publish-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and Publish Manual

on:
workflow_dispatch:

Choose a reason for hiding this comment

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

possibly have input of archive from build and test stage

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/*
48 changes: 48 additions & 0 deletions .github/workflows/build-and-test-pip.yml
Original file line number Diff line number Diff line change
@@ -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/*

Choose a reason for hiding this comment

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

upload archive to access later

- name: Install package
run: |
pip install dist/*.whl

- name: Run tests
run: |
pytest tests/
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dependencies:
- python>=3.7
- pip
- pip:
- -e .
- -e .[dev]
File renamed without changes.
2 changes: 1 addition & 1 deletion crd_connect.py → lablink_client/crd_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import random
import subprocess

from logging_utils import CloudAndConsoleLogger
from lablink_client.logging_utils import CloudAndConsoleLogger


# Set up logging
Expand Down
2 changes: 1 addition & 1 deletion database.py → lablink_client/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[project]
name = "lablink-client"
version = "0.0.1a0"
authors = [
{ name = "Liezl Maree", email = "[email protected]" },
{ name = "Andrew Park", email = "[email protected]" },
{ name = "Elizabeth Berrigan", email = "[email protected]" },
]
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 = ["."]
16 changes: 0 additions & 16 deletions requirements.txt

This file was deleted.

23 changes: 23 additions & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -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()
Loading