Skip to content

Commit 09ec747

Browse files
committed
Add PyPI publishing infrastructure
- Enhanced setup.py with proper metadata and project URLs - Added pyproject.toml for modern Python packaging - Created GitHub Actions workflow for automated PyPI publishing - Added LICENSE file (MIT) - Added MANIFEST.in for package file inclusion - Created build and test script for local development - Added comprehensive PUBLISHING.md guide Ready for PyPI publication via GitHub releases.
1 parent 002d5a9 commit 09ec747

7 files changed

Lines changed: 444 additions & 1 deletion

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch: # Allow manual triggering
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.9'
19+
20+
- name: Install build dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install build twine
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Check package
29+
run: twine check dist/*
30+
31+
- name: Publish to Test PyPI
32+
if: github.event_name == 'workflow_dispatch'
33+
env:
34+
TWINE_USERNAME: __token__
35+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
36+
run: |
37+
twine upload --repository testpypi dist/*
38+
39+
- name: Publish to PyPI
40+
if: github.event_name == 'release'
41+
env:
42+
TWINE_USERNAME: __token__
43+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
44+
run: |
45+
twine upload dist/*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 EdgeX Tech
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include README.md
2+
include LICENSE
3+
include requirements.txt
4+
include requirements-dev.txt
5+
recursive-exclude tests *
6+
recursive-exclude examples *
7+
recursive-exclude .github *
8+
recursive-exclude venv *
9+
global-exclude *.pyc
10+
global-exclude __pycache__
11+
global-exclude .DS_Store

PUBLISHING.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Publishing EdgeX Python SDK to PyPI
2+
3+
This guide explains how to publish the EdgeX Python SDK to PyPI without using personal accounts.
4+
5+
## Prerequisites
6+
7+
### 1. Create Organization PyPI Account
8+
9+
1. Go to [PyPI Registration](https://pypi.org/account/register/)
10+
2. Create an account using the organization email (e.g., `info@edgex.exchange`)
11+
3. Verify the email address
12+
4. Enable 2FA for security
13+
14+
### 2. Create API Tokens
15+
16+
For security, use API tokens instead of passwords:
17+
18+
1. Log into the organization PyPI account
19+
2. Go to Account Settings → API tokens
20+
3. Create a new API token:
21+
- **Name**: `edgex-python-sdk-upload`
22+
- **Scope**: Limit to specific project (after first upload)
23+
4. Copy and securely store the token (starts with `pypi-`)
24+
25+
### 3. Set up GitHub Secrets
26+
27+
Add the following secrets to your GitHub repository:
28+
29+
1. Go to GitHub repository → Settings → Secrets and variables → Actions
30+
2. Add these secrets:
31+
- `PYPI_API_TOKEN`: Your PyPI API token
32+
- `TEST_PYPI_API_TOKEN`: Your Test PyPI API token (optional, for testing)
33+
34+
## Publishing Methods
35+
36+
### Method 1: Automated Publishing via GitHub Actions (Recommended)
37+
38+
This method automatically publishes when you create a GitHub release:
39+
40+
1. **Create a release**:
41+
```bash
42+
git tag v0.1.0
43+
git push origin v0.1.0
44+
```
45+
46+
2. **Create GitHub release**:
47+
- Go to GitHub → Releases → Create a new release
48+
- Choose the tag you just created
49+
- Add release notes
50+
- Publish the release
51+
52+
3. **GitHub Actions will automatically**:
53+
- Build the package
54+
- Run quality checks
55+
- Upload to PyPI
56+
57+
### Method 2: Manual Publishing
58+
59+
If you prefer manual control:
60+
61+
1. **Install build tools**:
62+
```bash
63+
pip install build twine
64+
```
65+
66+
2. **Build the package**:
67+
```bash
68+
python scripts/build_and_test_package.py
69+
```
70+
71+
3. **Upload to Test PyPI first** (recommended):
72+
```bash
73+
twine upload --repository testpypi dist/*
74+
```
75+
76+
4. **Test installation from Test PyPI**:
77+
```bash
78+
pip install --index-url https://test.pypi.org/simple/ edgex-python-sdk
79+
```
80+
81+
5. **Upload to PyPI**:
82+
```bash
83+
twine upload dist/*
84+
```
85+
86+
## Testing Before Publishing
87+
88+
### Local Testing
89+
90+
1. **Build and test locally**:
91+
```bash
92+
python scripts/build_and_test_package.py
93+
```
94+
95+
2. **Install locally**:
96+
```bash
97+
pip install dist/edgex_python_sdk-*.whl
98+
```
99+
100+
3. **Test basic functionality**:
101+
```python
102+
import edgex_sdk
103+
print(edgex_sdk.__version__)
104+
```
105+
106+
### Test PyPI
107+
108+
Always test on Test PyPI before publishing to the main PyPI:
109+
110+
1. **Upload to Test PyPI**:
111+
```bash
112+
twine upload --repository testpypi dist/*
113+
```
114+
115+
2. **Install from Test PyPI**:
116+
```bash
117+
pip install --index-url https://test.pypi.org/simple/ edgex-python-sdk
118+
```
119+
120+
## Version Management
121+
122+
Update version numbers in these files before publishing:
123+
124+
1. `setup.py` - line with `version="x.x.x"`
125+
2. `pyproject.toml` - line with `version = "x.x.x"`
126+
3. `edgex_sdk/__init__.py` - add `__version__ = "x.x.x"`
127+
128+
## Security Best Practices
129+
130+
1. **Use API tokens**, not passwords
131+
2. **Enable 2FA** on PyPI account
132+
3. **Limit token scope** to specific projects
133+
4. **Store tokens securely** in GitHub Secrets
134+
5. **Rotate tokens regularly**
135+
6. **Never commit tokens** to version control
136+
137+
## Troubleshooting
138+
139+
### Common Issues
140+
141+
1. **Package name already exists**:
142+
- Choose a different name in `setup.py` and `pyproject.toml`
143+
144+
2. **Version already exists**:
145+
- Increment version number
146+
- You cannot overwrite existing versions on PyPI
147+
148+
3. **Authentication failed**:
149+
- Check API token is correct
150+
- Ensure token has proper permissions
151+
152+
4. **Build fails**:
153+
- Run `python scripts/build_and_test_package.py` locally
154+
- Check for missing dependencies or syntax errors
155+
156+
### Getting Help
157+
158+
- PyPI Help: https://pypi.org/help/
159+
- Packaging Guide: https://packaging.python.org/
160+
- GitHub Actions: https://docs.github.com/en/actions
161+
162+
## Post-Publishing
163+
164+
After successful publishing:
165+
166+
1. **Test installation**:
167+
```bash
168+
pip install edgex-python-sdk
169+
```
170+
171+
2. **Update documentation** if needed
172+
173+
3. **Announce the release** to users
174+
175+
4. **Monitor for issues** and user feedback

pyproject.toml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "edgex-python-sdk"
7+
version = "0.1.0"
8+
description = "A Python SDK for interacting with the EdgeX Exchange API"
9+
readme = "README.md"
10+
license = {text = "MIT"}
11+
authors = [
12+
{name = "EdgeX Tech", email = "info@edgex.exchange"}
13+
]
14+
maintainers = [
15+
{name = "EdgeX Tech", email = "info@edgex.exchange"}
16+
]
17+
keywords = ["edgex", "exchange", "trading", "api", "sdk", "cryptocurrency"]
18+
classifiers = [
19+
"Development Status :: 3 - Alpha",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: MIT License",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.7",
24+
"Programming Language :: Python :: 3.8",
25+
"Programming Language :: Python :: 3.9",
26+
"Programming Language :: Python :: 3.10",
27+
"Programming Language :: Python :: 3.11",
28+
"Topic :: Software Development :: Libraries :: Python Modules",
29+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
30+
"Topic :: Office/Business :: Financial",
31+
]
32+
requires-python = ">=3.7"
33+
dependencies = [
34+
"aiohttp>=3.8.0",
35+
"websocket-client>=1.0.0",
36+
"pydantic>=1.8.0",
37+
"python-dotenv>=0.15.0",
38+
"pycryptodome>=3.15.0",
39+
"ecdsa>=0.17.0",
40+
]
41+
42+
[project.optional-dependencies]
43+
dev = [
44+
"pytest>=6.0",
45+
"pytest-asyncio>=0.18.0",
46+
"black>=21.0.0",
47+
"flake8>=3.8.0",
48+
"mypy>=0.800",
49+
]
50+
51+
[project.urls]
52+
Homepage = "https://github.com/edgex-Tech/edgex-python-sdk"
53+
Repository = "https://github.com/edgex-Tech/edgex-python-sdk"
54+
Documentation = "https://github.com/edgex-Tech/edgex-python-sdk#readme"
55+
"Bug Reports" = "https://github.com/edgex-Tech/edgex-python-sdk/issues"
56+
57+
[tool.setuptools.packages.find]
58+
exclude = ["tests*", "examples*"]
59+
60+
[tool.black]
61+
line-length = 88
62+
target-version = ['py37']
63+
include = '\.pyi?$'
64+
extend-exclude = '''
65+
/(
66+
# directories
67+
\.eggs
68+
| \.git
69+
| \.hg
70+
| \.mypy_cache
71+
| \.tox
72+
| \.venv
73+
| build
74+
| dist
75+
)/
76+
'''
77+
78+
[tool.mypy]
79+
python_version = "3.7"
80+
warn_return_any = true
81+
warn_unused_configs = true
82+
disallow_untyped_defs = true

0 commit comments

Comments
 (0)