forked from clan/clan-core
python-project: delete template
this already went out-of-date and we haven't really used it, since its creation
This commit is contained in:
parent
35340aff80
commit
fa7b47ad59
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
use nix
|
@ -1,62 +0,0 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, 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
|
@ -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;
|
||||
};
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
import os
|
||||
|
||||
|
||||
def detect_git_repo(path: str) -> bool:
|
||||
return os.path.exists(f"{path}/.git")
|
@ -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()
|
@ -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
|
||||
)/
|
||||
'''
|
@ -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
|
@ -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
|
@ -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:")
|
@ -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
|
Loading…
Reference in New Issue
Block a user