From 855bb106a002c9ec238b3ec82e48207fe07880e5 Mon Sep 17 00:00:00 2001 From: JJJHolscher Date: Sat, 1 Jul 2023 13:30:03 +0200 Subject: [PATCH] ginit --- LICENSE | 21 +++++++++++ README.md | 12 ++++++ makefile | 92 ++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 43 ++++++++++++++++++++++ requirements.txt | 10 +++++ setup.py | 3 ++ src/__init__.py | 3 ++ src/main.py | 7 ++++ src/tests | 1 + tests/__init__.py | 1 + tests/test_main.py | 14 +++++++ 11 files changed, 207 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 makefile create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 src/__init__.py create mode 100644 src/main.py create mode 120000 src/tests create mode 100644 tests/__init__.py create mode 100644 tests/test_main.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5c7cd7 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# README + +## files + +______________________________________________________________________ +|.gitignore |a list of unshared files| +|makefile|dev tools for installing, publisizing etc.| +|pyproject.toml |project metadata| +|requirements.txt |python dependencies| +|setup.py|necessary for `pip install -e .`| +|src/main.py|first file that gets called| +-------------------------------------------- diff --git a/makefile b/makefile new file mode 100644 index 0000000..234fc7f --- /dev/null +++ b/makefile @@ -0,0 +1,92 @@ + +pwd = $(shell pwd) +name = $(notdir $(pwd)) +email = $(shell cat "$$HOME/.secret/email.txt") +version = $(shell yq ".project.version" pyproject.toml) + +binlink = ${HOME}/.local/bin/$(name) +srclink = $(pwd)/$(name) +venv = $(pwd)/.venv +venvbin = $(venv)/bin +activate = $(venv)/bin/activate + +define clear_dir + if [ -d $(1) ]; then rm -r $(1); fi + mkdir $(1) +endef + +$(venv): $(venvbin) $(binlink) $(srclink) + touch $(venv) + +$(venvbin): $(activate) requirements.txt + . .venv/bin/activate && \ + pip install -r requirements.txt + touch $(venvbin) + +$(activate): + python -m venv --prompt $(name) .venv + . .venv/bin/activate && \ + pip install --upgrade pip; + +$(binlink): + echo "#!/bin/sh\n$(venv)/bin/python $(pwd)/src/main.py \"\$$@\"" > $(binlink) + chmod +x $(binlink) + +$(srclink): + ln -s "./src" "$(srclink)" + sed 's/NAME/$(name)/' pyproject.toml > pyproject.temp + mv pyproject.temp pyproject.toml + +share: $(venv) .git/refs/remotes/public + git checkout main && \ + git push public --tags + +test_local: $(venv) + python -m unittest src.tests + +build: + $(call clear_dir,dist) + mv pyproject.toml pyproject.temp + sed 's/^email = .*/email = "$(email)"/' pyproject.temp > pyproject.toml + python -m build + mv pyproject.temp pyproject.toml + +increment_patch: + $(eval patch = $(shell echo $(version) | grep -o '[0-9]*$$')) + $(eval patch = $(shell echo "$$(($(patch)+1))")) + $(eval majorminor = $(shell echo $(version) | grep -o '^[0-9]*.[0-9]*.')) + $(eval version = $(majorminor)$(patch)) + sed 's/version = .*/version = "$(version)"/' pyproject.toml > pyproject.temp + mv pyproject.temp pyproject.toml + echo "$(version)" + +test: $(venv) test_local increment_patch build + twine upload dist/* -r pypitest + $(call clear_dir,"tmp") + cd tmp && \ + python -m venv .venv + . tmp/.venv/bin/activate && \ + pip install --extra-index-url "https://test.pypi.org/simple" "$(name) == $(version)" || \ + pip install --extra-index-url "https://test.pypi.org/simple" "$(name) == $(version)" && \ + python -m unittest "$(name).tests" + +publish: $(venv) + $(call clear_dir,"dist") + python -m build + twine upload dist/* + +.git/refs/remotes/public: + git checkout -b main + $(eval user_name = $(shell yq ".git.github" pyproject.toml)) + curl -u "$(user_name)" "https://api.github.com/user/repos" -d "{\"name\":\"$(name)\",\"private\":false}" + git remote add github "https://github.com/$(user_name)/$(name)" + git remote add public "/mnt/nas/git/$(name)" + git remote set-url --add --push public "/mnt/nas/git/$(name)" + git remote set-url --add --push public "https://github.com/$(user_name)/$(name)" + git push public main + +clean: + rm -r .venv + rm $(binlink) + rm $(srclink) + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..11d3ff9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ + +[project] +name = "NAME" +version = "0.0.0" # TODO; automatically update versions by looking at git +description = "" +dependencies = [] +dynamic = ["readme"] +requires-python = ">=3.11" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[git] +github = "JJJHolscher" + +[project.urls] +homepage = "https://github.com/JJJHolscher/NAME" + +[[project.authors]] +name = "Jochem Hölscher" +email = "a.fake@e.mail" + +[build-system] +requires = [ + "setuptools>=61.0", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +include = ["NAME"] + +[tool.setuptools.dynamic] +readme = {file = ["README.md"], content-type = "text/markdown"} + +[tool.jupytext] +formats = "ipynb,py" + +[tool.pyright] +exclude = ".venv" +venvPath = "." +venv = ".venv" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..44c9804 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +build +debugpy +ipython +jupytext +matplotlib-backend-kitty +numpy +pandas +pyright +result +twine diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0ca740b --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +#! /usr/bin/env python3 +from setuptools import setup +setup() diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..00e3147 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,3 @@ +#! /usr/bin/env python3 +# Remove this file if you don't have a main.py. +from .main import * diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..9789cc1 --- /dev/null +++ b/src/main.py @@ -0,0 +1,7 @@ +#! /usr/bin/env python3 +# vim:fenc=utf-8 + +""" + +""" + diff --git a/src/tests b/src/tests new file mode 120000 index 0000000..6dd24e0 --- /dev/null +++ b/src/tests @@ -0,0 +1 @@ +../tests \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..7ac2628 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +from .test_main import * diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..fb57aa3 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,14 @@ +#! /usr/bin/env python3 +# vim:fenc=utf-8 + +import unittest + +from src.main import * + + +class TestMain(unittest.TestCase): + def test_main(self): + self.assertEqual(UNITTESTS(), 0) + +if __name__ == "__main__": + unittest.main()