From 1cb89c6f584a1dd8df5cdc36c0a93ebba7ac2e48 Mon Sep 17 00:00:00 2001 From: Lino Gerlach Date: Sun, 16 Nov 2025 23:18:49 +0100 Subject: [PATCH 1/2] instructions for publishing --- PUBLISHING.md | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 79 ++++++++++++++++++++++++++ setup.py | 45 +++++++++------ 3 files changed, 255 insertions(+), 18 deletions(-) create mode 100644 PUBLISHING.md diff --git a/PUBLISHING.md b/PUBLISHING.md new file mode 100644 index 0000000..353d031 --- /dev/null +++ b/PUBLISHING.md @@ -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. diff --git a/pyproject.toml b/pyproject.toml index f96d8dc..9fc140d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,75 @@ +[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", +] +geometric = [ + "torch-geometric>=2.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'] @@ -16,3 +88,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" diff --git a/setup.py b/setup.py index 87f4fa6..4b517ff 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -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 + "geometric": [ + "torch-geometric>=2.0.0", ], }, + keywords="deep-learning pytorch logic-gates neural-networks machine-learning", + include_package_data=True, ) From 5fade555d40c27dec975e53ad4a03ce8985ecc1b Mon Sep 17 00:00:00 2001 From: Lino Gerlach Date: Sun, 16 Nov 2025 23:46:18 +0100 Subject: [PATCH 2/2] move publishing instructions to docs/ --- PUBLISHING.md => docs/guides/publishing.md | 0 pyproject.toml | 3 --- setup.py | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) rename PUBLISHING.md => docs/guides/publishing.md (100%) diff --git a/PUBLISHING.md b/docs/guides/publishing.md similarity index 100% rename from PUBLISHING.md rename to docs/guides/publishing.md diff --git a/pyproject.toml b/pyproject.toml index 9fc140d..e29a5a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,9 +54,6 @@ dev = [ "sphinx>=4.0.0", "sphinx-rtd-theme>=1.0.0", ] -geometric = [ - "torch-geometric>=2.0.0", -] [project.urls] Homepage = "https://github.com/ligerlac/torchlogix" diff --git a/setup.py b/setup.py index 4b517ff..1d80f67 100644 --- a/setup.py +++ b/setup.py @@ -64,8 +64,8 @@ "sphinx>=4.0.0", "sphinx-rtd-theme>=1.0.0", ], - "geometric": [ - "torch-geometric>=2.0.0", + "cuda": [ + # No additional dependencies needed, just triggers CUDA extension build ], }, keywords="deep-learning pytorch logic-gates neural-networks machine-learning",