Skip to content

Anonymous961/python_package_sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧮 Calculator Package (Sample Python Project)

This is a sample project for creating a package in Python. It demonstrates how to structure a simple Python project, add CLI support, write tests with pytest, and run it like a command-line tool.


📁 Project Structure

calculator_package/
│
├── calculator/               # Package source code
│   ├── __init__.py
│   ├── core.py               # Calculator logic
│   └── cli.py                # CLI interface
│
├── tests/                    # Unit tests
│   ├── __init__.py
│   ├── test_core.py
│   └── conftest.py           # Adds package to PYTHONPATH for tests
│
├── main.py                   # Entry point (CLI executable)
├── pyproject.toml
├── requirements.txt
├── setup.py
└── README.md

🚀 Usage

🧪 1. Setup Virtual Environment

python -m venv venv
source venv/bin/activate

📦 2. Install Dependencies

pip install -r requirements.txt

▶️ 3. Run the Calculator

Make main.py executable:

chmod +x main.py

Now run:

./main.py add 2 3
# Output: Result: 5.0

🔬 Running Tests

Make sure you add PYTHONPATH or use conftest.py.

pytest

🛠 Calculator Functions

  • add(a, b)
  • subtract(a, b)
  • multiply(a, b)
  • divide(a, b) → raises error on divide by zero

🎁 Optional: Install as a Package (Editable Mode)

pip install -e .

Now you can use it anywhere in the virtual environment.


✅ License

MIT License


🧪 Educational Purpose

This project is designed for learning and testing how to properly create and structure a Python package with CLI and tests.

About

Just a sample python package

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages