forked from chatchat-space/Langchain-Chatchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CICD github action build publish pypi、Release Tag (chatchat-space#4260)
## Add CI/CD build process, which includes the following tasks: compiling and building, releasing to test PyPI, testing with pytest, releasing to PyPI, and publishing a Release Tag. ### your configuration env to github Repository secrets [using-secrets-in-github-actions](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) ### pypi pypi token generate for docs [publishers](https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/) or [publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) #### Environment - PYPI_API_TOKEN - TEST_PYPI_API_TOKEN ### Release Tag [release-action](https://github.com/ncipollo/release-action) [managing-your-personal-access-tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) 增加CICD构建流程,包含了如下作业,编译构建、发布test pypi、测试pytest、发布pypi、发布Release Tag 需要配置仓库变量才能使用,可以在这里查看配置方法 [using-secrets-in-github-actions](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) ### pypi pypi token生成可以选择配置变量也可以选择pipy加入开发人员[publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) #### Environment - PYPI_API_TOKEN - TEST_PYPI_API_TOKEN
- Loading branch information
Showing
17 changed files
with
460 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.PHONY: all format lint test tests test_watch integration_tests docker_tests help extended_tests | ||
|
||
# Default target executed when no arguments are given to make. | ||
all: help | ||
|
||
###################### | ||
# TESTING AND COVERAGE | ||
###################### | ||
|
||
# Define a variable for the test file path. | ||
TEST_FILE ?= tests/unit_tests/ | ||
|
||
# Run unit tests and generate a coverage report. | ||
coverage: | ||
poetry run pytest --cov \ | ||
--cov-config=.coveragerc \ | ||
--cov-report xml \ | ||
--cov-report term-missing:skip-covered \ | ||
$(TEST_FILE) | ||
|
||
test tests: | ||
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE) | ||
|
||
extended_tests: | ||
poetry run pytest --disable-socket --allow-unix-socket --only-extended tests/unit_tests | ||
|
||
test_watch: | ||
poetry run ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket tests/unit_tests | ||
|
||
test_watch_extended: | ||
poetry run ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket --only-extended tests/unit_tests | ||
|
||
integration_tests: | ||
poetry run pytest tests/integration_tests | ||
|
||
scheduled_tests: | ||
poetry run pytest -m scheduled tests/integration_tests | ||
|
||
|
||
###################### | ||
# 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/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$') | ||
lint_package: PYTHON_FILES=chatchat | ||
lint_tests: PYTHON_FILES=tests | ||
lint_tests: MYPY_CACHE=.mypy_cache_test | ||
|
||
lint lint_diff lint_package lint_tests: | ||
./scripts/check_pydantic.sh . | ||
./scripts/lint_imports.sh | ||
poetry run ruff . | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I $(PYTHON_FILES) | ||
[ "$(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 --select I --fix $(PYTHON_FILES) | ||
|
||
spell_check: | ||
poetry run codespell --toml pyproject.toml | ||
|
||
spell_fix: | ||
poetry run codespell --toml pyproject.toml -w | ||
|
||
###################### | ||
# HELP | ||
###################### | ||
|
||
help: | ||
@echo '-- LINTING --' | ||
@echo 'format - run code formatters' | ||
@echo 'lint - run linters' | ||
@echo 'spell_check - run codespell on the project' | ||
@echo 'spell_fix - run codespell on the project and fix the errors' | ||
@echo '-- TESTS --' | ||
@echo 'coverage - run unit tests and generate coverage report' | ||
@echo 'test - run unit tests' | ||
@echo 'tests - run unit tests (alias for "make test")' | ||
@echo 'test TEST_FILE=<test_file> - run all tests in file' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import importlib | ||
import sys | ||
import types | ||
|
||
# 动态导入 a_chatchat 模块 | ||
chatchat = importlib.import_module('chatchat') | ||
|
||
# 创建新的模块对象 | ||
module = types.ModuleType('langchain_chatchat') | ||
sys.modules['langchain_chatchat'] = module | ||
|
||
# 把 a_chatchat 的所有属性复制到 langchain_chatchat | ||
for attr in dir(chatchat): | ||
if not attr.startswith('_'): | ||
setattr(module, attr, getattr(chatchat, attr)) | ||
|
||
|
||
# 动态导入子模块 | ||
def import_submodule(name): | ||
full_name = f'chatchat.{name}' | ||
submodule = importlib.import_module(full_name) | ||
sys.modules[f'langchain_chatchat.{name}'] = submodule | ||
for attr in dir(submodule): | ||
if not attr.startswith('_'): | ||
setattr(module, attr, getattr(submodule, attr)) | ||
|
||
|
||
# 需要的子模块列表,自己添加 | ||
submodules = ['configs', 'server', | ||
'startup', 'webui_pages' | ||
] | ||
|
||
# 导入所有子模块 | ||
for submodule in submodules: | ||
import_submodule(submodule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import random | ||
import string | ||
import sys | ||
import traceback | ||
from importlib.machinery import SourceFileLoader | ||
|
||
if __name__ == "__main__": | ||
files = sys.argv[1:] | ||
has_failure = False | ||
for file in files: | ||
try: | ||
module_name = "".join( | ||
random.choice(string.ascii_letters) for _ in range(20) | ||
) | ||
SourceFileLoader(module_name, file).load_module() | ||
except Exception: | ||
has_failure = True | ||
print(file) # noqa: T201 | ||
traceback.print_exc() | ||
print() # noqa: T201 | ||
|
||
sys.exit(1 if has_failure else 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
# | ||
# This script searches for lines starting with "import pydantic" or "from pydantic" | ||
# in tracked files within a Git repository. | ||
# | ||
# Usage: ./scripts/check_pydantic.sh /path/to/repository | ||
|
||
# Check if a path argument is provided | ||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 /path/to/repository" | ||
exit 1 | ||
fi | ||
|
||
repository_path="$1" | ||
|
||
# Search for lines matching the pattern within the specified repository | ||
result=$(git -C "$repository_path" grep -E '^import pydantic|^from pydantic') | ||
|
||
# Check if any matching lines were found | ||
if [ -n "$result" ]; then | ||
echo "ERROR: The following lines need to be updated:" | ||
echo "$result" | ||
echo "Please replace the code with an import from langchain_core.pydantic_v1." | ||
echo "For example, replace 'from pydantic import BaseModel'" | ||
echo "with 'from langchain_core.pydantic_v1 import BaseModel'" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
# Initialize a variable to keep track of errors | ||
errors=0 | ||
|
||
# make sure not importing from chatchat | ||
git --no-pager grep '^from chatchat\.' . && errors=$((errors+1)) | ||
|
||
# Decide on an exit status based on the errors | ||
if [ "$errors" -gt 0 ]; then | ||
exit 1 | ||
else | ||
exit 0 | ||
fi |
Oops, something went wrong.