Skip to content

Commit c4b3f74

Browse files
authored
Initial commit
0 parents  commit c4b3f74

File tree

14 files changed

+1004
-0
lines changed

14 files changed

+1004
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# An action for setting up poetry install with caching.
2+
# Using a custom action since the default action does not
3+
# take poetry install groups into account.
4+
# Action code from:
5+
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
6+
name: poetry-install-with-caching
7+
description: Poetry install with support for caching of dependency groups.
8+
9+
inputs:
10+
python-version:
11+
description: Python version, supporting MAJOR.MINOR only
12+
required: true
13+
14+
poetry-version:
15+
description: Poetry version
16+
required: true
17+
18+
cache-key:
19+
description: Cache key to use for manual handling of caching
20+
required: true
21+
22+
working-directory:
23+
description: Directory whose poetry.lock file should be cached
24+
required: true
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- uses: actions/setup-python@v5
30+
name: Setup python ${{ inputs.python-version }}
31+
id: setup-python
32+
with:
33+
python-version: ${{ inputs.python-version }}
34+
35+
- uses: actions/cache@v4
36+
id: cache-bin-poetry
37+
name: Cache Poetry binary - Python ${{ inputs.python-version }}
38+
env:
39+
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
40+
with:
41+
path: |
42+
/opt/pipx/venvs/poetry
43+
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
44+
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
45+
46+
- name: Refresh shell hashtable and fixup softlinks
47+
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
48+
shell: bash
49+
env:
50+
POETRY_VERSION: ${{ inputs.poetry-version }}
51+
PYTHON_VERSION: ${{ inputs.python-version }}
52+
run: |
53+
set -eux
54+
55+
# Refresh the shell hashtable, to ensure correct `which` output.
56+
hash -r
57+
58+
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
59+
# Delete and recreate the softlinks pipx expects to have.
60+
rm /opt/pipx/venvs/poetry/bin/python
61+
cd /opt/pipx/venvs/poetry/bin
62+
ln -s "$(which "python$PYTHON_VERSION")" python
63+
chmod +x python
64+
cd /opt/pipx_bin/
65+
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
66+
chmod +x poetry
67+
68+
# Ensure everything got set up correctly.
69+
/opt/pipx/venvs/poetry/bin/python --version
70+
/opt/pipx_bin/poetry --version
71+
72+
- name: Install poetry
73+
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
74+
shell: bash
75+
env:
76+
POETRY_VERSION: ${{ inputs.poetry-version }}
77+
PYTHON_VERSION: ${{ inputs.python-version }}
78+
# Install poetry using the python version installed by setup-python step.
79+
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
80+
81+
- name: Restore pip and poetry cached dependencies
82+
uses: actions/cache@v4
83+
env:
84+
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
85+
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
86+
with:
87+
path: |
88+
~/.cache/pip
89+
~/.cache/pypoetry/virtualenvs
90+
~/.cache/pypoetry/cache
91+
~/.cache/pypoetry/artifacts
92+
${{ env.WORKDIR }}/.venv
93+
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/**/poetry.lock', env.WORKDIR)) }}

.github/scripts/check_diff.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import sys
3+
from typing import Dict
4+
5+
LIB_DIRS = ["libs/{lib}"]
6+
7+
if __name__ == "__main__":
8+
files = sys.argv[1:]
9+
10+
dirs_to_run: Dict[str, set] = {
11+
"lint": set(),
12+
"test": set(),
13+
}
14+
15+
if len(files) == 300:
16+
# max diff length is 300 files - there are likely files missing
17+
raise ValueError("Max diff reached. Please manually run CI on changed libs.")
18+
19+
for file in files:
20+
if any(
21+
file.startswith(dir_)
22+
for dir_ in (
23+
".github/workflows",
24+
".github/tools",
25+
".github/actions",
26+
".github/scripts/check_diff.py",
27+
)
28+
):
29+
# add all LANGCHAIN_DIRS for infra changes
30+
dirs_to_run["test"].update(LIB_DIRS)
31+
32+
if any(file.startswith(dir_) for dir_ in LIB_DIRS):
33+
for dir_ in LIB_DIRS:
34+
if file.startswith(dir_):
35+
dirs_to_run["test"].add(dir_)
36+
elif file.startswith("libs/"):
37+
raise ValueError(
38+
f"Unknown lib: {file}. check_diff.py likely needs "
39+
"an update for this new library!"
40+
)
41+
42+
outputs = {
43+
"dirs-to-lint": list(dirs_to_run["lint"] | dirs_to_run["test"]),
44+
"dirs-to-test": list(dirs_to_run["test"]),
45+
}
46+
for key, value in outputs.items():
47+
json_output = json.dumps(value)
48+
print(f"{key}={json_output}") # noqa: T201
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys
2+
3+
import tomllib
4+
from packaging.version import parse as parse_version
5+
import re
6+
7+
MIN_VERSION_LIBS = ["langchain-core"]
8+
9+
10+
def get_min_version(version: str) -> str:
11+
# case ^x.x.x
12+
_match = re.match(r"^\^(\d+(?:\.\d+){0,2})$", version)
13+
if _match:
14+
return _match.group(1)
15+
16+
# case >=x.x.x,<y.y.y
17+
_match = re.match(r"^>=(\d+(?:\.\d+){0,2}),<(\d+(?:\.\d+){0,2})$", version)
18+
if _match:
19+
_min = _match.group(1)
20+
_max = _match.group(2)
21+
assert parse_version(_min) < parse_version(_max)
22+
return _min
23+
24+
# case x.x.x
25+
_match = re.match(r"^(\d+(?:\.\d+){0,2})$", version)
26+
if _match:
27+
return _match.group(1)
28+
29+
raise ValueError(f"Unrecognized version format: {version}")
30+
31+
32+
def get_min_version_from_toml(toml_path: str):
33+
# Parse the TOML file
34+
with open(toml_path, "rb") as file:
35+
toml_data = tomllib.load(file)
36+
37+
# Get the dependencies from tool.poetry.dependencies
38+
dependencies = toml_data["tool"]["poetry"]["dependencies"]
39+
40+
# Initialize a dictionary to store the minimum versions
41+
min_versions = {}
42+
43+
# Iterate over the libs in MIN_VERSION_LIBS
44+
for lib in MIN_VERSION_LIBS:
45+
# Check if the lib is present in the dependencies
46+
if lib in dependencies:
47+
# Get the version string
48+
version_string = dependencies[lib]
49+
50+
# Use parse_version to get the minimum supported version from version_string
51+
min_version = get_min_version(version_string)
52+
53+
# Store the minimum version in the min_versions dictionary
54+
min_versions[lib] = min_version
55+
56+
return min_versions
57+
58+
59+
# Get the TOML file path from the command line argument
60+
toml_file = sys.argv[1]
61+
62+
# Call the function to get the minimum versions
63+
min_versions = get_min_version_from_toml(toml_file)
64+
65+
print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))

.github/workflows/_codespell.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: make spell_check
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
working-directory:
8+
required: true
9+
type: string
10+
description: "From which folder this pipeline executes"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
codespell:
17+
name: (Check for spelling errors)
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Install Dependencies
25+
run: |
26+
pip install toml
27+
28+
- name: Extract Ignore Words List
29+
working-directory: ${{ inputs.working-directory }}
30+
run: |
31+
# Use a Python script to extract the ignore words list from pyproject.toml
32+
python ../../.github/workflows/extract_ignored_words_list.py
33+
id: extract_ignore_words
34+
35+
- name: Codespell
36+
uses: codespell-project/actions-codespell@v2
37+
with:
38+
skip: guide_imports.json
39+
ignore_words_list: ${{ steps.extract_ignore_words.outputs.ignore_words_list }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: compile-integration-test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
working-directory:
7+
required: true
8+
type: string
9+
description: "From which folder this pipeline executes"
10+
11+
env:
12+
POETRY_VERSION: "1.7.1"
13+
14+
jobs:
15+
build:
16+
defaults:
17+
run:
18+
working-directory: ${{ inputs.working-directory }}
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
python-version:
23+
- "3.9"
24+
- "3.12"
25+
name: "poetry run pytest -m compile tests/integration_tests #${{ matrix.python-version }}"
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
30+
uses: "./.github/actions/poetry_setup"
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
poetry-version: ${{ env.POETRY_VERSION }}
34+
working-directory: ${{ inputs.working-directory }}
35+
cache-key: compile-integration
36+
37+
- name: Install integration dependencies
38+
shell: bash
39+
run: poetry install --with=test_integration,test
40+
41+
- name: Check integration tests compile
42+
shell: bash
43+
run: poetry run pytest -m compile tests/integration_tests
44+
45+
- name: Ensure the tests did not create any additional files
46+
shell: bash
47+
run: |
48+
set -eu
49+
50+
STATUS="$(git status)"
51+
echo "$STATUS"
52+
53+
# grep will exit non-zero if the target message isn't found,
54+
# and `set -e` above will cause the step to fail.
55+
echo "$STATUS" | grep 'nothing to commit, working tree clean'

0 commit comments

Comments
 (0)