From fa7b47ad596c56aeb9062af8e292773378002809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 23 Aug 2023 14:57:11 +0200 Subject: [PATCH] python-project: delete template this already went out-of-date and we haven't really used it, since its creation --- templates/flake-module.nix | 7 --- templates/python-project/.envrc | 1 - templates/python-project/default.nix | 62 ------------------- templates/python-project/flake-module.nix | 16 ----- templates/python-project/my_lib/__init__.py | 5 -- templates/python-project/my_tool/__init__.py | 17 ----- templates/python-project/pyproject.toml | 58 ----------------- templates/python-project/shell.nix | 39 ------------ templates/python-project/tests/conftest.py | 10 --- templates/python-project/tests/test_cli.py | 20 ------ .../tests/test_detect_git_repo.py | 16 ----- 11 files changed, 251 deletions(-) delete mode 100644 templates/python-project/.envrc delete mode 100644 templates/python-project/default.nix delete mode 100644 templates/python-project/flake-module.nix delete mode 100644 templates/python-project/my_lib/__init__.py delete mode 100644 templates/python-project/my_tool/__init__.py delete mode 100644 templates/python-project/pyproject.toml delete mode 100644 templates/python-project/shell.nix delete mode 100644 templates/python-project/tests/conftest.py delete mode 100644 templates/python-project/tests/test_cli.py delete mode 100644 templates/python-project/tests/test_detect_git_repo.py diff --git a/templates/flake-module.nix b/templates/flake-module.nix index a7149430..2074c12a 100644 --- a/templates/flake-module.nix +++ b/templates/flake-module.nix @@ -1,15 +1,8 @@ { - imports = [ - ./python-project/flake-module.nix - ]; flake.templates = { new-clan = { description = "Initialize a new clan flake"; path = ./new-clan; }; - python-project = { - description = "Initialize a new internal python project"; - path = ./python-project; - }; }; } diff --git a/templates/python-project/.envrc b/templates/python-project/.envrc deleted file mode 100644 index 1d953f4b..00000000 --- a/templates/python-project/.envrc +++ /dev/null @@ -1 +0,0 @@ -use nix diff --git a/templates/python-project/default.nix b/templates/python-project/default.nix deleted file mode 100644 index 18fa4c6f..00000000 --- a/templates/python-project/default.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ pkgs ? import { } -, lib ? pkgs.lib -, python3 ? pkgs.python3 -, ruff ? pkgs.ruff -, runCommand ? pkgs.runCommand -, -}: -let - pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); - name = pyproject.project.name; - - src = lib.cleanSource ./.; - - dependencies = lib.attrValues { - # inherit (python3.pkgs) - # some-package - # ; - }; - - devDependencies = lib.attrValues { - inherit (pkgs) ruff; - inherit (python3.pkgs) - black - mypy - pytest - pytest-cov - setuptools - wheel - ; - }; - - package = python3.pkgs.buildPythonPackage { - inherit name src; - format = "pyproject"; - nativeBuildInputs = [ - python3.pkgs.setuptools - ]; - propagatedBuildInputs = - dependencies - ++ [ ]; - passthru.tests = { inherit check; }; - passthru.devDependencies = devDependencies; - }; - - checkPython = python3.withPackages (_ps: devDependencies ++ dependencies); - - check = runCommand "${name}-check" { } '' - cp -r ${src} ./src - chmod +w -R ./src - cd src - export PYTHONPATH=. - echo -e "\x1b[32m## run ruff\x1b[0m" - ${ruff}/bin/ruff check . - echo -e "\x1b[32m## run mypy\x1b[0m" - ${checkPython}/bin/mypy . - echo -e "\x1b[32m## run pytest\x1b[0m" - ${checkPython}/bin/pytest - touch $out - ''; - -in -package diff --git a/templates/python-project/flake-module.nix b/templates/python-project/flake-module.nix deleted file mode 100644 index 5b130500..00000000 --- a/templates/python-project/flake-module.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ self, ... }: { - perSystem = { self', pkgs, ... }: - let - name = "python-template"; - in - { - packages.${name} = pkgs.callPackage ./default.nix { }; - - devShells.${name} = pkgs.callPackage ./shell.nix { - inherit self; - package = (self'.packages.${name}); - }; - - checks.python-template = self'.packages.${name}.tests.check; - }; -} diff --git a/templates/python-project/my_lib/__init__.py b/templates/python-project/my_lib/__init__.py deleted file mode 100644 index d87e45fe..00000000 --- a/templates/python-project/my_lib/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - - -def detect_git_repo(path: str) -> bool: - return os.path.exists(f"{path}/.git") diff --git a/templates/python-project/my_tool/__init__.py b/templates/python-project/my_tool/__init__.py deleted file mode 100644 index 4b0d9553..00000000 --- a/templates/python-project/my_tool/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -import argparse - -# statement that doesn't need testing -__version__ = "1.0.0" # pragma: no cover - - -# this will be an entrypoint under /bin/my_cli (see pyproject.toml config) -def my_cli() -> None: - parser = argparse.ArgumentParser(description="my-tool") - parser.add_argument( - "-v", "--version", help="Show the version of this program", action="store_true" - ) - args = parser.parse_args() - if args.version: - print(f"Version: {__version__}") - else: - parser.print_help() diff --git a/templates/python-project/pyproject.toml b/templates/python-project/pyproject.toml deleted file mode 100644 index 10656441..00000000 --- a/templates/python-project/pyproject.toml +++ /dev/null @@ -1,58 +0,0 @@ -[build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" - -[tool.setuptools] -packages = ["my_tool"] - -[project] -name = "my_tool" -description = "internal tooling of cLAN" -dynamic = ["version"] -scripts = {my-tool = "my_tool:my_cli"} - -[tool.pytest.ini_options] -addopts = "--cov . --cov-report term --cov-fail-under=100 --no-cov-on-fail" - -[tool.mypy] -python_version = "3.10" -warn_redundant_casts = true -disallow_untyped_calls = true -disallow_untyped_defs = true -no_implicit_optional = true - -[[tool.mypy.overrides]] -module = "setuptools.*" -ignore_missing_imports = true - -[[tool.mypy.overrides]] -module = "pytest.*" -ignore_missing_imports = true - -[tool.ruff] -line-length = 88 - -select = ["E", "F", "I"] -ignore = [ "E501" ] - -[tool.black] -line-length = 88 -target-version = ['py310'] -include = '\.pyi?$' -exclude = ''' -/( - \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - # The following are specific to Black, you probably don't want those. - | blib2to3 - | tests/data - | profiling -)/ -''' diff --git a/templates/python-project/shell.nix b/templates/python-project/shell.nix deleted file mode 100644 index 035e87f9..00000000 --- a/templates/python-project/shell.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ package, pkgs, ... }: -let - pythonWithDeps = pkgs.python3.withPackages ( - ps: - package.propagatedBuildInputs - ++ package.devDependencies - ++ [ - ps.pip - ] - ); - checkScript = pkgs.writeScriptBin "check" '' - nix build -f . tests -L "$@" - ''; - devShell = pkgs.mkShell { - packages = [ - pkgs.ruff - pythonWithDeps - ]; - # sets up an editable install and add enty points to $PATH - shellHook = '' - tmp_path=$(realpath ./.pythonenv) - repo_root=$(realpath .) - rm -rf $tmp_path - mkdir -p "$tmp_path/${pythonWithDeps.sitePackages}" - - ${pythonWithDeps.interpreter} -m pip install \ - --quiet \ - --disable-pip-version-check \ - --no-index \ - --no-build-isolation \ - --prefix "$tmp_path" \ - --editable $repo_root - - export PATH="$tmp_path/bin:${checkScript}/bin:$PATH" - export PYTHONPATH="$repo_root:$tmp_path/${pythonWithDeps.sitePackages}" - ''; - }; -in -devShell diff --git a/templates/python-project/tests/conftest.py b/templates/python-project/tests/conftest.py deleted file mode 100644 index 1c810680..00000000 --- a/templates/python-project/tests/conftest.py +++ /dev/null @@ -1,10 +0,0 @@ -import subprocess - -import pytest - - -# returns a temporary directory with a fake git repo -@pytest.fixture() -def git_repo_path(tmp_path: str) -> str: - subprocess.run(["mkdir", ".git"], cwd=tmp_path) - return tmp_path diff --git a/templates/python-project/tests/test_cli.py b/templates/python-project/tests/test_cli.py deleted file mode 100644 index 6c6f124c..00000000 --- a/templates/python-project/tests/test_cli.py +++ /dev/null @@ -1,20 +0,0 @@ -import sys - -import pytest - -import my_tool - - -def test_no_args(capsys: pytest.CaptureFixture) -> None: - my_tool.my_cli() - captured = capsys.readouterr() - assert captured.out.startswith("usage:") - - -def test_version( - capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch -) -> None: - monkeypatch.setattr(sys, "argv", ["", "--version"]) - my_tool.my_cli() - captured = capsys.readouterr() - assert captured.out.startswith("Version:") diff --git a/templates/python-project/tests/test_detect_git_repo.py b/templates/python-project/tests/test_detect_git_repo.py deleted file mode 100644 index d54bf7e2..00000000 --- a/templates/python-project/tests/test_detect_git_repo.py +++ /dev/null @@ -1,16 +0,0 @@ -import tempfile - -import my_lib - - -# using the fixture from conftest.py -def test_is_git_repo(git_repo_path: str) -> None: - result = my_lib.detect_git_repo(git_repo_path) - assert result is True - - -# using the fixture from conftest.py -def test_is_not_git_repo() -> None: - with tempfile.TemporaryDirectory() as tempdir: - result = my_lib.detect_git_repo(tempdir) - assert result is False