Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# VCS
.git/
.gitignore

# Python build artifacts
*.egg-info/
__pycache__/
*.py[cod]
*.so
build/
dist/
.eggs/

# Packaging outputs (avoid re-bundling previous build products)
debian-packages/
rpm-packages/

# Editor / OS
.vscode/
.idea/
.DS_Store
36 changes: 36 additions & 0 deletions .github/workflows/build-deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Debian Packages

on:
push:
tags:
- 'v*'
pull_request:
branches: [main]
paths:
- 'packaging/debian/**'
- 'src/**'
- 'pyproject.toml'
- '.github/workflows/build-deb.yml'
workflow_dispatch:

jobs:
build-deb:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build .deb
run: bash packaging/debian/build-helpers/build-flagtensor.sh

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: flagtensor-amd64-packages
path: debian-packages/*.deb
retention-days: 7
36 changes: 36 additions & 0 deletions .github/workflows/build-rpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build RPM Packages

on:
push:
tags:
- 'v*'
pull_request:
branches: [main]
paths:
- 'packaging/rpm/**'
- 'src/**'
- 'pyproject.toml'
- '.github/workflows/build-rpm.yml'
workflow_dispatch:

jobs:
build-rpm:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build .rpm
run: bash packaging/rpm/build-flagtensor-rpm.sh

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: flagtensor-amd64-rpm-packages
path: rpm-packages/*.rpm
retention-days: 7
26 changes: 26 additions & 0 deletions packaging/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Installing python3-flagtensor

After `apt install python3-flagtensor` (Debian/Ubuntu) or `dnf install python3-flagtensor` (Fedora),
install the ML runtime separately — it is intentionally **not** declared as a
hard Depends/Requires because the distro versions are CPU-only (torch) or
too old (triton) for GPU workloads.

FlagTensor needs PyTorch (GPU build) and Triton at runtime:

```bash
pip install --index-url https://download.pytorch.org/whl/cu128 torch==2.9.0+cu128
pip install triton
```

A `venv` is recommended to isolate pip-installed packages from the system
Python:

```bash
python3 -m venv ~/.venv/flagos
source ~/.venv/flagos/bin/activate
# then the pip install lines above
```

Note: the distro `python3-torch` package (CPU-only build) is intentionally
not pulled in — FlagOS workloads need a GPU build, which PyTorch upstream
distributes via PyPI (per-CUDA-version wheels), not as a `.deb` / `.rpm`.
32 changes: 32 additions & 0 deletions packaging/debian/build-helpers/Dockerfile.deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG BASE_IMAGE_VERSION=24.04
FROM ubuntu:${BASE_IMAGE_VERSION}
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential debhelper devscripts dpkg-dev fakeroot \
dh-python pybuild-plugin-pyproject \
python3-all python3-pip python3-setuptools python3-wheel \
git ca-certificates \
lintian \
&& apt-get clean && rm -rf /var/lib/apt/lists/*


COPY . /workspace/FlagTensor
WORKDIR /workspace/FlagTensor

RUN cp -r packaging/debian debian

RUN dpkg-buildpackage -us -uc -b || \
{ echo "=== build failed ===" >&2; \
find /workspace -name "*.log" -exec echo "=== {} ===" \; -exec cat {} \; 2>/dev/null || true; \
exit 1; }

# Run lintian against the produced .deb — surface packaging warnings
# (unused-license-paragraph, no-manual-page, missing-build-dependency, etc.)
# in the build log without failing the build.
RUN lintian --info --display-info /workspace/python3-flagtensor_*.deb || true

RUN mkdir -p /output && \
find /workspace -maxdepth 1 -name "*.deb" -exec cp {} /output/ \; && \
find /workspace -maxdepth 1 -name "*.changes" -exec cp {} /output/ \; && \
ls -lh /output/
19 changes: 19 additions & 0 deletions packaging/debian/build-helpers/build-flagtensor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$(dirname "$(dirname "$SCRIPT_DIR")")")"
BASE_IMAGE_VERSION="${1:-24.04}"
IMAGE_TAG="flagtensor-deb:${BASE_IMAGE_VERSION}"
OUTPUT_DIR="${PROJECT_DIR}/debian-packages"

docker build --network=host \
-f "${SCRIPT_DIR}/Dockerfile.deb" \
--build-arg BASE_IMAGE_VERSION="$BASE_IMAGE_VERSION" \
-t "$IMAGE_TAG" "$PROJECT_DIR"

mkdir -p "$OUTPUT_DIR"
CID=$(docker create "$IMAGE_TAG")
docker cp "$CID:/output/." "$OUTPUT_DIR/"
docker rm "$CID" > /dev/null

echo ""; echo ">>> Output:"; ls -lh "$OUTPUT_DIR"
5 changes: 5 additions & 0 deletions packaging/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flagtensor (0.1.0-1) unstable; urgency=medium

* Initial Debian packaging.

-- FlagOS Contributors <contact@flagos.io> Tue, 12 May 2026 12:00:00 +0000
24 changes: 24 additions & 0 deletions packaging/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Source: flagtensor
Section: python
Priority: optional
Maintainer: FlagOS Contributors <contact@flagos.io>
Build-Depends: debhelper-compat (= 13),
dh-python,
python3-all,
python3-setuptools,
python3-wheel,
pybuild-plugin-pyproject
Standards-Version: 4.6.2
Homepage: https://github.com/flagos-ai/FlagTensor
Vcs-Browser: https://github.com/flagos-ai/FlagTensor
Vcs-Git: https://github.com/flagos-ai/FlagTensor.git
Rules-Requires-Root: no

Package: python3-flagtensor
Architecture: all
Depends: python3:any, ${misc:Depends}, python3-matplotlib, python3-openpyxl
# python3-torch and triton are intentionally NOT declared. distro torch is
# CPU-only, triton has no current distro package. Install both via pip
# (see packaging/INSTALL.md).
Description: FlagTensor — tensor utilities for FlagOS
Tensor manipulation utilities (reshape/permute/index helpers) used across the FlagOS operator libraries.
23 changes: 23 additions & 0 deletions packaging/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: FlagTensor
Upstream-Contact: FlagOS Contributors <contact@flagos.io>
Source: https://github.com/flagos-ai/FlagTensor

Files: *
Copyright: 2024-2026 Beijing Academy of Artificial Intelligence (BAAI)
2024-2026 FlagTensor contributors
License: Apache-2.0

License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.
On Debian systems, the full text of the Apache 2.0 License is in
/usr/share/common-licenses/Apache-2.0.
34 changes: 34 additions & 0 deletions packaging/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/make -f
export DH_VERBOSE = 1
export PYBUILD_NAME = flagtensor

%:
dh $@ --with python3 --buildsystem=pybuild

# Smoke find_spec test (not actual import) — verifies the built
# module lands at the expected path. Doesn't import the module
# because module-level deps (torch, triton, cupy, ...) are install-
# time concerns not satisfied in the build container. Catches:
# wrong install path, missing __init__.py, dh_python install bugs.
# Note: prior version used `import ; exit 0` which silently passed
# on import failures. Fixed with && short-circuit.
override_dh_auto_test:
@echo "=== smoke find_spec test ==="
# Use found_dir + break (not `&& exit 0` inside the loop) so future
# multi-Python builds verify every interpreter rather than stopping
# at the first match.
@found_dir=""; \
for d in .pybuild/cpython3_*/build; do \
if [ -d "$$d/flagtensor" ]; then \
found_dir="$$d"; \
break; \
fi; \
done; \
if [ -z "$$found_dir" ]; then \
echo "ERROR: could not find a built flagtensor module"; \
exit 1; \
fi; \
echo "Found build dir: $$found_dir"; \
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH="$$found_dir" python3 -c \
"import importlib.util; s = importlib.util.find_spec('flagtensor'); assert s and s.origin, 'flagtensor not findable'; print('OK: flagtensor at', s.origin)"

1 change: 1 addition & 0 deletions packaging/debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
19 changes: 19 additions & 0 deletions packaging/rpm/build-flagtensor-rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
BASE_IMAGE_VERSION="${1:-43}"
IMAGE_TAG="flagtensor-rpm:f${BASE_IMAGE_VERSION}"
OUTPUT_DIR="${PROJECT_DIR}/rpm-packages"

docker build --network=host \
-f "${SCRIPT_DIR}/dockerfiles/Dockerfile.rpm" \
--build-arg BASE_IMAGE_VERSION="$BASE_IMAGE_VERSION" \
-t "$IMAGE_TAG" "$PROJECT_DIR"

mkdir -p "$OUTPUT_DIR"
CID=$(docker create "$IMAGE_TAG")
docker cp "$CID:/output/." "$OUTPUT_DIR/"
docker rm "$CID" > /dev/null

echo ""; echo ">>> Output:"; ls -lh "$OUTPUT_DIR"
30 changes: 30 additions & 0 deletions packaging/rpm/dockerfiles/Dockerfile.rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG BASE_IMAGE=fedora
ARG BASE_IMAGE_VERSION=43

FROM ${BASE_IMAGE}:${BASE_IMAGE_VERSION}

RUN dnf install -y \
rpm-build rpmdevtools pyproject-rpm-macros \
python3-devel python3-setuptools python3-wheel python3-pip \
&& dnf clean all

RUN rpmdev-setuptree

COPY . /workspace/FlagTensor

RUN SPEC_VERSION=$(grep '^Version:' /workspace/FlagTensor/packaging/rpm/specs/flagtensor.spec | awk '{print $2}') && \
tar czf /root/rpmbuild/SOURCES/flagtensor-${SPEC_VERSION}.tar.gz \
-C /workspace/FlagTensor \
--exclude='./.git' \
--transform "s|^\\./|flagtensor-${SPEC_VERSION}/|" \
.

RUN rpmbuild -ba /workspace/FlagTensor/packaging/rpm/specs/flagtensor.spec 2>&1 || \
{ echo "=== build failed ==="; \
find /root/rpmbuild -name "*.log" -exec echo "=== {} ===" \; -exec cat {} \; 2>/dev/null || true; \
exit 1; }

RUN mkdir -p /output && \
find /root/rpmbuild/RPMS -name "*.rpm" -exec cp {} /output/ \; && \
find /root/rpmbuild/SRPMS -name "*.rpm" -exec cp {} /output/ \; && \
ls -lh /output/
50 changes: 50 additions & 0 deletions packaging/rpm/specs/flagtensor.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%global debug_package %{nil}

# Filter the auto-generated Requires for: torch + triton.
# Reason: distro torch is CPU-only; distro triton has no current version. Users install both via pip.
# See packaging/INSTALL.md (or future flagos-packaging install docs) for the
# user-side pip install incantation.
%global __requires_exclude ^python3(\.[0-9]+)?dist\((torch|triton)\)$
Name: python3-flagtensor
Version: 0.1.0
Release: 1%{?dist}
Summary: FlagTensor — tensor utilities for FlagOS

License: Apache-2.0
URL: https://github.com/flagos-ai/FlagTensor
Source0: %{url}/archive/refs/tags/v%{version}.tar.gz#/flagtensor-%{version}.tar.gz
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3-setuptools >= 60
BuildRequires: python3-wheel
BuildRequires: python3-pip
BuildRequires: pyproject-rpm-macros

%description
Tensor manipulation utilities (reshape/permute/index helpers) used across the FlagOS operator libraries.

%prep
%autosetup -n flagtensor-%{version}

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files flagtensor

%check
# Smoke find_spec test (no actual import) — verifies the built module
# lands at the expected sitelib path. Doesn't import the module so
# missing runtime deps (torch, triton, ...) don't trip the check;
# those are user-install-time concerns, not packaging concerns.
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=%{buildroot}%{python3_sitelib} \
python3 -c "import importlib.util; s = importlib.util.find_spec('flagtensor'); assert s and s.origin, 'flagtensor not findable'; print('OK: flagtensor at', s.origin)"

%files -f %{pyproject_files}
%license LICENSE

%changelog
* Wed May 13 2026 FlagOS Contributors <contact@flagos.io> - 0.1.0-1
- Initial RPM packaging.