diff --git a/.gitignore b/.gitignore index 5de36c5..547b948 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ develop-eggs/ buildout.cfg .installed.cfg parts/ +/uv.lock diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/Makefile b/Makefile index 12d59bb..e983a77 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,17 @@ doc: @echo make install: install everything, including ourselves - @echo make upgrade: update/upgrade uv, brew, pipx + @echo make upgrade: update/upgrade uv, brew, uv tool -install: osx-deps npm ourselves_install local-dev extra-pipx +install: osx-deps ourselves_install uv-tools local-dev npm upgrade: uv self update + uv tool upgrade --all + uv cache prune brew update brew upgrade - pipx reinstall-all osx-deps: @@ -34,7 +35,6 @@ osx-deps: npm \ odt2txt \ pinentry-mac \ - pipx \ pre-commit \ pv \ rg \ @@ -45,42 +45,43 @@ osx-deps: watch \ wget \ tidy-html5 - @echo "=================================================================================" - @echo "A 'pipx reinstall-all' might be needed if there was a brew python version upgrade" - @echo "=================================================================================" - cd /tmp && pipx install --force --editable ~/zelf/tools && cd - -pipx-deps: ~/.local/pipx/venvs/ansible\ - ~/.local/pipx/venvs/ansible-lint\ - ~/.local/pipx/venvs/beautysh\ - ~/.local/pipx/venvs/black\ - ~/.local/pipx/venvs/checkoutmanager\ - ~/.local/pipx/venvs/cookiecutter\ - ~/.local/pipx/venvs/docutils\ - ~/.local/pipx/venvs/dotfiles\ - ~/.local/pipx/venvs/flake8\ - ~/.local/pipx/venvs/isort\ - ~/.local/pipx/venvs/legit\ - ~/.local/pipx/venvs/mopup \ - ~/.local/pipx/venvs/oplop\ - ~/.local/pipx/venvs/pipenv\ - ~/.local/pipx/venvs/pyupgrade\ - ~/.local/pipx/venvs/tox \ - ~/.local/pipx/venvs/youtube-dl +uv-tools: ~/.local/share/uv/tools/ansible\ + ~/.local/share/uv/tools/ansible-lint\ + ~/.local/share/uv/tools/beautysh\ + ~/.local/share/uv/tools/black\ + ~/.local/share/uv/tools/cookiecutter\ + ~/.local/share/uv/tools/docutils\ + ~/.local/share/uv/tools/dotfiles\ + ~/.local/share/uv/tools/flake8\ + ~/.local/share/uv/tools/isort\ + ~/.local/share/uv/tools/legit\ + ~/.local/share/uv/tools/oplop\ + ~/.local/share/uv/tools/pyupgrade\ + ~/.local/share/uv/tools/tox \ + ~/.local/share/uv/tools/youtube-dl +# mopup pipenv +~/.local/share/uv/tools/ansible: + uv tool install ansible --with dnspython -~/.local/pipx/venvs/ansible: - pipx install --include-deps ansible --pip-args dnspython +~/.local/share/uv/tools/tox: + uv tool install tox --with tox-uv -~/.local/pipx/venvs/%: - pipx install $* + +~/.local/share/uv/tools/%: + uv tool install $* + + +pythons: + uv python install 3.12 3.11 ~/Dotfiles: cd ~ && git clone ssh://vanrees.org/~/repos/Dotfiles - dotfiles --sync + uvx dotfiles --sync echo "You might want to run dotfiles --sync --force, btw" @@ -88,23 +89,18 @@ pipx-deps: ~/.local/pipx/venvs/ansible\ curl -LsSf https://astral.sh/uv/install.sh | sh -ourselves_install: /Users/reinout/.cargo/bin/uv pipx-deps ~/Dotfiles +ourselves_install: /Users/reinout/.cargo/bin/uv pythons ~/Dotfiles ./install_shell_scripts.sh - python3 generate_python_docs.py - python3 generate_shell_docs.py + uv tool install . + uv run ./generate_python_docs.py + uv run ./generate_shell_docs.py local-dev: - checkoutmanager co - pipx install --force --editable ~/opensource/checkoutmanager - pipx install --force --editable ~/opensource/zest.releaser - pipx install --force --editable ~/opensource/z3c.dependencychecker - pipx install --force --editable ~/zelf/denoter - - -extra-pipx: - pipx inject tox tox-uv - pipx inject --editable zest.releaser ~/opensource/qgispluginreleaser + uvx checkoutmanager co + uv tool install --editable ~/opensource/zest.releaser/ --with ~/opensource/qgispluginreleaser + uv tool install --editable ~/opensource/checkoutmanager/ + uv tool install --editable ~/zelf/denoter/ npm: diff --git a/README.rst b/README.rst index 68e1abb..8cef633 100644 --- a/README.rst +++ b/README.rst @@ -14,8 +14,8 @@ The idea is that this directory's bin subdirectory is on my path. - Shell scripts are located in ``shell/``. Running ``./install_shell_scripts.sh`` symlinks these into the ``bin/`` directory. -- The ``setup.py`` lists the python scripts, in the ``tools/`` directory. - These are installed with pipenv. +- The ``pyproject.toml`` lists the python scripts, in the ``tools/`` directory. + These are installed with ``uv`` by the ``Makefile``. And.... it is a way for me to be more **explicit** about my setup. A ``Makefile`` for installing what I need (with homebrew and pipx) instead of trying to remember everything @@ -49,13 +49,13 @@ Checkout ourselves:: cd ~/zelf git clone git@github.com:reinout/tools.git -Now install pipx, tools and dotfiles and checkouts and local dev installs:: +Now install uv, tools and dotfiles and checkouts and local dev installs:: cd ~/zelf/tools make install Note: the makefile also functions as a documentation on what I brew-install and -pipx-install. +uv-tools-install. Extra OSX install notes @@ -94,3 +94,12 @@ Likewise I've got a README for the python scripts. Look `at /tools on github formatted README at the bottom. This is generated from the scripts' docstrings with ``generate_python_docs.py`` (I just want a simple README, not full Sphinx documentation). + + +Local dev install notes +----------------------- + +Some hints:: + + $ uv sync + $ uv run dtname (or another command) diff --git a/generate_python_docs.py b/generate_python_docs.py index a3c0d9a..daac1a2 100755 --- a/generate_python_docs.py +++ b/generate_python_docs.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 """Generate a readme for the shell scripts.""" + import os import sys diff --git a/generate_shell_docs.py b/generate_shell_docs.py index 37f0aac..557f0fe 100755 --- a/generate_shell_docs.py +++ b/generate_shell_docs.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 """Generate a readme for the shell scripts.""" + import os OMIT = ["README.rst"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..05f946d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "tools" +version = "0.1.dev0" +description = "Tools and scripts for Reinout" +authors = [ + {name = "Reinout van Rees", email = "reinout@vanrees.org"}, +] +readme = "README.rst" +requires-python = ">=3.12" +dependencies = [] + +[tool.setuptools] +packages = ["tools"] + +[project.scripts] +log = "tools.engineerlog:main" +add_time = "tools.add_time:main" +copytoblog = "tools.blog:copytoblog" +dtname = "tools.dtname:main" +new_sermon = "tools.blog:new_sermon" +fixthunderbird = "tools.thunderbird:fix_thunderbird" +gh = "tools.github:main" +latestentries = "tools.blog:list_todays_entries" +makedocs = "tools.blog:makedocs" +sommen = "tools.sommen:main" +gac = "tools.git:main" +mkinit = "tools.mkinit:main" +python_coding_cleanup = "tools.python_coding_cleanup:main" + +[tool.ruff] +target-version = "py312" + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "I", "UP", "C901"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 872cf27..0000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[isort] -force_single_line = true -skip = bin,parts,var,bootstrap.py -from_first = true diff --git a/setup.py b/setup.py deleted file mode 100644 index 71b9383..0000000 --- a/setup.py +++ /dev/null @@ -1,52 +0,0 @@ -from setuptools import setup - -version = "0.1.dev0" - - -setup( - name="tools", - version=version, - description="Tools and scripts for Reinout", - long_description="", - classifiers=[], - keywords="", - author="Reinout van Rees", - author_email="reinout@vanrees.org", - url="https://reinout.vanrees.org", - license="GPL", - packages=["tools"], - namespace_packages=[], - include_package_data=True, - zip_safe=False, - install_requires=[ - # 'media-manager', - # ^^^ Only on osx at the moment,included in the buildout - # 'createcoverage', - # 'eolfixer', - # 'nensbuild', - # 'nenslint', - "coverage", - "future", - "nose", - "pyserial", - # 'readline', - "six", # Trying to make it explicit - ], - entry_points={ - "console_scripts": [ - "log = tools.engineerlog:main", - "add_time = tools.add_time:main", - "copytoblog = tools.blog:copytoblog", - "dtname = tools.dtname:main", - "new_sermon = tools.blog:new_sermon", - "fixthunderbird = tools.thunderbird:fix_thunderbird", - "gh = tools.github:main", - "latestentries = tools.blog:list_todays_entries", - "makedocs = tools.blog:makedocs", - "sommen = tools.sommen:main", - "gac = tools.git:main", - "mkinit = tools.mkinit:main", - "python_coding_cleanup = tools.python_coding_cleanup:main", - ] - }, -) diff --git a/shell/dos2unix.py b/shell/dos2unix.py index af22394..288d771 100755 --- a/shell/dos2unix.py +++ b/shell/dos2unix.py @@ -26,7 +26,7 @@ def unix2dos(data): def confirm(file_): - s = raw_input("%s? " % file_) + s = input(f"{file_}? ") return s and s[0] == "y" @@ -53,11 +53,11 @@ def usage(): sys.exit() -def main(): +def main(): # noqa: C901 try: opts, args = getopt.getopt(sys.argv[1:], "fniuvdc") args[0] - except: + except: # noqa: E722 usage() force = 0 noaction = 0 diff --git a/tools/add_time.py b/tools/add_time.py index 74666dd..bcdadaa 100644 --- a/tools/add_time.py +++ b/tools/add_time.py @@ -14,10 +14,7 @@ import sys try: - from PIL import Image - from PIL import ImageDraw - from PIL import ImageFont - from PIL import ImageOps + from PIL import Image, ImageDraw, ImageFont, ImageOps except ImportError: print("No PIL available.") @@ -45,4 +42,4 @@ def main(): out_filename = date_string.replace(":", "_") + ".png" image.save(out_filename, "png") - print("Saved %s" % out_filename) + print(f"Saved {out_filename}") diff --git a/tools/blog.py b/tools/blog.py index 81074fe..9e56cfa 100644 --- a/tools/blog.py +++ b/tools/blog.py @@ -12,14 +12,14 @@ """ -from datetime import datetime -from string import Template import os import readline import shutil import subprocess import sys import webbrowser +from datetime import datetime +from string import Template DOCS = os.path.expanduser("~/zelf/reinout.vanrees.org/docs") BUILD = os.path.join(DOCS, "build", "html") @@ -45,7 +45,7 @@ def copytoblog(): print("pass along filename!") filename = sys.argv[1] if not os.path.exists(filename): - print("%s doesn't exist" % filename) + print(f"{filename} doesn't exist") now = datetime.now() y = "%04d" % now.year @@ -100,7 +100,7 @@ def copytoblog(): webbrowser.open(on_site) if "y" in input("Delete file in ~/blog/? [y/N] "): os.remove(os.path.join(os.path.expanduser("~/blog"), filename)) - print("%s removed" % filename) + print(f"{filename} removed") def makedocs(): @@ -137,7 +137,7 @@ def list_todays_entries(): monthdir = os.path.join(yeardir, m) daydir = os.path.join(monthdir, d) if not os.path.exists(daydir): - print("Nothing posted yet in %s" % daydir) + print(f"Nothing posted yet in {daydir}") sys.exit(1) entries = [ entry @@ -188,7 +188,7 @@ def new_sermon(): yeardir = os.path.join(SERMONSOURCE, yyyy) if not os.path.exists(yeardir): os.mkdir(yeardir) - print("Created %s" % yeardir) + print(f"Created {yeardir}") title = None while not title: diff --git a/tools/mkinit.py b/tools/mkinit.py index 6b5df26..014bf71 100644 --- a/tools/mkinit.py +++ b/tools/mkinit.py @@ -13,8 +13,8 @@ def main(): dirname = sys.argv[1] if not os.path.exists(dirname): os.mkdir(dirname) - print("Created directory %s" % dirname) + print(f"Created directory {dirname}") initfile = os.path.join(dirname, "__init__.py") if not os.path.exists(initfile): open(initfile, "w").write("# package\n") - print("Created file %s" % initfile) + print(f"Created file {initfile}") diff --git a/tools/sommen.py b/tools/sommen.py index 6c196e5..45510ab 100644 --- a/tools/sommen.py +++ b/tools/sommen.py @@ -43,10 +43,7 @@ def main(): else: actions = [plus, minus, times] for i in range(NUMBER_OF_LINES): - line = "{} {}\n\n".format( - random.choice(actions)(), - random.choice(actions)(), - ) + line = f"{random.choice(actions)()} {random.choice(actions)()}\n\n" outfile.write(line) outfile.close() webbrowser.open("file:///tmp/sommen.txt") diff --git a/tools/thunderbird.py b/tools/thunderbird.py index f893cd0..2c60837 100644 --- a/tools/thunderbird.py +++ b/tools/thunderbird.py @@ -33,7 +33,7 @@ def fix_thunderbird(): # new = '%s: %s-%s\n' % (newsgroup, # parts[0], # parts[-1]) - new = "{}: 1-{}\n".format(newsgroup, parts[-1]) + new = f"{newsgroup}: 1-{parts[-1]}\n" print(new) outfile.write(new) outfile.close()