MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Python
  • pyproject.toml

Contents

  1. pyproject.toml
    1. Other example

pyproject.toml

Replaces requirements.txt

To install pip install -e .

my_project/
├── pyproject.toml
└── my_package/
    ├── __init__.py
    └── main.py

   1 # my_package/main.py
   2 
   3 def say_hello():
   4     print("Hello from the world of TOML-configured Python!")
   5 
   6 if __name__ == "__main__":
   7     say_hello()

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "my_hello_app"
version = "0.1.0"
dependencies = []

[project.scripts]
# This creates a command 'hello-world' that runs say_hello()
hello-world = "my_package.main:say_hello"

[tool.setuptools]
packages = ["my_package"]

Other example

make install
make check
make clean

Structure

hello_project/
├── pyproject.toml
├── Makefile
├── .gitignore
├── src/
│   └── main.py
└── tests/
    └── test_main.py

pyproject.toml

[project]
name = "hello_world_example"
version = "0.1.0"
dependencies = []

[project.optional-dependencies]
dev = [
    "coverage",
    "ruff",
]

[tool.ruff]
target-version = "py310"
lint.select = ["E", "F", "I"]
line-length = 88

[tool.coverage.run]
source = ["src"]
branch = true

[tool.coverage.report]
show_missing = true

Makefile

VENV = .venv
PYTHON = $(VENV)/bin/python3
PIP = $(VENV)/bin/pip
RUFF = $(VENV)/bin/ruff
COVERAGE = $(VENV)/bin/coverage

.PHONY: venv install lint format test coverage clean check

$(VENV)/bin/activate:
        python3 -m venv $(VENV)
        $(PIP) install --upgrade pip

venv: $(VENV)/bin/activate

install: venv
        $(PIP) install -e ".[dev]"

lint: venv
        $(RUFF) check .

format: venv
        $(RUFF) format .

test: venv
        $(PYTHON) -m unittest discover tests

coverage: venv
        $(COVERAGE) run -m unittest discover tests
        $(COVERAGE) report
        $(COVERAGE) html

check: format lint coverage

clean:
        rm -rf $(VENV) .ruff_cache htmlcov .coverage
        find . -type d -name "__pycache__" -exec rm -rf {} +

.gitignore

.venv/
__pycache__/
*.py[cod]
.coverage
htmlcov/
.ruff_cache/
.DS_Store

src/main.py

   1 def get_hello_message(name="World"):
   2     return f"Hello, {name}!"
   3 
   4 if __name__ == "__main__":
   5     print(get_hello_message())

tests/test_main.py

   1 import unittest
   2 from src.main import get_hello_message
   3 
   4 class TestHelloWorld(unittest.TestCase):
   5     def test_default_greeting(self):
   6         self.assertEqual(get_hello_message(), "Hello, World!")
   7 
   8     def test_custom_greeting(self):
   9         self.assertEqual(get_hello_message("Gemini"), "Hello, Gemini!")
  10 
  11 if __name__ == "__main__":
  12     unittest.main()
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01