From 263df3000f2fb9d88a10f9ed655f0f2ead1264c0 Mon Sep 17 00:00:00 2001 From: Ivan Mamtsev Date: Fri, 22 Nov 2024 17:33:35 +0400 Subject: [PATCH 1/2] rework boilerplate --- .github/workflows/pyci.yml | 4 ---- .gitignore | 4 ++-- Makefile | 3 +++ hexlet_python_package/half.py | 2 ++ hexlet_python_package/scripts/__init__.py | 0 .../scripts/hexlet_python_package.py | 11 --------- hexlet_python_package/scripts/main.py | 11 +++++++++ hexlet_python_package/user.py | 22 ------------------ pyproject.toml | 9 +++++++- ruff.toml | 9 ++++++++ setup.cfg | 23 ------------------- tests/test_half.py | 5 ++++ tests/test_users.py | 16 ------------- uv.lock | 2 +- 14 files changed, 41 insertions(+), 80 deletions(-) create mode 100644 hexlet_python_package/half.py delete mode 100644 hexlet_python_package/scripts/__init__.py delete mode 100644 hexlet_python_package/scripts/hexlet_python_package.py create mode 100644 hexlet_python_package/scripts/main.py delete mode 100644 hexlet_python_package/user.py create mode 100644 ruff.toml delete mode 100644 setup.cfg create mode 100644 tests/test_half.py delete mode 100644 tests/test_users.py diff --git a/.github/workflows/pyci.yml b/.github/workflows/pyci.yml index 9b5fe67..38deb15 100644 --- a/.github/workflows/pyci.yml +++ b/.github/workflows/pyci.yml @@ -7,10 +7,6 @@ on: jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - # we want to test our package on several versions of Python - python-version: [3.8, 3.9] steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/.gitignore b/.gitignore index 3ec8339..ff94aeb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ __pycache__ dist/ *.pyc -.venv/ +.venv .coverage coverage.xml -.pytest_cache/ +*_cache/ diff --git a/Makefile b/Makefile index 3ad05ae..c27acc9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ install: uv sync +run: + uv run hexlet-python-package + test: uv run pytest diff --git a/hexlet_python_package/half.py b/hexlet_python_package/half.py new file mode 100644 index 0000000..2fe13bb --- /dev/null +++ b/hexlet_python_package/half.py @@ -0,0 +1,2 @@ +def half(num): + return num / 2 diff --git a/hexlet_python_package/scripts/__init__.py b/hexlet_python_package/scripts/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/hexlet_python_package/scripts/hexlet_python_package.py b/hexlet_python_package/scripts/hexlet_python_package.py deleted file mode 100644 index c2f299d..0000000 --- a/hexlet_python_package/scripts/hexlet_python_package.py +++ /dev/null @@ -1,11 +0,0 @@ -from hexlet_python_package import user - - -def main(): - """Run an example code.""" - # it is ok to have some magical numbers locally - print(user.User(name='Bob', age=42).get_introduction()) # noqa:WPS432 - - -if __name__ == '__main__': - main() diff --git a/hexlet_python_package/scripts/main.py b/hexlet_python_package/scripts/main.py new file mode 100644 index 0000000..c3963cf --- /dev/null +++ b/hexlet_python_package/scripts/main.py @@ -0,0 +1,11 @@ +import sys + +from hexlet_python_package.half import half + + +def main(): + print(half(float(sys.argv[-1]))) + + +if __name__ == "__main__": + main() diff --git a/hexlet_python_package/user.py b/hexlet_python_package/user.py deleted file mode 100644 index 6e799ff..0000000 --- a/hexlet_python_package/user.py +++ /dev/null @@ -1,22 +0,0 @@ -class User(object): - """Object representation of user.""" - - def __init__(self, name: str, age: int): - """ - Construct a new user. - - Args: - name: user's name - age: user's age - """ - self.name = name - self.age = age - - def get_introduction(self) -> str: - """ - Return a user's self-introduction. - - Returns: - str - """ - return "Hello, i'm {self.name}, {self.age}".format(self=self) diff --git a/pyproject.toml b/pyproject.toml index 5b189ed..c9f967e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,4 +16,11 @@ dev-dependencies = [ ] [project.scripts] -hexlet-python-package = "hexlet_python_package.scripts.hexlet_python_package:main" +hexlet-python-package = "hexlet_python_package.scripts.main:main" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["hexlet_python_package"] diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..5496d6f --- /dev/null +++ b/ruff.toml @@ -0,0 +1,9 @@ +line-length = 80 + +[lint.per-file-ignores] + # init modules can contain the local imports, logic, unused imports +"__init__.py" = ["F401"] + +[lint] +preview = true +select = ["E", "F", "I"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 29d0216..0000000 --- a/setup.cfg +++ /dev/null @@ -1,23 +0,0 @@ -[flake8] -accept-encodings = utf-8 -max-complexity = 6 -statistics = False -max-line-length = 80 -enable-extensions = G -isort-show-traceback = True - -exclude = .git,__pycache__,.venv,dist,build - -ignore = - # line break occurred before a binary operator - W503 - -per-file-ignores = - # init modules can contain the local imports, logic, unused imports - __init__.py: F401 - -[isort] -multi_line_output = 3 -include_trailing_comma = true -default_section = FIRSTPARTY -line_length = 79 diff --git a/tests/test_half.py b/tests/test_half.py new file mode 100644 index 0000000..510c0cd --- /dev/null +++ b/tests/test_half.py @@ -0,0 +1,5 @@ +from hexlet_python_package.half import half + + +def test_half(): + assert half(6) == 3 diff --git a/tests/test_users.py b/tests/test_users.py deleted file mode 100644 index 2acf8de..0000000 --- a/tests/test_users.py +++ /dev/null @@ -1,16 +0,0 @@ -from hexlet_python_package.user import User - - -def test_instantiation(): - """Check that User instance has the particular properties.""" - bob = User('Bob', 42) - assert bob.name == 'Bob' - assert bob.age == 42 - - -def test_introduction(): - """Check that user introduses herself properly.""" - alice = User('Alice', 21) - intro = alice.get_introduction() - assert alice.name in intro - assert str(alice.age) in intro diff --git a/uv.lock b/uv.lock index 88d7b47..1876788 100644 --- a/uv.lock +++ b/uv.lock @@ -106,7 +106,7 @@ wheels = [ [[package]] name = "python-example-app" version = "0.1.0" -source = { virtual = "." } +source = { editable = "." } [package.dev-dependencies] dev = [ From 91322865035e4db06f0d25da76a031e4650e6992 Mon Sep 17 00:00:00 2001 From: Ivan Mamtsev Date: Fri, 22 Nov 2024 17:36:29 +0400 Subject: [PATCH 2/2] fix readme --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index a2599aa..424b7d3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,19 @@ This project was built using these tools: --- +### Setup + +```bash +make install +``` + + +### Run tests + +```bash +make test +``` + [![Hexlet Ltd. logo](https://raw.githubusercontent.com/Hexlet/assets/master/images/hexlet_logo128.png)](https://hexlet.io/?utm_source=github&utm_medium=link&utm_campaign=python-package) This repository is created and maintained by the team and the community of Hexlet, an educational project. [Read more about Hexlet](https://hexlet.io/?utm_source=github&utm_medium=link&utm_campaign=python-package).