Skip to content

Commit

Permalink
feat: update workflows, config, and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andy blair committed Oct 16, 2024
1 parent f339560 commit 32ff7a4
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 197 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
name: Test nyx_client and nyx_extras

on:
push:
branches: [main]
pull_request:

jobs:
test:
strategy:
matrix:
project: [nyx_client, nyx_extras]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ matrix.project }}
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.10.14

- uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

- run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
- name: Install dependencies for nyx_client
if: matrix.project == 'nyx_client'
run: poetry install --with dev --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0
- name: Install dependencies for nyx_extras
if: matrix.project == 'nyx_extras'
run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0

- run: make lint

- run: make tests
51 changes: 32 additions & 19 deletions .github/workflows/publish-testpypi.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
name: Verify and Upload nyx_client and nyx_extras to TEST PyPI

on:
workflow_dispatch:

name: Verify and Upload nyx_client and nyx_extras

on:
workflow_dispatch:

jobs:
verify_and_upload:
strategy:
matrix:
project: [nyx_client, nyx_extras]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ matrix.project }}
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.10.14

- uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

- run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
- name: Install dependencies for nyx_client
if: matrix.project == 'nyx_client'
run: poetry install --with dev --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0
- name: Install dependencies for nyx_extras
if: matrix.project == 'nyx_extras'
run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0

- run: make lint

- run: make tests

- run: make build

- run: |
pip install dist/nyx_client*.whl
python -c "from nyx_client import NyxClient, Data"
pip uninstall -y nyx_client
- run: |
pip install dist/nyx_client*.tar.gz
python -c "from nyx_client import NyxClient, Data"
pip uninstall -y nyx_client
- name: Verify wheel installation
run: |
pip install dist/${{ matrix.project }}*.whl
python -c "from ${{ matrix.project }} import *"
pip uninstall -y ${{ matrix.project }}
- name: Verify tar.gz installation
run: |
pip install dist/${{ matrix.project }}*.tar.gz
python -c "from ${{ matrix.project }} import *"
pip uninstall -y ${{ matrix.project }}
- name: Publish package to TestPyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_PASSWORD2024 }}
packages-dir: ./dist/
packages-dir: ${{ matrix.project }}/dist/
verify-metadata: true
repository-url: https://test.pypi.org/legacy/
verbose: true
Expand Down
56 changes: 36 additions & 20 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
name: Verify and Upload nyx_client and nyx_extras to PyPI

on:
workflow_dispatch:

jobs:
verify_and_upload:
strategy:
matrix:
project: [nyx_client, nyx_extras]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ matrix.project }}
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.10.14

- uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

- run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
- name: Install dependencies for nyx_client
if: matrix.project == 'nyx_client'
run: poetry install --with dev --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0
- name: Install dependencies for nyx_extras
if: matrix.project == 'nyx_extras'
run: poetry install --with dev --extras "langchain-openai langchain-cohere" --no-interaction
env:
POETRY_INSTALLER_PARALLEL: 0

- run: make lint

- run: make tests

- run: make build

- run: |
pip install dist/nyx_client*.whl
python -c "from nyx_client import NyxClient, Data"
pip uninstall -y nyx_client
- run: |
pip install dist/nyx_client*.tar.gz
python -c "from nyx_client import NyxClient, Data"
pip uninstall -y nyx_client
- name: Publish package to PyPi
- name: Verify wheel installation
run: |
pip install dist/${{ matrix.project }}*.whl
if [ "${{ matrix.project }}" = "nyx_client" ]; then
python -c "from nyx_client import NyxClient, Data"
else
python -c "from nyx_extras import *"
fi
pip uninstall -y ${{ matrix.project }}
- name: Verify tar.gz installation
run: |
pip install dist/${{ matrix.project }}*.tar.gz
if [ "${{ matrix.project }}" = "nyx_client" ]; then
python -c "from nyx_client import NyxClient, Data"
else
python -c "from nyx_extras import *"
fi
pip uninstall -y ${{ matrix.project }}
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD2024 }}
packages-dir: ./dist/
packages-dir: ${{ matrix.project }}/dist/
verify-metadata: true
verbose: true
skip-existing: false
3 changes: 2 additions & 1 deletion nyx_client/nyx_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _nyx_delete(self, endpoint: str, params: dict | None = None):
headers["authorization"] = "Bearer " + self._token
resp = requests.delete(url=self.config.nyx_url + NYX_API_BASE_URL + endpoint, headers=headers, params=params)
resp.raise_for_status()
return resp.json()
return

@ensure_setup
@auth_retry
Expand Down Expand Up @@ -457,6 +457,7 @@ def get_data(
url=resp["accessURL"],
content_type=resp["contentType"],
creator=resp["creator"],
size=resp["size"],
org=self.org,
categories=resp["categories"],
genre=resp["genre"],
Expand Down
22 changes: 5 additions & 17 deletions nyx_client/nyx_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,21 @@
from dotenv import dotenv_values


@dataclass
@dataclass(frozen=True)
class BaseNyxConfig:
"""Configuration for the Nyx client.
Attributes:
host_config: Configuration for the host client.
nyx_url: The URL of the Nyx instance.
nyx_username: The username of the Nyx user.
nyx_email: The email of the Nyx user.
nyx_password: The password of the Nyx user.
org: The organisation name.
community_mode: Whether the host is in community mode.
"""

def __init__(self, url: str, email: str, password: str, override_token: str | None = None):
"""Instantiate a new nyx base configuration.
Args:
url: The URL of the Nyx instance.
email: The email of the Nyx user.
password: The password of the Nyx user.
override_token: Token to override the default authentication.
"""
self.nyx_url = url
self.nyx_email = email
self.nyx_password = password
self.override_token = override_token
nyx_url: str
nyx_password: str
nyx_email: str
override_token: str | None

@classmethod
def from_env(
Expand Down
2 changes: 1 addition & 1 deletion nyx_client/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nyx-client"
version = "0.1.4"
version = "0.2.0"
description = "Nyx Client SDK provides a powerful toolkit for building generative AI applications using data brokered on the Nyx platform."
authors = [
"Iotics <info@iotics.com>",
Expand Down
23 changes: 12 additions & 11 deletions nyx_client/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def mock_dotenv_values():

@pytest.fixture
def mock_config():
config = BaseNyxConfig(env_file=None, override_token="test_token", validate=False)
config.org = "test"
config = BaseNyxConfig.from_env(env_file=None, override_token="test_token")
yield config


@pytest.fixture
def nyx_client(mock_config):
with patch("nyx_client.client.NyxClient._setup"):
client = NyxClient(config=mock_config)
client.org = "test"
yield client


Expand Down Expand Up @@ -78,6 +78,8 @@ def test_delete_data(requests_mock, nyx_client):
description="",
content_type="application/poney",
creator="me",
categories=["ai"],
genre="ai",
)
nyx_client.delete_data(data)
assert requests_mock.call_count == 1
Expand Down Expand Up @@ -105,8 +107,8 @@ def test_authorise_invalid_credentials(nyx_client):


def test_get_all_categories_empty_result(nyx_client):
with patch.object(nyx_client, "_federated_sparql_query", return_value=[]):
result = nyx_client.get_all_categories()
with patch.object(nyx_client, "_nyx_get", return_value=[]):
result = nyx_client.categories()
assert result == []


Expand Down Expand Up @@ -173,15 +175,13 @@ def test_delete_data_not_found(requests_mock, nyx_client):
description="",
content_type="application/poney",
creator="me",
categories=["ai"],
genre="ai",
)
with pytest.raises(requests.HTTPError):
nyx_client.delete_data(data)


def test_get_subscribed_datasets_no_subscriptions(nyx_client):
assert nyx_client.get_data() == []


def test_sparql_query_constructs_data(nyx_client):
# Mock response from _sparql_query
mock_response = [
Expand All @@ -191,11 +191,12 @@ def test_sparql_query_constructs_data(nyx_client):
"name": "test_data",
"contentType": "application/json",
"creator": "TestCreator",
"size": "321",
"size": 321,
"description": "Some description of sorts",
"categories": ["ai"],
"genre": "ai",
}
]
nyx_client._subscribed_data = ["test_data"]

# Patch the _sparql_query method to return our mock response
with patch.object(nyx_client, "_nyx_get", return_value=mock_response):
Expand All @@ -207,7 +208,7 @@ def test_sparql_query_constructs_data(nyx_client):
assert len(data) == 1

# Assert that the Data has the correct attributes
assert data[0].url == f"https://example.com/access?buyer_org={nyx_client.config.org}"
assert data[0].url == f"https://example.com/access?buyer_org={nyx_client.org}"
assert data[0].title == "Test Data"
assert data[0].name == "test_data"
assert data[0].content_type == "application/json"
Expand Down
Loading

0 comments on commit 32ff7a4

Please sign in to comment.