# Publishing Guide for heapgeneratorq

This guide will walk you through the steps to publish your package to PyPI.

## Prerequisites

1. **Create PyPI Account**: Register at https://pypi.org/account/register/
2. **Create Test PyPI Account** (optional but recommended): Register at https://test.pypi.org/account/register/
3. **Install required tools**:
   ```bash
   pip install --upgrade pip setuptools wheel twine
   ```

## Before Publishing

1. **Update package information** in `setup.py` and `pyproject.toml`:
   - Replace `"Your Name"` with your actual name
   - Replace `"your.email@example.com"` with your email
   - Update the GitHub URL with your repository URL
   - Verify the version number

2. **Test locally**:
   ```bash
   cd c:\Users\devan\Downloads\py\heapgeneratorq
   pip install -e .
   ```

3. **Verify the package works**:
   ```python
   import heapgeneratorq
   print(heapgeneratorq.get_algorithms_file_path())
   ```

## Building the Package

1. **Clean previous builds** (if any):
   ```bash
   Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
   ```

2. **Build the distribution packages**:
   ```bash
   python setup.py sdist bdist_wheel
   ```

   This creates:
   - `dist/heapgeneratorq-0.1.0.tar.gz` (source distribution)
   - `dist/heapgeneratorq-0.1.0-py3-none-any.whl` (wheel distribution)

3. **Verify the build**:
   ```bash
   twine check dist/*
   ```

## Publishing to Test PyPI (Recommended First Step)

1. **Upload to Test PyPI**:
   ```bash
   twine upload --repository testpypi dist/*
   ```

   You'll be prompted for your Test PyPI username and password.

2. **Test installation from Test PyPI**:
   ```bash
   pip install --index-url https://test.pypi.org/simple/ heapgeneratorq
   ```

3. **Verify it works**:
   ```python
   import heapgeneratorq
   heapgeneratorq.copy_algorithms_file()
   ```

## Publishing to PyPI (Production)

1. **Upload to PyPI**:
   ```bash
   twine upload dist/*
   ```

   You'll be prompted for your PyPI username and password.

2. **Verify on PyPI**: Visit https://pypi.org/project/heapgeneratorq/

3. **Install from PyPI**:
   ```bash
   pip install heapgeneratorq
   ```

## Using API Tokens (Recommended)

Instead of using username/password, use API tokens:

1. **Generate token on PyPI**:
   - Go to https://pypi.org/manage/account/token/
   - Create a new API token
   - Copy the token (starts with `pypi-`)

2. **Create `.pypirc` file** in your home directory (`C:\Users\devan\.pypirc`):
   ```ini
   [distutils]
   index-servers =
       pypi
       testpypi

   [pypi]
   username = __token__
   password = pypi-YourActualTokenHere

   [testpypi]
   username = __token__
   password = pypi-YourTestPyPITokenHere
   ```

3. **Upload without prompt**:
   ```bash
   twine upload dist/*
   ```

## Updating the Package

When you want to release a new version:

1. **Update version number** in:
   - `setup.py`
   - `pyproject.toml`
   - `heapgeneratorq/__init__.py`

2. **Update CHANGELOG** in `README.md`

3. **Clean and rebuild**:
   ```bash
   Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
   python setup.py sdist bdist_wheel
   twine check dist/*
   ```

4. **Upload new version**:
   ```bash
   twine upload dist/*
   ```

## Common Issues

### Package name already taken
- Choose a different name in `setup.py` and `pyproject.toml`
- Check availability: https://pypi.org/project/YOUR-PACKAGE-NAME/

### Version already exists
- Increment the version number
- You cannot reupload the same version

### Import errors after installation
- Ensure `__init__.py` is present in the package directory
- Check that `l1.py` is included in `MANIFEST.in`

## GitHub Repository (Recommended)

1. **Create a repository** on GitHub
2. **Initialize git** in your package directory:
   ```bash
   cd c:\Users\devan\Downloads\py\heapgeneratorq
   git init
   git add .
   git commit -m "Initial commit"
   git branch -M main
   git remote add origin https://github.com/yourusername/heapgeneratorq.git
   git push -u origin main
   ```

3. **Update URLs** in `setup.py` and `pyproject.toml` with your actual GitHub URL

## Resources

- PyPI: https://pypi.org/
- Test PyPI: https://test.pypi.org/
- Python Packaging Guide: https://packaging.python.org/
- Twine Documentation: https://twine.readthedocs.io/
