pip install . # pyproject.toml
pyproject.toml🔗
Crie seu arquivo pyproject.toml, nele você define metadados do projeto como
nome, dependências e versão
Nota
Esta sendo usado o hatch como build backend.
pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "calc"
version = "0.1.0"
dependencies = ["pydantic>=2.6.4"]
[project.optional-dependencies]
lint = ["pylint>=3.1.0"]
[tool.hatch.build.targets.sdist]
packages = ["calc"]
[tool.hatch.build.targets.wheel]
packages = ["calc"]
Código🔗
calc/__init__.py
# pylint: disable=missing-module-docstring
import operator
from functools import reduce
from numbers import Number
from pydantic import validate_arguments
@validate_arguments(config={'arbitrary_types_allowed': True})
def add(*args: Number) -> Number:
"""Sum N arguments.
:param args: Arguments to be used in the operation.
"""
return reduce(operator.add, args)
@validate_arguments(config={'arbitrary_types_allowed': True})
def div(*args: Number) -> Number:
"""Divide N arguments.
:param args: Arguments to be used in the operation.
"""
return reduce(operator.floordiv, args)
@validate_arguments(config={'arbitrary_types_allowed': True})
def mult(*args: Number) -> Number:
"""Multiply N arguments.
:param args: Arguments to be used in the operation.
"""
return reduce(operator.mul, args)
@validate_arguments(config={'arbitrary_types_allowed': True})
def sub(*args: Number) -> Number:
"""Subtract N arguments.
:param args: Arguments to be used in the operation.
"""
return reduce(operator.sub, args)
Install🔗
Após a definição instale o projeto.
Extras🔗
Instale um grupo de dependências entre colchetes separados por vírgula.