
Guide to Publishing Neuroca to PyPI¶
This guide will walk you through publishing your Neuroca package to PyPI, both manually and using the GitHub Actions workflow.
Option 1: Using GitHub Actions (Recommended)¶
We've set up a GitHub Actions workflow that will automatically publish your package to PyPI when you create a new release. Here's how to use it:
Step 1: Set Up API Tokens¶
- Create a PyPI account if you don't have one already:
- Go to https://pypi.org/account/register/
-
Complete the registration process and verify your email
-
Create a TestPyPI account:
- Go to https://test.pypi.org/account/register/
-
Complete the registration process and verify your email
-
Create API tokens:
- Log in to PyPI and go to https://pypi.org/manage/account/#api-tokens
- Create a new token with the scope limited to your project
- Copy the token value (you won't be able to see it again)
- Repeat for TestPyPI at https://test.pypi.org/manage/account/#api-tokens
Step 2: Add Tokens to GitHub Secrets¶
- Go to your GitHub repository
- Navigate to "Settings" > "Secrets and variables" > "Actions"
- Click "New repository secret"
- Add two secrets:
- Name:
PYPI_API_TOKEN
, Value: your PyPI token - Name:
TEST_PYPI_API_TOKEN
, Value: your TestPyPI token
Step 3: Prepare Your Package¶
-
Update version numbers:
-
Make sure all your changes are committed and pushed to GitHub
Step 4: Create a GitHub Release¶
- Go to your GitHub repository
- Navigate to "Releases" (https://github.com/YOUR_USERNAME/Neuro-Cognitive-Architecture/releases)
- Click "Create a new release"
- Choose a tag (e.g.,
v0.1.0
- this should match your version number) - Add a title and description
- Click "Publish release"
The GitHub Action will automatically trigger and: - Build your package - Upload it to TestPyPI first - Then upload it to the main PyPI repository
Step 5: Verify Installation¶
Once the workflow completes successfully, verify that your package can be installed:
# Create a test environment
python -m venv test-env
source test-env/bin/activate # On Windows: test-env\Scripts\activate
# Install your package
pip install neuroca
# Test importing
python -c "import neuroca; print(neuroca.__version__)"
Option 2: Manual Publishing¶
If you prefer to publish manually or need to troubleshoot the process:
Step 1: Set Up Authentication¶
Create a ~/.pypirc
file with your API tokens:
[distutils]
index-servers =
pypi
testpypi
[pypi]
username = __token__
password = your-pypi-token
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = your-testpypi-token
Step 2: Build the Package¶
# Make sure you have the build package installed
pip install build
# Build the package
python -m build
This will create distribution files in the dist/
directory.
Step 3: Upload to TestPyPI First¶
# Install twine if you don't have it
pip install twine
# Upload to TestPyPI
twine upload --repository testpypi dist/*
Step 4: Test the TestPyPI Installation¶
# Create a test environment
python -m venv test-env
source test-env/bin/activate # On Windows: test-env\Scripts\activate
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ neuroca
# Test importing
python -c "import neuroca; print(neuroca.__version__)"
Step 5: Upload to PyPI¶
If everything looks good on TestPyPI, upload to the main PyPI repository:
Common Issues and Troubleshooting¶
-
Version conflicts: You cannot upload a package with the same version number twice. Always increment the version number for new uploads.
-
Missing metadata: Ensure your
pyproject.toml
has all required fields (name, version, description, etc.). -
README rendering issues: Make sure your README.md has valid Markdown syntax.
-
Package name already exists: Check if the package name is available on PyPI before trying to publish.
-
Dependency issues: Verify all dependencies are correctly specified in
pyproject.toml
.
Next Steps After Publishing¶
-
Update your documentation to include installation instructions:
-
Consider creating a GitHub tag for the version:
-
Announce the release in relevant channels (GitHub Discussions, mailing lists, etc.)