Skip to main content

Test to upload math module to Pypi

Project description

RW Math

A simple Python mathematical operations module for demonstration and learning purposes.

Python Version License Code Coverage

Features

  • Basic mathematical operations: addition, subtraction, multiplication, division
  • Fully tested with pytest
  • 100% code coverage
  • Type hints for better IDE support
  • Clean, simple API

Installation

From PyPI (when published)

pip install rw-math

For Development

# Clone the repository
git clone <repository-url>
cd python_module

# Tests work directly without installation due to pythonpath configuration
pytest

Usage

As a Library

from rwmath import add, sub, mul, div

# Addition
result = add(3, 4)  # 7

# Subtraction
result = sub(10, 4)  # 6

# Multiplication
result = mul(5, 6)  # 30

# Division
result = div(10, 2)  # 5.0

Command Line

rw_math
# Output: Hello from python-module!
#         add 7

API Reference

Simple mathematical operations: add(), sub(), mul(), div()

See source code in src/rwmath/math.py for implementation details.

Building and Publishing

How to Build

uv build --no-sources

This creates distribution packages in the dist/ directory.

How to Publish

Publish to PyPI:

uv publish --token <your_token_from_pypi>

Publish to Test PyPI:

uv publish --publish-url https://test.pypi.org/legacy/ --token <your_token>

Getting API Tokens

Testing Installation from Test PyPI

After publishing to Test PyPI, test the installation:

# Install from Test PyPI (persists index in pyproject.toml)
uv add --index https://test.pypi.org/simple/ rw-math

Note: Using --index (not --index-url) will persist the Test PyPI configuration in pyproject.toml. Your package has no runtime dependencies, so it installs cleanly from Test PyPI.

Development

Project Structure

python_module/
\x00\x00 src/
   \x00\x00 main.py              # Entry point
   \x00\x00 rwmath/
       \x00\x00 __init__.py      # Package exports
       \x00\x00 math.py          # Core functions
\x00\x00 tests/
   \x00\x00 __init__.py
   \x00\x00 test_math.py         # Unit tests
\x00\x00 pyproject.toml           # Project configuration
\x00\x00 .gitignore
\x00\x00 README.md

Setup Development Environment

  1. Clone the repository:
git clone <repository-url>
cd python_module
  1. Install development dependencies:
# Install the package with dev dependencies
uv sync --extra dev

Or manually:

uv add --dev pytest pytest-cov

The project uses pythonpath = ["src"] in pyproject.toml, which allows pytest to import modules directly without installing the package.

Running Tests

All test settings are configured in pyproject.toml, so you just need to run:

Basic test run (includes coverage automatically):

pytest

This automatically:

  • Finds tests in tests/ directory
  • Measures code coverage for src/rwmath/
  • Shows missing lines in terminal
  • Generates HTML report in htmlcov/
  • Fails if coverage drops below 80%

Additional test commands:

# Verbose output
pytest -v

# Run specific test
pytest tests/test_math.py::TestAdd::test_add_positive_numbers

# View HTML coverage report
open htmlcov/index.html  # macOS

Test Coverage

Current coverage: 100%

All coverage settings are centralized in pyproject.toml:

  • Minimum required: 80% (configurable)
  • HTML reports: Generated in htmlcov/
  • Terminal output: Shows missing lines
  • Excludes: Test files and __init__.py files
  • Precision: 2 decimal places

Code Quality Standards

  • Type Hints: All functions use type annotations
  • Testing: 100% code coverage with pytest
  • Documentation: Docstrings for all public functions
  • Edge Cases: Comprehensive testing including error conditions

Configuration Files

pyproject.toml

All project and test configuration is centralized in pyproject.toml:

Project Metadata:

[project]
name = "rw_math"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["pytest>=8.4.2", "pytest-cov>=7.0.0"]

Pytest Configuration:

[tool.pytest.ini_options]
pythonpath = ["src"]           # Import from src/ without installation
testpaths = ["tests"]          # Test discovery location
addopts = [
    "--cov=src/rwmath",        # Coverage target
    "--cov-report=term-missing", # Terminal report
    "--cov-report=html",       # HTML report
    "--cov-fail-under=80",     # Minimum 80% coverage
]

Coverage Settings:

[tool.coverage.run]
source = ["src"]               # Source code location
omit = ["*/tests/*", "*/__init__.py"]  # Exclude from coverage

[tool.coverage.report]
precision = 2                  # Decimal places
show_missing = true            # Show uncovered lines
fail_under = 80                # Minimum threshold

[tool.coverage.html]
directory = "htmlcov"          # HTML report location

Key Benefits:

  • ✅ No separate pytest.ini or .coveragerc files needed
  • ✅ All settings version-controlled in one place
  • ✅ Consistent configuration across all environments
  • pythonpath = ["src"] enables imports without package installation

Requirements

  • Python 3.12 or higher
  • pytest >= 8.4.2
  • pytest-cov >= 7.0.0

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pytest)
  5. Ensure coverage is maintained (pytest --cov)
  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

Code Style

  • Follow PEP 8 guidelines
  • Use type hints for all function signatures
  • Write docstrings for public APIs
  • Keep functions simple and focused (Single Responsibility Principle)
  • Write tests for all new functionality

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Ronson W.

Changelog

[0.1.0] - 2024-10-28

Added

  • Initial release
  • Basic mathematical operations (add, sub, mul, div)
  • Complete test suite with 100% coverage
  • Type hints for all functions
  • Command-line interface
  • Comprehensive documentation

Roadmap

Future enhancements under consideration:

  • Additional mathematical operations (power, modulo, etc.)
  • Support for floating-point inputs
  • More robust error handling
  • Performance optimizations
  • CLI with argument parsing

Support

For issues, questions, or contributions, please open an issue on the GitHub repository.

Acknowledgments

  • Built with uv for fast Python package management
  • Tested with pytest
  • Coverage reports by pytest-cov

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

rw_math-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

rw_math-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file rw_math-0.1.1.tar.gz.

File metadata

  • Download URL: rw_math-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for rw_math-0.1.1.tar.gz
Algorithm Hash digest
SHA256 035b3c983967538ac42f699c91e5dc199a41746284a2b6725c01663f409b43e7
MD5 70e1478df58b19d03fe502ec5daf0663
BLAKE2b-256 745b0de16d6377fd6c16b8c03ef14074d32cb4b62bf9b28fbbdb0c45d91ecc7f

See more details on using hashes here.

File details

Details for the file rw_math-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rw_math-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for rw_math-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c26db32abd208f8fb786025aabd53e1cdd2137056c6027558b305332f3372635
MD5 f7a316d30edae56a9b781052e8564adb
BLAKE2b-256 cd81b461aa6ce23f9774c8d43e7e91a3ac8fabcb6625f09be6abf025b23642ea

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