diff --git a/Dockerfile b/Dockerfile index be0dd17..5d771d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,8 @@ -# Step 1: Use an official Python runtime as a parent image -FROM python:3.10-slim +FROM python:3.12-slim -# Step 2: Set the working directory in the container WORKDIR /app -# Step 3: Copy the requirements file to the container -COPY requirements.txt . - -# Step 4: Install the required Python packages -RUN pip install --no-cache-dir -r requirements.txt - -# Step 5: Copy the rest of the application code to the container COPY . . +RUN pip install -e . -# Step 6: Set the default entry point for the container -# Use the `cli.py` script as the entry point for the container ENTRYPOINT ["python", "weaviatest.py"] - -# Optionally, provide a default command to the entrypoint -# CMD ["--help"] - - diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..554b647 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +.PHONY: default env_install test build_container clean + +ENV := .venv +SYSTEM_PYTHON := python3 +PYTHON_VERSION := 3.12.5 +ENV_PYTHON := ${ENV}/bin/python3 +ENV_SITE_PACKAGES := ${ENV}/lib/python${PYTHON_VERSION}/site-packages +PROJECT_PACKAGE_NAME := eco_pytests +ENV_PROJECT_PACKAGE_PATH := ${ENV_SITE_PACKAGES}/${PROJECT_PACKAGE_NAME}-% +CONTAINER_NAME := weaviatest +VERSION ?= latest #$(shell git rev-parse --short HEAD) +PUSH_TAG ?= latest + +default: test + +${ENV_PYTHON}: + @echo "Creating Python ${PYTHON_VERSION} environment..." >&2 + @${SYSTEM_PYTHON} -m venv ${ENV} + @${ENV_PYTHON} -m pip install -U pip setuptools + +${ENV_PROJECT_PACKAGE_PATH}: ${ENV_PYTHON} + @echo "Installing Python project in ${ENV_SITE_PACKAGES}" + @${ENV_PYTHON} -m pip install . + +env_install: ${ENV_PROJECT_PACKAGE_PATH} + +test: ${ENV_PROJECT_PACKAGE_PATH} + +build_container: + docker build -t ${CONTAINER_NAME}:${VERSION} . + +clean: + @rm -rf ${ENV} \ No newline at end of file diff --git a/README.md b/README.md index 4e2e81e..e322bae 100644 --- a/README.md +++ b/README.md @@ -35,26 +35,52 @@ The Weaviatest CLI provides the following actions: You can run the Weaviatest CLI directly from the command line. -## Requirements +## Install -The Weaviatest CLI requires the following dependencies, which are listed in the `requirements.txt` file. If the required client changes are not yet published, you can use a branch from the `weaviate-python-client` repository. To do so, add the following requirement to the `requirements.txt` file: +Weaviatest can be installed as a pip package to do so, you can run the command: +``` bash +pip install -U pip setuptools +``` + +As an alternative, the pip package can be install with the flag -e to make the installation package editable +``` bash +pip install -e -U pip setuptools +``` +Finally, there is a Makefile to facilitate the creation of a python environment and install the weaviatest package: +``` bash +make env_install +source .venv/bin/activate ``` + +### Requirements + +The Weaviatest CLI requires the following dependencies, which are listed in the `setup.cfg` file. If the required client changes are not yet published, you can use a branch from the `weaviate-python-client` repository. To do so, add the following requirement to the `setup.cfg` file: + +```bash weaviate-client @ git+https://github.com/weaviate/weaviate-python-client.git@ ``` For example: -``` +```bash weaviate-client @ git+https://github.com/weaviate/weaviate-python-client.git@dev/1.26 ``` Then, run the following command to install the dependencies: +```bash +pip install -U pip setuptools ``` -pip install -r requirements.txt + +#### Dev requirements + +For development, there are extra requirements to be installed. They can be install once the virtual environment has been activated, and the run: +``` bash +pip install -r dev-requirements.txt ``` + ### Linting You can configure the [pre-commit](https://pre-commit.com/) to automatically run all linters locally on each commit. Install `pre-commit` on your system, and then enable it with `pre-commit install`. diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..0873db7 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,3 @@ +pre-commit +flake8==7.1.1 +black==24.4.2 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..bc12405 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools >= 65", + "setuptools_scm[toml] >6.2", + "wheel >= 0.38.1", +] +build-backend = 'setuptools.build_meta' diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index ac5ed6d..0000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -# weaviate-client @ git+https://github.com/weaviate/weaviate-python-client.git@dev/1.26 -weaviate-client -numpy -semver -click - -pre-commit - -flake8==7.1.1 -black==24.4.2 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..c341850 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,55 @@ +[metadata] +name = weaviatests +provides = weaviatests +description = Weaviate library for testing +url = https://github.com/weaviate/weaviatest +download_url = https://github.com/weaviate/weaviatest +author = weaviate +author_email = +keywords = python3, sql +license = GPL-3 +platforms = Linux +version = 0.0.1 +project_urls = + Docs = https://github.com/weaviate/weaviatest/blob/main/README.md + Bugs = https://github.com/weaviate/weaviatest/issues + +license_files = + LICENSE +long_description = file: README.md +long_description_content_type = text/markdown +classifiers = + Development Status :: 3 - Alpha + Environment :: Console + Intended Audience :: Developers + Intended Audience :: Other Audience + Natural Language :: English + License :: OSI Approved :: GNU General Public License (GPL) + License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.12 + Programming Language :: Python :: Implementation :: CPython + Topic :: Software Development + +[options] +include_package_data = True +python_requires = + >=3.12 +install_requires = + weaviate-client + numpy + semver + click +setup_requires = + pip + setuptools +zip_safe = False +packages = + weaviatest + +[options.package_data] +# If any package or subpackage contains *.txt, *.rst or *.md files, include them: +*: ["*.txt", "*.rst", "*.md", LICENSE], \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/weaviatest.py b/weaviatest.py index 07394af..aff4e0a 100755 --- a/weaviatest.py +++ b/weaviatest.py @@ -3,21 +3,21 @@ import click import sys -from lib.create_collection import create_collection -from lib.create_tenants import create_tenants -from lib.create_backup import create_backup -from lib.delete_collection import delete_collection -from lib.delete_data import delete_data -from lib.delete_tenants import delete_tenants -from lib.create_data import ingest_data -from lib.update_collection import update_collection -from lib.update_data import update_data -from lib.update_tenants import update_tenants -from lib.query_data import query_data -from lib.restore_backup import restore_backup -from lib.get_collection import get_collection -from lib.get_tenants import get_tenants -from lib.common import connect_to_weaviate +from weaviatest.create_collection import create_collection +from weaviatest.create_tenants import create_tenants +from weaviatest.create_backup import create_backup +from weaviatest.delete_collection import delete_collection +from weaviatest.delete_data import delete_data +from weaviatest.delete_tenants import delete_tenants +from weaviatest.create_data import ingest_data +from weaviatest.update_collection import update_collection +from weaviatest.update_data import update_data +from weaviatest.update_tenants import update_tenants +from weaviatest.query_data import query_data +from weaviatest.restore_backup import restore_backup +from weaviatest.get_collection import get_collection +from weaviatest.get_tenants import get_tenants +from weaviatest.common import connect_to_weaviate # General CLI group for Weaviate operations diff --git a/weaviatest/__init__.py b/weaviatest/__init__.py new file mode 100644 index 0000000..143f486 --- /dev/null +++ b/weaviatest/__init__.py @@ -0,0 +1 @@ +# __init__.py diff --git a/lib/common.py b/weaviatest/common.py similarity index 100% rename from lib/common.py rename to weaviatest/common.py diff --git a/lib/create_backup.py b/weaviatest/create_backup.py similarity index 100% rename from lib/create_backup.py rename to weaviatest/create_backup.py diff --git a/lib/create_collection.py b/weaviatest/create_collection.py similarity index 100% rename from lib/create_collection.py rename to weaviatest/create_collection.py diff --git a/lib/create_data.py b/weaviatest/create_data.py similarity index 99% rename from lib/create_data.py rename to weaviatest/create_data.py index 1053179..4705421 100755 --- a/lib/create_data.py +++ b/weaviatest/create_data.py @@ -1,4 +1,4 @@ -import lib.common as common +import weaviatest.common as common import json import numpy as np import random diff --git a/lib/create_tenants.py b/weaviatest/create_tenants.py similarity index 100% rename from lib/create_tenants.py rename to weaviatest/create_tenants.py diff --git a/lib/delete_collection.py b/weaviatest/delete_collection.py similarity index 100% rename from lib/delete_collection.py rename to weaviatest/delete_collection.py diff --git a/lib/delete_data.py b/weaviatest/delete_data.py similarity index 100% rename from lib/delete_data.py rename to weaviatest/delete_data.py diff --git a/lib/delete_tenants.py b/weaviatest/delete_tenants.py similarity index 98% rename from lib/delete_tenants.py rename to weaviatest/delete_tenants.py index eac4e90..b112829 100755 --- a/lib/delete_tenants.py +++ b/weaviatest/delete_tenants.py @@ -1,4 +1,4 @@ -import lib.common as common +import weaviatest.common as common import semver from weaviate.collections.classes.tenants import Tenant diff --git a/lib/get_collection.py b/weaviatest/get_collection.py similarity index 100% rename from lib/get_collection.py rename to weaviatest/get_collection.py diff --git a/lib/get_tenants.py b/weaviatest/get_tenants.py similarity index 98% rename from lib/get_tenants.py rename to weaviatest/get_tenants.py index 5cf333d..8304e74 100644 --- a/lib/get_tenants.py +++ b/weaviatest/get_tenants.py @@ -31,3 +31,4 @@ def get_tenants(client, collection, verbose): print( f"{len(tenants):<20}{len(inactive_tenants):<20}{len(active_tenants):<20}{len(offoaded_tenants):<20}" ) + return tenants diff --git a/lib/query_data.py b/weaviatest/query_data.py similarity index 98% rename from lib/query_data.py rename to weaviatest/query_data.py index b3eb0d4..1585680 100755 --- a/lib/query_data.py +++ b/weaviatest/query_data.py @@ -1,4 +1,4 @@ -import lib.common as common +import weaviatest.common as common import weaviate.classes.config as wvc from weaviate.classes.query import MetadataQuery from weaviate.collections.classes.tenants import TenantActivityStatus diff --git a/lib/restore_backup.py b/weaviatest/restore_backup.py similarity index 100% rename from lib/restore_backup.py rename to weaviatest/restore_backup.py diff --git a/lib/update_collection.py b/weaviatest/update_collection.py similarity index 100% rename from lib/update_collection.py rename to weaviatest/update_collection.py diff --git a/lib/update_data.py b/weaviatest/update_data.py similarity index 99% rename from lib/update_data.py rename to weaviatest/update_data.py index da7b850..43dcf0e 100755 --- a/lib/update_data.py +++ b/weaviatest/update_data.py @@ -1,4 +1,4 @@ -import lib.common as common +import weaviatest.common as common import numpy as np import random import weaviate.classes.config as wvc diff --git a/lib/update_tenants.py b/weaviatest/update_tenants.py similarity index 100% rename from lib/update_tenants.py rename to weaviatest/update_tenants.py