Add PyPI packaging support and build automation

- Add pyproject.toml for modern packaging configuration
- Add MANIFEST.in for package distribution manifest
- Add build.sh script for automated package building
- Add clean.sh script for cleaning build artifacts
- Add PYPI.md with comprehensive PyPI publishing guide
- Update setup.py to install main.py to share directory
- Update setup.py metadata (license, author email, repository URL)
- Update .gitignore to include PyPI build artifacts (*.tar.gz, *.whl)
- Update README.md with PyPI installation and build instructions
- Update DOCUMENTATION.md with PyPI packaging section
- Update AI.PROMPT with PyPI packaging changes
- All scripts include proper GPL license headers

The package is now ready for PyPI publication with custom install logic intact.
parent 1e882aa4
...@@ -143,6 +143,10 @@ build/ ...@@ -143,6 +143,10 @@ build/
*.egg *.egg
*.whl *.whl
# PyPI build artifacts
*.tar.gz
*.whl
# Local configuration files # Local configuration files
.local/ .local/
.local/share/aisbf/ .local/share/aisbf/
......
...@@ -10,6 +10,7 @@ This AI.PROMPT file is automatically updated when significant changes are made t ...@@ -10,6 +10,7 @@ This AI.PROMPT file is automatically updated when significant changes are made t
4. **Key Functionality Changes**: When major features are added or existing functionality is significantly modified 4. **Key Functionality Changes**: When major features are added or existing functionality is significantly modified
5. **Command Line Interface Changes**: When the aisbf script commands or behavior are modified 5. **Command Line Interface Changes**: When the aisbf script commands or behavior are modified
6. **Development vs Production Workflow Changes**: When the development/production distinction or workflows are modified 6. **Development vs Production Workflow Changes**: When the development/production distinction or workflows are modified
7. **PyPI Packaging Changes**: When packaging configuration, build scripts, or PyPI-related files are modified
### How to Update AI.PROMPT ### How to Update AI.PROMPT
...@@ -49,18 +50,22 @@ geminiproxy/ ...@@ -49,18 +50,22 @@ geminiproxy/
│ ├── config.py # Configuration management │ ├── config.py # Configuration management
│ ├── models.py # Pydantic models │ ├── models.py # Pydantic models
│ ├── providers.py # Provider handlers │ ├── providers.py # Provider handlers
│ ├── handlers.py # Request handlers │ └── handlers.py # Request handlers
│ ├── providers.json # Default provider configs (moved to config/)
│ └── rotations.json # Default rotation configs (moved to config/)
├── config/ # Configuration files directory ├── config/ # Configuration files directory
│ ├── providers.json # Default provider configurations │ ├── providers.json # Default provider configurations
│ └── rotations.json # Default rotation configurations │ └── rotations.json # Default rotation configurations
├── main.py # FastAPI application entry point ├── main.py # FastAPI application entry point
├── setup.py # Installation script ├── setup.py # Installation script with custom install logic
├── pyproject.toml # Modern packaging configuration for PyPI
├── MANIFEST.in # Package manifest for distribution
├── build.sh # Build script for PyPI packages
├── clean.sh # Clean script for build artifacts
├── start_proxy.sh # Development start script ├── start_proxy.sh # Development start script
├── aisbf.sh # Alternative start script ├── aisbf.sh # Alternative start script
├── requirements.txt # Python dependencies ├── requirements.txt # Python dependencies
├── INSTALL.md # Installation guide ├── INSTALL.md # Installation guide
├── PYPI.md # PyPI publishing guide
├── DOCUMENTATION.md # Complete API documentation
└── README.md # Project documentation └── README.md # Project documentation
``` ```
...@@ -117,7 +122,12 @@ FastAPI application: ...@@ -117,7 +122,12 @@ FastAPI application:
## Installation Process ## Installation Process
### User Installation (no root required) ### Installation from PyPI (Recommended)
```bash
pip install aisbf
```
### User Installation from Source (no root required)
```bash ```bash
python setup.py install python setup.py install
``` ```
...@@ -126,10 +136,10 @@ Automatically adds `--user` flag for non-root users. ...@@ -126,10 +136,10 @@ Automatically adds `--user` flag for non-root users.
Installs to: Installs to:
- `~/.local/lib/python*/site-packages/aisbf/` - Package - `~/.local/lib/python*/site-packages/aisbf/` - Package
- `~/.local/aisbf-venv/` - Virtual environment - `~/.local/aisbf-venv/` - Virtual environment
- `~/.local/share/aisbf/` - Config files - `~/.local/share/aisbf/` - Config files and main.py
- `~/.local/bin/aisbf` - Executable script - `~/.local/bin/aisbf` - Executable script
### System-wide Installation (requires root) ### System-wide Installation from Source (requires root)
```bash ```bash
sudo python setup.py install sudo python setup.py install
``` ```
...@@ -137,7 +147,7 @@ sudo python setup.py install ...@@ -137,7 +147,7 @@ sudo python setup.py install
Installs to: Installs to:
- `/usr/local/lib/python*/dist-packages/aisbf/` - Package - `/usr/local/lib/python*/dist-packages/aisbf/` - Package
- `/usr/local/aisbf-venv/` - Virtual environment - `/usr/local/aisbf-venv/` - Virtual environment
- `/usr/local/share/aisbf/` - Config files - `/usr/local/share/aisbf/` - Config files and main.py
- `/usr/local/bin/aisbf` - Executable script - `/usr/local/bin/aisbf` - Executable script
## Configuration Management ## Configuration Management
...@@ -145,8 +155,8 @@ Installs to: ...@@ -145,8 +155,8 @@ Installs to:
### Configuration File Locations ### Configuration File Locations
**Installed Configuration Files (read-only defaults):** **Installed Configuration Files (read-only defaults):**
- User: `~/.local/share/aisbf/providers.json`, `~/.local/share/aisbf/rotations.json` - User: `~/.local/share/aisbf/providers.json`, `~/.local/share/aisbf/rotations.json`, `~/.local/share/aisbf/main.py`
- System: `/usr/local/share/aisbf/providers.json`, `/usr/local/share/aisbf/rotations.json` - System: `/usr/local/share/aisbf/providers.json`, `/usr/local/share/aisbf/rotations.json`, `/usr/local/share/aisbf/main.py`
**User Configuration Files (writable):** **User Configuration Files (writable):**
- `~/.aisbf/providers.json` - Provider configurations - `~/.aisbf/providers.json` - Provider configurations
...@@ -202,11 +212,65 @@ Use `start_proxy.sh`: ...@@ -202,11 +212,65 @@ Use `start_proxy.sh`:
- Uses `config/` directory for configuration - Uses `config/` directory for configuration
### Production ### Production
Install with `python setup.py install`: Install with `python setup.py install` or `pip install aisbf`:
- Creates isolated venv - Creates isolated venv
- Installs all dependencies - Installs all dependencies
- Provides `aisbf` command with daemon support - Provides `aisbf` command with daemon support
- Uses installed config files - Uses installed config files and main.py from share directory
## PyPI Packaging
### Build Scripts
#### build.sh
Automated build script for creating PyPI distribution packages:
- Checks for build tools (build, twine)
- Installs them if not present
- Cleans previous build artifacts
- Builds package using `python -m build`
- Verifies package with `twine check`
- Displays created files and upload instructions
Usage:
```bash
./build.sh
```
#### clean.sh
Comprehensive cleanup script for removing build artifacts:
- Removes `dist/`, `build/`, `*.egg-info` directories
- Removes Python cache directories and compiled files
- Removes test and coverage artifacts
Usage:
```bash
./clean.sh
```
### Package Files
- **pyproject.toml**: Modern packaging configuration with project metadata
- **MANIFEST.in**: Package manifest specifying files to include in distribution
- **setup.py**: Installation script with custom install logic (venv creation, file copying)
- **PYPI.md**: Comprehensive PyPI publishing guide
### Build Artifacts (Ignored by Git)
The following files and directories are created during build and should not be committed:
- `dist/` - Distribution packages (*.tar.gz, *.whl)
- `build/` - Build artifacts
- `*.egg-info/` - Package metadata directories
- `__pycache__/` - Python bytecode cache
- `*.pyc`, `*.pyo`, `*.pyd` - Compiled Python files
### Publishing Workflow
1. Build the package: `./build.sh`
2. Test on TestPyPI: `python -m twine upload --repository testpypi dist/*`
3. Install from TestPyPI: `pip install --index-url https://test.pypi.org/simple/ aisbf`
4. Publish to PyPI: `python -m twine upload dist/*`
See [`PYPI.md`](PYPI.md) for detailed instructions.
## Important Conventions ## Important Conventions
...@@ -358,6 +422,7 @@ This AI.PROMPT file is automatically updated when significant changes are made t ...@@ -358,6 +422,7 @@ This AI.PROMPT file is automatically updated when significant changes are made t
4. **Key Functionality Changes**: When major features are added or existing functionality is significantly modified 4. **Key Functionality Changes**: When major features are added or existing functionality is significantly modified
5. **Command Line Interface Changes**: When the aisbf script commands or behavior are modified 5. **Command Line Interface Changes**: When the aisbf script commands or behavior are modified
6. **Development vs Production Workflow Changes**: When the development/production distinction or workflows are modified 6. **Development vs Production Workflow Changes**: When the development/production distinction or workflows are modified
7. **PyPI Packaging Changes**: When packaging configuration, build scripts, or PyPI-related files are modified
### How to Update AI.PROMPT ### How to Update AI.PROMPT
......
...@@ -29,10 +29,15 @@ geminiproxy/ ...@@ -29,10 +29,15 @@ geminiproxy/
│ └── rotations.json # Default rotation configurations │ └── rotations.json # Default rotation configurations
├── main.py # FastAPI application entry point ├── main.py # FastAPI application entry point
├── setup.py # Installation script ├── setup.py # Installation script
├── pyproject.toml # Modern packaging configuration
├── MANIFEST.in # Package manifest for distribution
├── build.sh # Build script for PyPI packages
├── clean.sh # Clean script for build artifacts
├── start_proxy.sh # Development start script ├── start_proxy.sh # Development start script
├── aisbf.sh # Alternative start script ├── aisbf.sh # Alternative start script
├── requirements.txt # Python dependencies ├── requirements.txt # Python dependencies
├── INSTALL.md # Installation guide ├── INSTALL.md # Installation guide
├── PYPI.md # PyPI publishing guide
└── README.md # Project documentation └── README.md # Project documentation
``` ```
...@@ -180,6 +185,72 @@ Install with `python setup.py install`: ...@@ -180,6 +185,72 @@ Install with `python setup.py install`:
- Provides `aisbf` command with daemon support - Provides `aisbf` command with daemon support
- Uses installed config files - Uses installed config files
## PyPI Packaging
### Building the Package
To build the package for PyPI distribution:
```bash
./build.sh
```
This script:
- Checks for build tools (build, twine)
- Installs them if not present
- Cleans previous build artifacts
- Builds the package using `python -m build`
- Verifies the package with `twine check`
- Displays created files and upload instructions
### Cleaning Build Artifacts
To remove all build artifacts and temporary files:
```bash
./clean.sh
```
This removes:
- `dist/` directory (distribution packages)
- `build/` directory (build artifacts)
- `*.egg-info` directories (package metadata)
- `__pycache__/` directories (Python bytecode cache)
- `*.pyc`, `*.pyo`, `*.pyd` files (compiled Python files)
- `.pytest_cache/`, `.mypy_cache/` directories
- `.coverage` file, `htmlcov/` directory
### Package Structure
The package includes:
- **Python Module**: `aisbf/` directory with all Python code
- **Configuration Files**: `config/` directory with JSON configs
- **Main Application**: `main.py` - FastAPI application
- **Documentation**: `README.md`, `DOCUMENTATION.md`
- **License**: `LICENSE.txt` (GPL-3.0-or-later)
- **Requirements**: `requirements.txt`
### Installation from PyPI
Users can install AISBF with:
```bash
# User installation (recommended)
pip install aisbf
# System-wide installation (requires root)
sudo pip install aisbf
```
### Publishing to PyPI
See [`PYPI.md`](PYPI.md) for detailed instructions on:
- Setting up PyPI account and API tokens
- Building and testing packages
- Publishing to TestPyPI and PyPI
- Version management
- Troubleshooting
## AISBF Script Commands ## AISBF Script Commands
### Starting in Foreground (Default) ### Starting in Foreground (Default)
......
include README.md
include LICENSE.txt
include requirements.txt
include main.py
recursive-include config *.json
recursive-include aisbf *.py
\ No newline at end of file
# PyPI Publishing Guide for AISBF
This guide explains how to publish the AISBF package to PyPI (Python Package Index).
## Prerequisites
1. **PyPI Account**: Create an account at https://pypi.org/account/register/
2. **Install Build Tools**:
```bash
pip install build twine
```
3. **Configure PyPI Credentials** (optional but recommended):
```bash
# Create ~/.pypirc file
cat > ~/.pypirc << EOF
[pypi]
username = __token__
password = pypi-<your-api-token>
[testpypi]
username = __token__
password = pypi-<your-testpypi-api-token>
EOF
```
To get API tokens:
- Go to https://pypi.org/manage/account/token/
- Create a token for PyPI and TestPyPI
## Building the Package
From the project root directory:
```bash
# Clean previous builds
rm -rf dist/ build/ *.egg-info
# Build the package
python -m build
```
This creates:
- `dist/aisbf-0.1.0.tar.gz` - Source distribution
- `dist/aisbf-0.1.0-py3-none-any.whl` - Wheel distribution
## Testing the Package
### Local Testing
```bash
# Install from the built wheel
pip install dist/aisbf-0.1.0-py3-none-any.whl
# Test the installation
aisbf status
```
### TestPyPI Testing
Before publishing to PyPI, test on TestPyPI:
```bash
# Upload to TestPyPI
python -m twine upload --repository testpypi dist/*
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ aisbf
# Test the installation
aisbf status
```
## Publishing to PyPI
Once tested successfully:
```bash
# Upload to PyPI
python -m twine upload dist/*
```
## Version Management
Before each release:
1. **Update version** in `setup.py` and `pyproject.toml`
2. **Update CHANGELOG.md** with release notes
3. **Update README.md** if needed
4. **Commit changes** to git
5. **Tag the release**:
```bash
git tag -a v0.1.0 -m "Release version 0.1.0"
git push origin v0.1.0
```
## Package Structure
The package includes:
- **Python Module**: `aisbf/` directory with all Python code
- **Configuration Files**: `config/` directory with JSON configs
- **Main Application**: `main.py` - FastAPI application
- **Documentation**: `README.md`, `DOCUMENTATION.md`
- **License**: `LICENSE.txt` (GPL-3.0-or-later)
- **Requirements**: `requirements.txt`
## Custom Installation Behavior
The AISBF package includes a custom install command that:
1. **Creates a virtual environment** at:
- User: `~/.local/aisbf-venv/`
- System: `/usr/local/aisbf-venv/`
2. **Installs configuration files** to:
- User: `~/.local/share/aisbf/`
- System: `/usr/local/share/aisbf/`
3. **Installs main.py** to:
- User: `~/.local/share/aisbf/main.py`
- System: `/usr/local/share/aisbf/main.py`
4. **Creates the aisbf script** at:
- User: `~/.local/bin/aisbf`
- System: `/usr/local/bin/aisbf`
## Installation from PyPI
Users can install AISBF with:
```bash
# User installation (recommended)
pip install aisbf
# System-wide installation (requires root)
sudo pip install aisbf
```
## Troubleshooting
### Build Errors
If you encounter build errors:
```bash
# Ensure all dependencies are installed
pip install --upgrade setuptools wheel build twine
# Clean and rebuild
rm -rf dist/ build/ *.egg-info
python -m build
```
### Upload Errors
If upload fails:
```bash
# Check package contents
twine check dist/*
# Verify credentials
python -m twine upload --repository testpypi dist/* --verbose
```
### Installation Issues
If users report installation issues:
1. Check Python version (requires >= 3.8)
2. Verify all dependencies are available
3. Check system permissions for installation directories
## Security Considerations
- **API Tokens**: Never commit API tokens to version control
- **Sensitive Data**: The package doesn't include API keys or sensitive configuration
- **Dependencies**: All dependencies are listed in `requirements.txt`
## Post-Release Checklist
After publishing:
- [ ] Verify package appears on PyPI
- [ ] Test installation from PyPI
- [ ] Update documentation if needed
- [ ] Announce release to users
- [ ] Monitor for issues and feedback
## Additional Resources
- [PyPI Packaging Tutorial](https://packaging.python.org/tutorials/packaging-projects/)
- [Twine Documentation](https://twine.readthedocs.io/)
- [PyPI Upload Guide](https://pypi.org/help/#apitoken)
## Support
For issues related to packaging or publishing:
- Check the [PyPI documentation](https://pypi.org/help/)
- Review the [packaging guide](https://packaging.python.org/)
- Open an issue at: https://git.nexlab.net/nexlab/aisbf.git/issues
\ No newline at end of file
...@@ -13,6 +13,13 @@ Official repository: https://git.nexlab.net/nexlab/aisbf.git ...@@ -13,6 +13,13 @@ Official repository: https://git.nexlab.net/nexlab/aisbf.git
## Quick Start ## Quick Start
### Installation ### Installation
#### From PyPI (Recommended)
```bash
pip install aisbf
```
#### From Source
```bash ```bash
python setup.py install python setup.py install
``` ```
...@@ -24,6 +31,30 @@ aisbf ...@@ -24,6 +31,30 @@ aisbf
Server starts on `http://localhost:8000` Server starts on `http://localhost:8000`
## Development
### Building the Package
To build the package for PyPI distribution:
```bash
./build.sh
```
This creates distribution files in the `dist/` directory.
### Cleaning Build Artifacts
To remove all build artifacts and temporary files:
```bash
./clean.sh
```
### PyPI Publishing
See [`PYPI.md`](PYPI.md) for detailed instructions on publishing to PyPI.
## Supported Providers ## Supported Providers
- Google (google-genai) - Google (google-genai)
- OpenAI and openai-compatible endpoints (openai) - OpenAI and openai-compatible endpoints (openai)
......
#!/bin/bash
########################################################
# Copyright (C) 2026 Stefy Lanza <stefy@nexlab.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Why did the programmer quit his job? Because he didn't get arrays!
########################################################
# AISBF - AI Service Broker Framework || AI Should Be Free
# Build script for creating PyPI distribution packages
set -e
echo "=========================================="
echo "Building AISBF Package for PyPI"
echo "=========================================="
echo ""
# Check if build and twine are installed
if ! command -v python &> /dev/null; then
echo "Error: Python is not installed or not in PATH"
exit 1
fi
# Install build tools if not already installed
echo "Checking for build tools..."
if ! python -m build --version &> /dev/null; then
echo "Installing build and twine..."
pip install build twine
fi
# Clean previous builds
echo ""
echo "Cleaning previous build artifacts..."
rm -rf dist/ build/ *.egg-info
# Build the package
echo ""
echo "Building package..."
python -m build
# Verify the package
echo ""
echo "Verifying package..."
twine check dist/*
# Display results
echo ""
echo "=========================================="
echo "Build completed successfully!"
echo "=========================================="
echo ""
echo "Created files:"
ls -lh dist/
echo ""
echo "To upload to TestPyPI:"
echo " python -m twine upload --repository testpypi dist/*"
echo ""
echo "To upload to PyPI:"
echo " python -m twine upload dist/*"
echo ""
\ No newline at end of file
#!/bin/bash
########################################################
# Copyright (C) 2026 Stefy Lanza <stefy@nexlab.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Why did the programmer quit his job? Because he didn't get arrays!
########################################################
# AISBF - AI Service Broker Framework || AI Should Be Free
# Clean script for removing build artifacts and temporary files
set -e
echo "=========================================="
echo "Cleaning AISBF Build Artifacts"
echo "=========================================="
echo ""
# Remove distribution directory
if [ -d "dist" ]; then
echo "Removing dist/ directory..."
rm -rf dist/
echo " ✓ dist/ removed"
else
echo " - dist/ not found (skipping)"
fi
# Remove build directory
if [ -d "build" ]; then
echo "Removing build/ directory..."
rm -rf build/
echo " ✓ build/ removed"
else
echo " - build/ not found (skipping)"
fi
# Remove egg-info directories
if ls *.egg-info 1> /dev/null 2>&1; then
echo "Removing *.egg-info directories..."
rm -rf *.egg-info
echo " ✓ *.egg-info removed"
else
echo " - *.egg-info not found (skipping)"
fi
# Remove Python cache directories
if [ -d "__pycache__" ]; then
echo "Removing __pycache__/ directory..."
rm -rf __pycache__
echo " ✓ __pycache__/ removed"
else
echo " - __pycache__/ not found (skipping)"
fi
# Remove Python cache directories in subdirectories
if find . -type d -name "__pycache__" | grep -q .; then
echo "Removing __pycache__/ directories in subdirectories..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo " ✓ __pycache__/ in subdirectories removed"
else
echo " - __pycache__/ in subdirectories not found (skipping)"
fi
# Remove .pyc files
if find . -type f -name "*.pyc" | grep -q .; then
echo "Removing .pyc files..."
find . -type f -name "*.pyc" -delete
echo " ✓ .pyc files removed"
else
echo " - .pyc files not found (skipping)"
fi
# Remove .pyo files
if find . -type f -name "*.pyo" | grep -q .; then
echo "Removing .pyo files..."
find . -type f -name "*.pyo" -delete
echo " ✓ .pyo files removed"
else
echo " - .pyo files not found (skipping)"
fi
# Remove .pyd files
if find . -type f -name "*.pyd" | grep -q .; then
echo "Removing .pyd files..."
find . -type f -name "*.pyd" -delete
echo " ✓ .pyd files removed"
else
echo " - .pyd files not found (skipping)"
fi
# Remove .pytest_cache directory
if [ -d ".pytest_cache" ]; then
echo "Removing .pytest_cache/ directory..."
rm -rf .pytest_cache
echo " ✓ .pytest_cache/ removed"
else
echo " - .pytest_cache/ not found (skipping)"
fi
# Remove .mypy_cache directory
if [ -d ".mypy_cache" ]; then
echo "Removing .mypy_cache/ directory..."
rm -rf .mypy_cache
echo " ✓ .mypy_cache/ removed"
else
echo " - .mypy_cache/ not found (skipping)"
fi
# Remove .coverage files
if [ -f ".coverage" ]; then
echo "Removing .coverage file..."
rm -f .coverage
echo " ✓ .coverage removed"
else
echo " - .coverage not found (skipping)"
fi
# Remove htmlcov directory
if [ -d "htmlcov" ]; then
echo "Removing htmlcov/ directory..."
rm -rf htmlcov
echo " ✓ htmlcov/ removed"
else
echo " - htmlcov/ not found (skipping)"
fi
echo ""
echo "=========================================="
echo "Clean completed successfully!"
echo "=========================================="
echo ""
echo "All build artifacts and temporary files have been removed."
echo ""
\ No newline at end of file
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "aisbf"
version = "0.1.0"
description = "AISBF - AI Service Broker Framework || AI Should Be Free - A modular proxy server for managing multiple AI provider integrations"
readme = "README.md"
license = {text = "GPL-3.0-or-later"}
requires-python = ">=3.8"
authors = [
{name = "AISBF Contributors"},
]
maintainers = [
{name = "Stefy Lanza", email = "stefy@nexlab.net"},
]
keywords = [
"ai",
"proxy",
"api",
"openai",
"anthropic",
"google",
"ollama",
"llm",
"chat",
"broker",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
]
[project.urls]
Homepage = "https://git.nexlab.net/nexlab/aisbf.git"
Repository = "https://git.nexlab.net/nexlab/aisbf.git"
Documentation = "https://git.nexlab.net/nexlab/aisbf.git"
"Bug Tracker" = "https://git.nexlab.net/nexlab/aisbf.git/issues"
[tool.setuptools]
packages = ["aisbf"]
[tool.setuptools.package-data]
aisbf = ["*.json"]
\ No newline at end of file
...@@ -56,6 +56,9 @@ class InstallCommand(_install): ...@@ -56,6 +56,9 @@ class InstallCommand(_install):
# Install config files # Install config files
self._install_config_files() self._install_config_files()
# Install main.py to share directory
self._install_main_file()
# Create venv and install requirements # Create venv and install requirements
self._create_venv_and_install_requirements() self._create_venv_and_install_requirements()
...@@ -114,6 +117,28 @@ class InstallCommand(_install): ...@@ -114,6 +117,28 @@ class InstallCommand(_install):
else: else:
print(f"Warning: Config directory {config_dir} not found") print(f"Warning: Config directory {config_dir} not found")
def _install_main_file(self):
"""Install main.py to the appropriate share directory"""
# Determine the share directory
if '--user' in sys.argv or os.geteuid() != 0:
# User installation - use ~/.local/share
share_dir = Path.home() / '.local' / 'share' / 'aisbf'
else:
# System installation - use /usr/local/share
share_dir = Path('/usr/local/share/aisbf')
# Create the share directory if it doesn't exist
share_dir.mkdir(parents=True, exist_ok=True)
# Copy main.py
main_file = this_directory / 'main.py'
if main_file.exists():
dst = share_dir / 'main.py'
shutil.copy2(main_file, dst)
print(f"Installed main.py to {dst}")
else:
print(f"Warning: main.py not found")
def _install_aisbf_script(self): def _install_aisbf_script(self):
"""Install the aisbf script that uses the venv""" """Install the aisbf script that uses the venv"""
# Determine the installation directory # Determine the installation directory
...@@ -121,27 +146,33 @@ class InstallCommand(_install): ...@@ -121,27 +146,33 @@ class InstallCommand(_install):
# User installation - use ~/.local/bin # User installation - use ~/.local/bin
bin_dir = Path.home() / '.local' / 'bin' bin_dir = Path.home() / '.local' / 'bin'
venv_dir = Path.home() / '.local' / 'aisbf-venv' venv_dir = Path.home() / '.local' / 'aisbf-venv'
share_dir = Path.home() / '.local' / 'share' / 'aisbf'
else: else:
# System installation - use /usr/local/bin # System installation - use /usr/local/bin
bin_dir = Path('/usr/local/bin') bin_dir = Path('/usr/local/bin')
venv_dir = Path('/usr/local') / 'aisbf-venv' venv_dir = Path('/usr/local') / 'aisbf-venv'
share_dir = Path('/usr/local/share/aisbf')
# Create the bin directory if it doesn't exist # Create the bin directory if it doesn't exist
bin_dir.mkdir(parents=True, exist_ok=True) bin_dir.mkdir(parents=True, exist_ok=True)
# Create the aisbf script that uses the venv # Create the aisbf script that uses the venv
script_content = f"""#!/bin/bash script_content = f"""#!/bin/bash
# AISBF - AI Service Broker Framework || AI Should Be Free # AISBF - AI Service Broker Framework || AI Should Be Free
# This script manages the AISBF server using the installed virtual environment # This script manages the AISBF server using the installed virtual environment
PIDFILE="/tmp/aisbf.pid" PIDFILE="/tmp/aisbf.pid"
VENV_DIR="{venv_dir}" VENV_DIR="{venv_dir}"
SHARE_DIR="{share_dir}"
# Function to start the server # Function to start the server
start_server() {{ start_server() {{
# Activate the virtual environment # Activate the virtual environment
source $VENV_DIR/bin/activate source $VENV_DIR/bin/activate
# Change to share directory where main.py is located
cd $SHARE_DIR
# Start the proxy server # Start the proxy server
uvicorn main:app --host 0.0.0.0 --port 8000 uvicorn main:app --host 0.0.0.0 --port 8000
}} }}
...@@ -161,7 +192,7 @@ start_daemon() {{ ...@@ -161,7 +192,7 @@ start_daemon() {{
fi fi
# Start in background with nohup # Start in background with nohup
nohup bash -c "source $VENV_DIR/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8000" > /dev/null 2>&1 & nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host 0.0.0.0 --port 8000" > /dev/null 2>&1 &
PID=$! PID=$!
echo $PID > "$PIDFILE" echo $PID > "$PIDFILE"
echo "AISBF started in background (PID: $PID)" echo "AISBF started in background (PID: $PID)"
...@@ -232,23 +263,24 @@ setup( ...@@ -232,23 +263,24 @@ setup(
name="aisbf", name="aisbf",
version="0.1.0", version="0.1.0",
author="AISBF Contributors", author="AISBF Contributors",
author_email="", author_email="stefy@nexlab.net",
description="AISBF - AI Service Broker Framework || AI Should Be Free - A modular proxy server for managing multiple AI provider integrations", description="AISBF - AI Service Broker Framework || AI Should Be Free - A modular proxy server for managing multiple AI provider integrations",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
url="https://github.com/yourusername/aisbf", url="https://git.nexlab.net/nexlab/aisbf.git",
packages=find_packages(), packages=find_packages(),
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
], ],
python_requires=">=3.8", python_requires=">=3.8",
install_requires=requirements, install_requires=requirements,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment