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
149 changes: 149 additions & 0 deletions docs/guides/publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Publishing torchlogix to PyPI

This guide explains how to publish the torchlogix package to PyPI so it can be installed via `pip install torchlogix`.

## Prerequisites

1. **PyPI Account**: Create an account at [https://pypi.org](https://pypi.org)
2. **TestPyPI Account** (optional but recommended): Create an account at [https://test.pypi.org](https://test.pypi.org)
3. **API Token**: Generate an API token from your PyPI account settings

## Step 1: Install Build Tools

```bash
pip install --upgrade pip build twine
```

## Step 2: Clean Previous Builds

```bash
rm -rf build dist *.egg-info src/*.egg-info
```

## Step 3: Build the Package

```bash
python -m build
```

This will create two files in the `dist/` directory:
- `torchlogix-0.1.0.tar.gz` (source distribution)
- `torchlogix-0.1.0-py3-none-any.whl` (wheel distribution)

## Step 4: Validate the Build

```bash
python -m twine check dist/*
```

You should see:
```
Checking dist/torchlogix-0.1.0-py3-none-any.whl: PASSED
Checking dist/torchlogix-0.1.0.tar.gz: PASSED
```

## Step 5: Test on TestPyPI (Recommended)

Before publishing to the real PyPI, test on TestPyPI:

```bash
python -m twine upload --repository testpypi dist/*
```

You'll be prompted for your username (use `__token__`) and your TestPyPI API token.

Then test installing from TestPyPI:
```bash
pip install --index-url https://test.pypi.org/simple/ --no-deps torchlogix
```

## Step 6: Publish to PyPI

Once you've verified everything works on TestPyPI:

```bash
python -m twine upload dist/*
```

You'll be prompted for your username (use `__token__`) and your PyPI API token.

## Step 7: Verify Installation

After publishing, verify that the package can be installed:

```bash
pip install torchlogix
```

## Using API Tokens (Recommended)

Instead of entering credentials each time, you can create a `.pypirc` file in your home directory:

```ini
[distutils]
index-servers =
pypi
testpypi

[pypi]
username = __token__
password = pypi-your-api-token-here

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-your-test-api-token-here
```

**Important**: Never commit `.pypirc` to version control!

## Updating the Package

When you want to release a new version:

1. Update the version number in:
- `setup.py` (line 13)
- `pyproject.toml` (line 7)

2. Update `CHANGELOG.md` with the changes

3. Commit the changes:
```bash
git add setup.py pyproject.toml CHANGELOG.md
git commit -m "Bump version to X.Y.Z"
git tag vX.Y.Z
git push && git push --tags
```

4. Clean, rebuild, and republish:
```bash
rm -rf build dist *.egg-info src/*.egg-info
python -m build
python -m twine check dist/*
python -m twine upload dist/*
```

## Versioning

This package follows [Semantic Versioning](https://semver.org/):
- MAJOR version (X.0.0): Incompatible API changes
- MINOR version (0.X.0): Add functionality (backwards-compatible)
- PATCH version (0.0.X): Bug fixes (backwards-compatible)

## Troubleshooting

### "File already exists" error

If you get this error, it means you're trying to upload a version that already exists on PyPI. You must increment the version number.

### Package not found after publishing

It may take a few minutes for the package to be indexed and available. Try again after a few minutes.

### Dependencies not installing

Make sure all dependencies are listed in both `setup.py` and `pyproject.toml` with compatible version constraints.

## GitHub Actions (Optional)

You can automate the publishing process using GitHub Actions. See `.github/workflows/publish.yml` for an example workflow.
76 changes: 76 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "torchlogix"
version = "0.1.0"
description = "Differentiable Logic Gate Networks in PyTorch"
readme = "README.md"
requires-python = ">=3.6"
license = {text = "MIT"}
authors = [
{name = "Lino Gerlach", email = "lino.oscar.gerlach@cern.ch"}
]
maintainers = [
{name = "Lino Gerlach", email = "lino.oscar.gerlach@cern.ch"}
]
keywords = ["deep-learning", "pytorch", "logic-gates", "neural-networks", "machine-learning"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]

dependencies = [
"torch>=1.6.0",
"numpy>=1.19.0",
"tqdm>=4.50.0",
"scikit-learn>=0.24.0",
"torchvision>=0.8.0",
"rich>=10.0.0",
]

[project.optional-dependencies]
dev = [
"flake8>=6.1.0",
"black>=23.12.1",
"isort>=5.13.2",
"pre-commit>=3.6.0",
"pytest>=8.0.0",
"autopep8>=2.0.4",
"sphinx>=4.0.0",
"sphinx-rtd-theme>=1.0.0",
]

[project.urls]
Homepage = "https://github.com/ligerlac/torchlogix"
Documentation = "https://ligerlac.github.io/torchlogix/"
Repository = "https://github.com/ligerlac/torchlogix"
"Bug Tracker" = "https://github.com/ligerlac/torchlogix/issues"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

[tool.black]
line-length = 88
target-version = ['py36']
Expand All @@ -16,3 +85,10 @@ force_grid_wrap = 0
use_parentheses = true
line_length = 88
skip = ['.git', 'build', 'dist', '*.egg-info']

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = "-v --strict-markers"
41 changes: 25 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@
long_description = fh.read()



ext_modules = []


setup(
name="torchlogix",
version="0.1.0",
author="Lino Gerlach",
author_email="lino.oscar.gerlach@cern.ch",
description="Differentiable Logic Gate Networks in PyTorch",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/ligerlac/torchlogix",
project_urls={
"Documentation": "https://ligerlac.github.io/torchlogix/",
"Source": "https://github.com/ligerlac/torchlogix",
"Bug Tracker": "https://github.com/ligerlac/torchlogix/issues",
},
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
Expand All @@ -33,32 +44,30 @@
],
package_dir={"": "src"},
packages=find_packages(where="src"),
ext_modules=ext_modules,
cmdclass={"build_ext": BuildExtension}
if ext_modules
else {}, # Only if building extensions
python_requires=">=3.6",
install_requires=[
"torch>=1.6.0",
"numpy>=1.26",
"tqdm",
"scikit-learn",
"torchvision",
"rich",
"torch-geometric",
"wheel",
"numpy>=1.19.0",
"tqdm>=4.50.0",
"scikit-learn>=0.24.0",
"torchvision>=0.8.0",
"rich>=10.0.0",
],
extras_require={
"dev": [
"flake8>=6.1.0",
"black>=23.12.1",
"black>=23.12.1",
"isort>=5.13.2",
"pre-commit>=3.6.0",
"pytest>=8.0.0",
"autopep8>=2.0.4",
"sphinx>=4.0.0",
"sphinx-rtd-theme>=1.0.0",
],
"cuda": [
# No additional dependencies needed, just triggers CUDA extension build
],
},
keywords="deep-learning pytorch logic-gates neural-networks machine-learning",
include_package_data=True,
)