Test to upload math module to Pypi
Project description
RW Math
A simple Python mathematical operations module for demonstration and learning purposes.
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
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
- Clone the repository:
git clone <repository-url>
cd python_module
- Install dependencies (optional, using uv):
uv add 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__.pyfiles - 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.inior.coveragercfiles 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Ensure coverage is maintained (
pytest --cov) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rw_math-0.1.0.tar.gz.
File metadata
- Download URL: rw_math-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d1faeef7a9b93ef887aa588e9a3fdee6d6cd282084f371e063a27e5752d31e3
|
|
| MD5 |
3483c44fa034e4d44abf5cceda174fdd
|
|
| BLAKE2b-256 |
3d8e7162f031979588229794325fd7b762a1d3a478520e0ecace37239325da2b
|
File details
Details for the file rw_math-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rw_math-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78caf18606b4c886ddd45d2cdf0d9b319be16e475e9dfbd8ce3327675c4b9ae2
|
|
| MD5 |
a85855bba5144d1e95d7a2f83487e92b
|
|
| BLAKE2b-256 |
75a721947656f2f1fa16f56577e0ce31406b58f684e16e601d91e89f650e3bcb
|