Skip to main content

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.

Metadata

Release files for demopy-gb-jj 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for demopy-gb-jj 0.6.1
File Size Uploaded
demopy_gb_jj-0.6.1.tar.gz 60.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for demopy-gb-jj 0.6.1
File
demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details

Total release size: 1.6 MB

Release files / demopy_gb_jj-0.6.1.tar.gz

Download URL demopy_gb_jj-0.6.1.tar.gz
Size 60.5 kB
Tags Source
SHA-256 checksum
How to use checksums
65178a8e9b3b21a4de27d502fe7a2f250edab99cad4e1ddac4964f36df21ded9
BLAKE2b-256 checksum
How to use checksums
7198d725d07c36750fb0905364dd78f86ff43c47aa353907feddc31ea84fc238
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl

Download URL demopy_gb_jj-0.6.1-cp313-cp313-win_amd64.whl
Size 99.7 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
8337495bd638079f77c95631ab49b1e3257e878251b5312fdf3c59f1bb24ab82
BLAKE2b-256 checksum
How to use checksums
e9ab2d1848f5123fb8cb2a45453367edcf064ef1050f85b0bedc8004fe58c84b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL demopy_gb_jj-0.6.1-cp313-cp313-macosx_11_0_arm64.whl
Size 198.9 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8ccaeb45b6f8f5dc69b9b88ded8077baf05cd213aacf0557ddf53b2ef3d36ad6
BLAKE2b-256 checksum
How to use checksums
730051f0bd5799baa2e8c461befcd9ed5aa0c30f80dc01b97bcdf703bdac64eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl

Download URL demopy_gb_jj-0.6.1-cp312-cp312-win_amd64.whl
Size 99.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
2c201c262590e1c364d9dac98e0939b8d2bdd66eb8c665a2876dcef4e04ce2f0
BLAKE2b-256 checksum
How to use checksums
354b176e6fa78c86200465a3cc8b1726038aa635410dc55d2df2ad3a6f7ced78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL demopy_gb_jj-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 227.3 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
72ff236bcac1ac1ba89ad1042b746695562d02d4991cb251a008a780497a2326
BLAKE2b-256 checksum
How to use checksums
81a32f01f97d069c44135017796df9620084864f23c139b3889cfcc38cb65ede
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL demopy_gb_jj-0.6.1-cp312-cp312-macosx_11_0_arm64.whl
Size 198.8 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7fe1d7167e29f96c77ebf7fd45f05b4d04cde09e20e0071bc81ceb8ff46a92a1
BLAKE2b-256 checksum
How to use checksums
0d8391e6f77fdfc521da441535cdb3c5dfbdd57a8b63e8938b636e91a978795c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl

Download URL demopy_gb_jj-0.6.1-cp311-cp311-win_amd64.whl
Size 100.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
b930aab887a2f6abbffa84c8e1a7010edf82283550ee1d139df4a26f27c7b512
BLAKE2b-256 checksum
How to use checksums
cade005e0466bafd740d326bdff5a2609afadbe6e6430c627e928fbd04ba1698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL demopy_gb_jj-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl
Size 227.6 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
9bbc1f7b4eeb1c5ceed91d5316f81a9ff7130f01c35de893c93017b1f9030262
BLAKE2b-256 checksum
How to use checksums
f94bb0c79a70f7471a340386ae28ffd865d63d94c5102477c1012168c0398652
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL demopy_gb_jj-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Size 199.6 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
811aeb75de0e15acc9b7de2c4a7e310aed06d702d8578ee10002f2d2b63c237f
BLAKE2b-256 checksum
How to use checksums
0b45b43fb6fd89a213f49b344c4f0954d2bd5b8f8332ec291577335d1086765a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl

Download URL demopy_gb_jj-0.6.1-cp310-cp310-win_amd64.whl
Size 100.2 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
3f14c0c8140cd30ac90163d148c32981b5c232f2fd79c581da5005daf17ad37b
BLAKE2b-256 checksum
How to use checksums
03745245123f169cc845a8574fae3cd1e622f8c087249a366b29d3d9cd22e42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl

Download URL demopy_gb_jj-0.6.1-cp39-cp39-win_amd64.whl
Size 100.4 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
d9dd36edbd89309480cba993fded837149ca50ed948a7afec3a8c290e8c3a2af
BLAKE2b-256 checksum
How to use checksums
6dc34dbca4ba9dbe4d8038aebd4cc8ccd36fd5a8d7d1832bcbefda48161eb8bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.6.1 This release

11 release files

0.2.5

2 release files

0.2.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page