Skip to content

Commit

Permalink
Migrate Python integration package to independent repo (#1)
Browse files Browse the repository at this point in the history
* Update .gitignore

* Update doc

* Add code and tests

* Fix lints and formatting

* Fix unused imports and paths

* Fix linting and mypy errors

* Fix paths and makefile

* Fix lint error for py39

* Fix type inheritance for pydantic validator

* Add docs

* Fix lint error

* Fix bug with schema

* Update build workflow

* Pass mypy

* Fix lint

* Remove integration tests
  • Loading branch information
prrao87 authored Jan 3, 2025
1 parent db0264a commit 2df5dab
Show file tree
Hide file tree
Showing 28 changed files with 3,458 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Dict

LIB_DIRS = ["libs/{lib}"]
LIB_DIRS = ["libs/kuzu"]

if __name__ == "__main__":
files = sys.argv[1:]
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/get_min_versions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
import sys

import tomllib
from packaging.version import parse as parse_version
import re

MIN_VERSION_LIBS = ["langchain-core"]

Expand Down
55 changes: 0 additions & 55 deletions .github/workflows/_compile_integration_test.yml

This file was deleted.

16 changes: 8 additions & 8 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ on:
working-directory:
required: true
type: string
default: 'libs/{lib}'
default: 'libs/kuzu'

env:
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.7.1"
PYTHON_VERSION: "3.12"
POETRY_VERSION: "1.8.5"

jobs:
build:
Expand Down Expand Up @@ -157,11 +157,11 @@ jobs:
run: make tests
working-directory: ${{ inputs.working-directory }}

- name: Run integration tests
env:
PARTNER_API_KEY: ${{ secrets.PARTNER_API_KEY }}
run: make integration_tests
working-directory: ${{ inputs.working-directory }}
# - name: Run integration tests
# env:
# PARTNER_API_KEY: ${{ secrets.PARTNER_API_KEY }}
# run: make integration_tests
# working-directory: ${{ inputs.working-directory }}

- name: Get minimum versions
working-directory: ${{ inputs.working-directory }}
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/check_diffs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,9 @@ jobs:
working-directory: ${{ matrix.working-directory }}
secrets: inherit

compile-integration-tests:
name: cd ${{ matrix.working-directory }}
needs: [ build ]
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
strategy:
matrix:
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
uses: ./.github/workflows/_compile_integration_test.yml
with:
working-directory: ${{ matrix.working-directory }}
secrets: inherit
ci_success:
name: "CI Success"
needs: [build, lint, test, compile-integration-tests]
needs: [build, lint, test]
if: |
always()
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ __pycache__
.mypy_cache_test
.env
.venv*
test_db
.DS_Store
.coverage
71 changes: 3 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,5 @@
# 🦜️🔗 LangChain {partner}
# 🦜️🔗 LangChain Kùzu

This repository contains 1 package with {partner} integrations with LangChain:
This repository contains 1 package that integrates Kùzu, an embedded graph database, with LangChain:

- [langchain-{package_lower}](https://pypi.org/project/langchain-{package_lower}/)

## Initial Repo Checklist (Remove this section after completing)

Welcome to the LangChain Partner Integration Repository! This checklist will help you get started with your new repository.

After creating your repo from the integration-repo-template, we'll go through the following steps:

1. Setting up your new repository in GitHub
2.

This setup assumes that the partner package is already split. For those instructions,
see [these docs](https://python.langchain.com/docs/contributing/integrations#partner-packages).

Code (auto ecli)

- [ ] Fill out the readme above (for folks that follow pypi link)
- [ ] Copy package into /libs folder
- [ ] Update these fields in /libs/*/pyproject.toml

- `tool.poetry.repository`
- `tool.poetry.urls["Source Code"]`

Workflow code (auto ecli)

- [ ] Populate .github/workflows/_release.yml with `on.workflow_dispatch.inputs.working-directory.default`
- [ ] Configure `LIB_DIRS` in .github/scripts/check_diff.py

Workflow code (manual)

- [ ] Add secrets as env vars in .github/workflows/_release.yml

Monorepo workflow code (manual)

- [ ] Pull in new code location, remove old in .github/workflows/api_doc_build.yml

In github (manual)

- [ ] Add integration testing secrets in Github (ask Erick for help)
- [ ] Add partner collaborators in Github (ask Erick for help)
- [ ] "Allow auto-merge" in General Settings
- [ ] Only "Allow squash merging" in General Settings
- [ ] Set up ruleset matching CI build (ask Erick for help)
- name: ci build
- enforcement: active
- bypass: write
- target: default branch
- rules: restrict deletions, require status checks ("CI Success"), block force pushes
- [ ] Set up ruleset
- name: require prs
- enforcement: active
- bypass: none
- target: default branch
- rules: restrict deletions, require a pull request before merging (0 approvals, no boxes), block force pushes

Pypi (manual)

- [ ] Add new repo to test-pypi and pypi trusted publishing (ask Erick for help)

Slack

- [ ] Set up release alerting in Slack (ask Erick for help)

release:
/github subscribe langchain-ai/langchain-{partner_lower} releases workflows:{name:"release"}
/github unsubscribe langchain-ai/langchain-{partner_lower} issues pulls commits deployments
- [langchain-kuzu](https://pypi.org/project/langchain-kuzu/)
64 changes: 64 additions & 0 deletions libs/kuzu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests

# Default target executed when no arguments are given to make.
all: help

# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/
# integration_test integration_tests: TEST_FILE = tests/integration_tests/


# unit tests are run with the --disable-socket flag to prevent network calls
test tests:
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)

test_watch:
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)

# # integration tests are run without the --disable-socket flag to allow network calls
# integration_test integration_tests:
# poetry run pytest $(TEST_FILE)

######################
# LINTING AND FORMATTING
######################

# Define a variable for Python and notebook files.
PYTHON_FILES=.
MYPY_CACHE=.mypy_cache
lint format: PYTHON_FILES=.
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/kuzu --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
lint_package: PYTHON_FILES=langchain_kuzu
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test

lint lint_diff lint_package lint_tests:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)

format format_diff:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I --fix $(PYTHON_FILES)

spell_check:
poetry run codespell --toml pyproject.toml

spell_fix:
poetry run codespell --toml pyproject.toml -w

check_imports: $(shell find langchain_kuzu -name '*.py')
poetry run python ./scripts/check_imports.py $^

######################
# HELP
######################

help:
@echo '----'
@echo 'check_imports - check imports'
@echo 'format - run code formatters'
@echo 'lint - run linters'
@echo 'test - run unit tests'
@echo 'tests - run unit tests'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
Loading

0 comments on commit 2df5dab

Please sign in to comment.