Skip to main content

A demo PyPI package with Rust extensions

Project description

demopy_gb_jj

A minimal Rust-based Python extension using PyO3 bindings with automated CI/CD pipeline.

CI PyPI version Python versions

Features

  • Rust-Python Integration: High-performance Rust functions exposed to Python via PyO3
  • Fallback Support: Pure Python implementations when Rust extension is unavailable
  • Automated CI/CD: GitHub Actions workflows for testing, building, and publishing
  • Version Management: Automated version bumping across all project files
  • Cross-Platform: Supports Windows, macOS, and Linux
  • Multiple Python Versions: Compatible with Python 3.8-3.13

Installation

From PyPI (Recommended)

pip install demopy_gb_jj
```text

### From Source

```bash
# Clone the repository
git clone https://github.com/jj-devhub/demopy.git
cd demopy

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install Python dependencies
pip install maturin

# Build and install the package
maturin develop
```text

## Usage

```python
import demopy

# Basic functions
print(demopy.hello())  # "Hello from demopy_gb_jj (Rust edition)!"
print(demopy.add(2, 3))  # 5
print(demopy.multiply(2.5, 4.0))  # 10.0

# List operations
numbers = [1, 2, 3, 4, 5]
print(demopy.sum_list(numbers))  # 15

# String operations
print(demopy.reverse_string("Hello, World!"))  # "!dlroW ,olleH"

# Version info
print(demopy.__version__)  # Current version
```text

## Development

### Prerequisites

- Python 3.8 or higher (tested up to 3.13)
- Rust 1.70 or higher
- Git

### Setup Development Environment

```bash
# Clone the repository
git clone https://github.com/jj-devhub/demopy.git
cd demopy

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install maturin pytest

# Set up pre-commit hooks for code quality (recommended)
python scripts/setup_pre_commit.py

# Build the extension in development mode
maturin develop

# Run tests
pytest tests/ -v
cargo test
```text

### Code Quality

This project uses automated code quality enforcement through pre-commit hooks:

```bash
# Set up pre-commit hooks (one-time setup)
python scripts/setup_pre_commit.py

# Hooks run automatically on git commit
git commit -m "your changes"  # Hooks auto-format and check code
```text

**Available quality tools:**

- **Black**: Python code formatting (88-char line length)
- **isort**: Import statement sorting
- **flake8**: Python linting and PEP 8 compliance
- **mypy**: Static type checking (optional)
- **cargo fmt**: Rust code formatting
- **cargo clippy**: Rust linting

See [docs/PRE_COMMIT_HOOKS.md](docs/PRE_COMMIT_HOOKS.md) for detailed information.

### Project Structure

```text
demopy/
├── .github/workflows/     # GitHub Actions CI/CD
├── docs/                  # Documentation
├── python/demopy/         # Python package source
├── src/                   # Rust source code
├── tests/                 # Test files
├── scripts/               # Utility scripts
├── .pre-commit-config.yaml # Pre-commit hooks configuration
├── Cargo.toml            # Rust package configuration
├── pyproject.toml        # Python package configuration
└── README.md
```text

### Version Management

This project uses automated version management. To bump the version:

#### Using GitHub Actions (Recommended)

1. Go to the "Actions" tab in your GitHub repository
2. Select "Version Bump" workflow
3. Click "Run workflow"
4. Choose the bump type (patch/minor/major) or specify a custom version
5. The workflow will automatically:
   - Update version numbers in all files
   - Create a commit and tag
   - Trigger the release workflow
   - Publish to PyPI

#### Manual Version Bumping

```bash
# Bump patch version (0.2.5 -> 0.2.6)
python scripts/bump_version.py patch

# Bump minor version (0.2.5 -> 0.3.0)
python scripts/bump_version.py minor

# Bump major version (0.2.5 -> 1.0.0)
python scripts/bump_version.py major

# Set specific version
python scripts/bump_version.py 1.2.3
```text

### Testing

```bash
# Run Python tests
pytest tests/ -v

# Run Rust tests
cargo test

# Run linting
cargo fmt --all -- --check
cargo clippy -- -D warnings

# Test pure Python fallback
python -c "
import sys
sys.path.insert(0, 'python')
import builtins
original_import = builtins.__import__
def mock_import(name, *args, **kwargs):
    if 'demopy_gb_jj._rust' in name:
        raise ImportError('Mocked')
    return original_import(name, *args, **kwargs)
builtins.__import__ = mock_import
import demopy
print(demopy.hello())
"
```text

### Building and Publishing

The project uses GitHub Actions for automated building and publishing:

1. **Continuous Integration**: Runs on every push and pull request
   - Tests across multiple OS and Python versions
   - Builds the Rust extension
   - Runs both Rust and Python tests

2. **Release Workflow**: Triggers on version tags
   - Builds wheels for all platforms
   - Creates source distribution
   - Publishes to PyPI
   - Creates GitHub release with changelog

3. **Version Bump Workflow**: Manual trigger for version management
   - Updates version across all files
   - Creates commit and tag
   - Triggers release workflow

### Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for new functionality
5. Run the test suite (`pytest tests/ && cargo test`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

## Architecture

### Rust Extension

The Rust code in `src/lib.rs` implements high-performance functions using PyO3:

- **hello()**: Returns a greeting message
- **add(a, b)**: Adds two integers
- **multiply(a, b)**: Multiplies two floats
- **sum_list(numbers)**: Sums a list of integers
- **reverse_string(s)**: Reverses a string

### Python Wrapper

The Python module in `python/demopy/__init__.py` provides:

- Import handling with fallback to pure Python
- Consistent API regardless of backend
- Version information
- Proper error handling

### Fallback Mechanism

If the Rust extension fails to load, the package automatically falls back to
pure Python implementations, ensuring the package works even in environments
where the Rust extension cannot be built or loaded.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE)
file for details.

## Changelog

See [Releases](https://github.com/jj-devhub/demopy/releases) for a detailed changelog.

A demo PyPI package for CI/CD publishing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

demopy_gb_jj-0.6.1.tar.gz (60.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl (99.7 kB view details)

Uploaded CPython 3.13Windows x86-64

demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl (198.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl (99.7 kB view details)

Uploaded CPython 3.12Windows x86-64

demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl (227.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl (198.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl (100.2 kB view details)

Uploaded CPython 3.11Windows x86-64

demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl (227.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (199.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl (100.2 kB view details)

Uploaded CPython 3.10Windows x86-64

demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl (100.4 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file demopy_gb_jj-0.6.1.tar.gz.

File metadata

  • Download URL: demopy_gb_jj-0.6.1.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for demopy_gb_jj-0.6.1.tar.gz
Algorithm Hash digest
SHA256 65178a8e9b3b21a4de27d502fe7a2f250edab99cad4e1ddac4964f36df21ded9
MD5 984542305e841f4f776dc3e8f3d20736
BLAKE2b-256 7198d725d07c36750fb0905364dd78f86ff43c47aa353907feddc31ea84fc238

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8337495bd638079f77c95631ab49b1e3257e878251b5312fdf3c59f1bb24ab82
MD5 8c9129646ca1f2b71c1f1d51a223402e
BLAKE2b-256 e9ab2d1848f5123fb8cb2a45453367edcf064ef1050f85b0bedc8004fe58c84b

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ccaeb45b6f8f5dc69b9b88ded8077baf05cd213aacf0557ddf53b2ef3d36ad6
MD5 d1d634722ce479684fe5453a84bc5052
BLAKE2b-256 730051f0bd5799baa2e8c461befcd9ed5aa0c30f80dc01b97bcdf703bdac64eb

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2c201c262590e1c364d9dac98e0939b8d2bdd66eb8c665a2876dcef4e04ce2f0
MD5 92e86ccd716f8cddb3dbfed69b00981c
BLAKE2b-256 354b176e6fa78c86200465a3cc8b1726038aa635410dc55d2df2ad3a6f7ced78

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 72ff236bcac1ac1ba89ad1042b746695562d02d4991cb251a008a780497a2326
MD5 e30ef302fac3e3be04afa634f121376c
BLAKE2b-256 81a32f01f97d069c44135017796df9620084864f23c139b3889cfcc38cb65ede

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fe1d7167e29f96c77ebf7fd45f05b4d04cde09e20e0071bc81ceb8ff46a92a1
MD5 5259cae3da967c3f0992690434240661
BLAKE2b-256 0d8391e6f77fdfc521da441535cdb3c5dfbdd57a8b63e8938b636e91a978795c

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b930aab887a2f6abbffa84c8e1a7010edf82283550ee1d139df4a26f27c7b512
MD5 ee3a12c7adea8113ae8547c580759363
BLAKE2b-256 cade005e0466bafd740d326bdff5a2609afadbe6e6430c627e928fbd04ba1698

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9bbc1f7b4eeb1c5ceed91d5316f81a9ff7130f01c35de893c93017b1f9030262
MD5 24608b52faffb020039705f4c1761884
BLAKE2b-256 f94bb0c79a70f7471a340386ae28ffd865d63d94c5102477c1012168c0398652

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 811aeb75de0e15acc9b7de2c4a7e310aed06d702d8578ee10002f2d2b63c237f
MD5 ae52dee1616ce88c092a60f95f6a98bf
BLAKE2b-256 0b45b43fb6fd89a213f49b344c4f0954d2bd5b8f8332ec291577335d1086765a

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3f14c0c8140cd30ac90163d148c32981b5c232f2fd79c581da5005daf17ad37b
MD5 6fada746cfb7deb882d2072707a38919
BLAKE2b-256 03745245123f169cc845a8574fae3cd1e622f8c087249a366b29d3d9cd22e42c

See more details on using hashes here.

File details

Details for the file demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 100.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d9dd36edbd89309480cba993fded837149ca50ed948a7afec3a8c290e8c3a2af
MD5 524192b8205a305678793287099cd7a9
BLAKE2b-256 6dc34dbca4ba9dbe4d8038aebd4cc8ccd36fd5a8d7d1832bcbefda48161eb8bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page