From f5a68d936c060dddff2fae043b1a2cbcfb22ca38 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Sun, 26 Apr 2026 23:01:24 +0800 Subject: [PATCH] release: 0.0.1 --- README.md | 50 +++++++++++++ Scripts/publish_to_gitea.sh | 145 ++++++++++++++++++++++++++++++++++++ conda_env/recipe/README.md | 44 +++++++++++ conda_env/recipe/meta.yaml | 42 +++++++++++ pyproject.toml | 26 +++++++ 5 files changed, 307 insertions(+) create mode 100755 Scripts/publish_to_gitea.sh create mode 100644 conda_env/recipe/README.md create mode 100644 conda_env/recipe/meta.yaml create mode 100644 pyproject.toml diff --git a/README.md b/README.md index f44a087..0fe31e3 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,56 @@ pip install pandas numpy scipy scikit-learn matplotlib seaborn openpyxl xlrd pip install black autopep8 basedpyright ``` +### 1.6 打包 Qfunctions + Qtorch 为 Conda 包 + +项目已提供可直接构建的打包文件: + +- `pyproject.toml` +- `conda_env/recipe/meta.yaml` + +构建步骤: + +```bash +conda activate Deeplearning +conda install -n Deeplearning -y conda-build anaconda-client +cd /home/newbie/Project/MachineLearning/Deeplearning +conda-build conda_env/recipe +``` + +本地安装(从本机 conda-bld): + +```bash +conda activate Deeplearning +conda install -n Deeplearning -y -c local deeplearning-qtools +``` + +安装后即可使用: + +```bash +python -c "import Qfunctions, Qtorch; print('ok')" +``` + +发布到 Anaconda.org 后,其他项目(如 GestureRecognition)可直接安装: + +```bash +conda install -c deeplearning-qtools +``` + +一键发布到 Gitea(自动构建 + 打 tag + push + 可选创建 Release): + +```bash +cd /home/newbie/Project/MachineLearning/Deeplearning +chmod +x Scripts/publish_to_gitea.sh +./Scripts/publish_to_gitea.sh +``` + +如果希望脚本自动在 Gitea 创建 Release 并上传 conda 包,请先设置: + +```bash +export GITEA_TOKEN= +./Scripts/publish_to_gitea.sh +``` + ## 2. 项目约定 ### 2.1 输入数据格式 diff --git a/Scripts/publish_to_gitea.sh b/Scripts/publish_to_gitea.sh new file mode 100755 index 0000000..a3d2810 --- /dev/null +++ b/Scripts/publish_to_gitea.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash +set -euo pipefail + +# One-command publish flow: +# 1) Build conda package +# 2) Commit current changes (if any) +# 3) Tag as v +# 4) Push branch + tag to origin (your Gitea remote) +# 5) Optionally create Gitea Release and upload built package when GITEA_TOKEN is set + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +cd "$ROOT_DIR" + +if ! command -v python >/dev/null 2>&1; then + echo "python not found in PATH" + exit 1 +fi + +if ! command -v conda >/dev/null 2>&1; then + echo "conda not found in PATH" + exit 1 +fi + +if ! command -v conda-build >/dev/null 2>&1; then + echo "conda-build is not installed in current environment." + echo "Run: conda install -n Deeplearning -y conda-build" + exit 1 +fi + +VERSION="$(python - <<'PY' +import pathlib +import re +text = pathlib.Path('pyproject.toml').read_text(encoding='utf-8') +m = re.search(r'^version\s*=\s*"([^"]+)"', text, flags=re.M) +if not m: + raise SystemExit('Could not read version from pyproject.toml') +print(m.group(1)) +PY +)" +TAG="v${VERSION}" + +echo "Building conda package for version: ${VERSION}" +PKG_PATH="$(conda-build conda_env/recipe --output)" +conda-build conda_env/recipe + +if git diff --quiet && git diff --cached --quiet; then + echo "No local file changes to commit." +else + git add pyproject.toml conda_env/recipe/meta.yaml conda_env/recipe/README.md Scripts/publish_to_gitea.sh README.md + git commit -m "release: ${VERSION}" || true +fi + +if git rev-parse "${TAG}" >/dev/null 2>&1; then + echo "Tag ${TAG} already exists locally." +else + git tag -a "${TAG}" -m "Release ${TAG}" +fi + +echo "Pushing current branch and tag to origin" +git push origin HEAD +git push origin "${TAG}" + +echo "Pushed to origin." + +if [[ -z "${GITEA_TOKEN:-}" ]]; then + echo "GITEA_TOKEN not set. Skip creating Gitea Release." + echo "Built package: ${PKG_PATH}" + exit 0 +fi + +ORIGIN_URL="$(git remote get-url origin)" + +parse_owner_repo() { + local url="$1" + if [[ "$url" =~ ^git@([^:]+):(.+)\.git$ ]]; then + echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}" + return + fi + if [[ "$url" =~ ^https?://([^/]+)/(.+)\.git$ ]]; then + echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}" + return + fi + echo "" +} + +PARSED="$(parse_owner_repo "$ORIGIN_URL")" +if [[ -z "$PARSED" ]]; then + echo "Cannot parse origin URL: $ORIGIN_URL" + exit 1 +fi + +GITEA_HOST="${PARSED%%|*}" +OWNER_REPO="${PARSED#*|}" +API_BASE="https://${GITEA_HOST}/api/v1/repos/${OWNER_REPO}" + +echo "Creating or updating Gitea release ${TAG} on ${OWNER_REPO}" + +RELEASE_JSON="$(curl -sS -X POST "${API_BASE}/releases" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" || true)" + +RELEASE_ID="$(printf '%s' "$RELEASE_JSON" | python - <<'PY' +import json,sys +text=sys.stdin.read().strip() +if not text: + print('') + raise SystemExit +try: + obj=json.loads(text) +except Exception: + print('') + raise SystemExit +print(obj.get('id','')) +PY +)" + +if [[ -z "$RELEASE_ID" ]]; then + RELEASE_ID="$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" "${API_BASE}/releases/tags/${TAG}" | python - <<'PY' +import json,sys +text=sys.stdin.read().strip() +try: + obj=json.loads(text) +except Exception: + print('') + raise SystemExit +print(obj.get('id','')) +PY +)" +fi + +if [[ -z "$RELEASE_ID" ]]; then + echo "Failed to get release id for tag ${TAG}" + exit 1 +fi + +PKG_FILE="$(basename "$PKG_PATH")" +echo "Uploading asset ${PKG_FILE}" +curl -sS -X POST "${API_BASE}/releases/${RELEASE_ID}/assets?name=${PKG_FILE}" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@${PKG_PATH}" >/dev/null + +echo "Release published: ${TAG}" +echo "Asset uploaded: ${PKG_FILE}" diff --git a/conda_env/recipe/README.md b/conda_env/recipe/README.md new file mode 100644 index 0000000..8368613 --- /dev/null +++ b/conda_env/recipe/README.md @@ -0,0 +1,44 @@ +# Build and install Deeplearning conda package + +This recipe packages both `Qfunctions` and `Qtorch` into one conda package: + +- Package name: `deeplearning-qtools` +- Import names after install: `Qfunctions`, `Qtorch` + +## 1) Build package + +```bash +conda activate Deeplearning +conda install -n Deeplearning -y conda-build anaconda-client +cd /home/newbie/Project/MachineLearning/Deeplearning +conda-build conda_env/recipe +``` + +## 2) Install from local build output + +```bash +conda activate Deeplearning +conda install -n Deeplearning -y -c local deeplearning-qtools +``` + +## 3) Verify imports + +```bash +python -c "import Qfunctions, Qtorch; print('ok')" +``` + +## 4) Upload to Anaconda.org (optional) + +```bash +# Login once +anaconda login + +# Upload generated package (linux-64/noarch path depends on build output) +anaconda upload /home//miniconda3/conda-bld/noarch/deeplearning-qtools-0.0.1-py_0.conda +``` + +After upload, others can install with: + +```bash +conda install -c deeplearning-qtools +``` diff --git a/conda_env/recipe/meta.yaml b/conda_env/recipe/meta.yaml new file mode 100644 index 0000000..4ca40dc --- /dev/null +++ b/conda_env/recipe/meta.yaml @@ -0,0 +1,42 @@ +{% set name = "deeplearning-qtools" %} +{% set version = "0.0.1" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + path: ../.. + +build: + noarch: python + number: 0 + script: "{{ PYTHON }} -m pip install . --no-deps --no-build-isolation -vv" + +requirements: + host: + - python >=3.10 + - pip + - setuptools >=68 + - wheel + run: + - python >=3.10 + - numpy >=1.24 + - pandas >=2.0 + - matplotlib >=3.7 + - scikit-learn >=1.3 + - openpyxl >=3.1 + - pytorch >=2.0 + +test: + imports: + - Qfunctions + - Qtorch + +about: + summary: Reusable Qfunctions and Qtorch modules from Deeplearning + license: Proprietary + +extra: + recipe-maintainers: + - deeplearning-team diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..18b9a22 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools>=68", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "deeplearning-qtools" +version = "0.0.1" +description = "Reusable Qfunctions and Qtorch modules from Deeplearning" +readme = "README.md" +requires-python = ">=3.10" +authors = [{ name = "Deeplearning Team" }] +dependencies = [ + "numpy>=1.24", + "pandas>=2.0", + "matplotlib>=3.7", + "scikit-learn>=1.3", + "openpyxl>=3.1", + "torch>=2.0", +] + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +include = ["Qfunctions*", "Qtorch*"] +exclude = ["Result*", "Static*", "Scripts*", "conda_env*"]