Skip to content

Pip package for lablink-client #5

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 37 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
2880ab8
remove authentication step
eberrigan Jan 28, 2025
71c456f
initialize logging with None
eberrigan Jan 28, 2025
0c22881
add multiple jobs
eberrigan Feb 14, 2025
44e0e23
remove authentication
eberrigan Feb 14, 2025
ce9a6d3
add separate job for tests
eberrigan Feb 14, 2025
8c26809
update env
eberrigan Feb 14, 2025
7e767ea
list files
eberrigan Feb 14, 2025
98fc5de
fix dev dependencies
eberrigan Feb 14, 2025
edaaee9
make publish pip workflow
eberrigan Feb 14, 2025
b8005b7
change where to find package
eberrigan Feb 18, 2025
bb9210d
remove pythonpath manipulation
eberrigan Feb 19, 2025
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
77 changes: 77 additions & 0 deletions .github/workflows/build-and-test-pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build and Test

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build lablink-client
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- 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: Upload artifact
uses: actions/upload-artifact@v4
with:
name: lablink-client-dist
path: dist/
retention-days: 1

tests:
name: Test lablink-client
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4
Comment on lines +47 to +49
Copy link
Contributor

Choose a reason for hiding this comment

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

So we do need the tests folder, but having all the code checked-out can lead to false positive import tests (see b8005). Maybe there is a way to just move the tests folder and change that to our working directory?


- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: lablink-client-dist
path: dist/

- name: List files
run: |
ls dist/

- name: Install package from artifact
run: |
WHL=$(ls dist/*.whl)
pip install "$WHL[dev]"

- name: Print installed packages
run: |
pip list

- name: Run tests
run: |
pytest tests/
36 changes: 36 additions & 0 deletions .github/workflows/publish-pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish on Release
# This workflow will only work if an artifact named "lablink-client-dist" is uploaded to the repository
# Run this workflow after testing using the "build-and-test-pip.yml" workflow
on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Download Package Artifact
uses: actions/download-artifact@v3
with:
name: lablink-client-dist # Name of the artifact to download
path: package/ # Download the artifact to this path

- name: Verify Artifact Contents
run: |
ls package/

- name: Publish package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TUTORIAL_PYPI_API_TOKEN }}
run: |
twine upload package/*
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: vm
name: lablink-client

channels:
- conda-forge
Expand All @@ -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
18 changes: 14 additions & 4 deletions logging_utils.py → lablink_client/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ def __init__(self, module_name: str, level=logging.DEBUG, format=None):
self.name = module_name

format = format or "%(module)s[%(levelname)s]: %(message)s"
formatter = logging.Formatter(format, datefmt="%H:%M:%S")
self.formatter = logging.Formatter(format, datefmt="%H:%M:%S")
self.level = level
self.console_logger = self.setup_console_logging(
level=level, formatter=formatter
)
self.cloud_logger = self.setup_cloud_logging(level=level, formatter=formatter)
level=self.level, formatter=self.formatter
)
self._cloud_logger = None


@property
def cloud_logger(self):
if self._cloud_logger is None:
self._cloud_logger = self.setup_cloud_logging(
level=self.level, formatter=self.formatter
)
return self._cloud_logger

def __getattr__(self, name):
"""Pass the log call to both the console and cloud loggers."""
Expand Down
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
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[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 = ["."]
include = ["lablink_client*"]

[tool.pytest.ini_options]
pythonpath = ["."]
16 changes: 0 additions & 16 deletions requirements.txt

This file was deleted.

11 changes: 11 additions & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""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