From 18acb7250e3ae0fa40a93f3f709dc4364b80f403 Mon Sep 17 00:00:00 2001 From: ahuston-0 Date: Mon, 29 Jul 2024 18:29:54 -0400 Subject: [PATCH] bulk rename to flupdt, add CLI, add README, add .gitignore Signed-off-by: ahuston-0 --- .gitignore | 165 ++++++++++++++++++++++++++++++++++ README.md | 27 ++++++ app/main.py | 10 --- checks.nix | 15 ++++ flake.nix | 4 +- {app => flupdt}/__init__.py | 0 flupdt/cli.py | 11 +++ {app => flupdt}/common.py | 0 {app => flupdt}/flake_show.py | 2 +- flupdt/main.py | 13 +++ flupdt/model.py | 52 +++++++++++ main.py | 5 -- pyproject.toml | 12 ++- shell.nix | 4 +- 14 files changed, 297 insertions(+), 23 deletions(-) delete mode 100644 app/main.py rename {app => flupdt}/__init__.py (100%) create mode 100644 flupdt/cli.py rename {app => flupdt}/common.py (100%) rename {app => flupdt}/flake_show.py (96%) create mode 100644 flupdt/main.py create mode 100644 flupdt/model.py delete mode 100644 main.py diff --git a/.gitignore b/.gitignore index ce88720..a23f776 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,168 @@ post-diff # ruff cache .ruff_cache + +# borrowed from https://github.com/github/gitignore/blob/bfa56dc5d8465f558383f6764e1219b4e983b725/Python.gitignore + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/README.md b/README.md index e69de29..01d5ce0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,27 @@ +# Flake Update Diff Tool + +This is the Nix flake update validator. A tool which is able to evaluate a flake +at two points in history, check that everything evaluates, and provide a diff +of the two. In its target state, it will provide a similar function to +DeterminateSystems' awesome `update-flake-lock` tool, but with `nvd` integration +and other bells and whistles that we've come to like. + +## How to Use + +Currently, this only supports locally-stored flakes, although we are planning to +add support for `git`-based URLs for usage outside of CI pipelines where the +repository is already downloaded. + +``` shell +nix run github:RAD-Development/flake-update-diff-tool -- +``` + +For use in other nix-based projects, `flpudt` is available as +`packages.${system}.flupdt`. Please see our `examples/` folder for common +use-cases. + +## Why the name? + +`flupdt` comes from Fl(ake) Up(date) D(iff) T(ool). The cli is also available as +`flake-update-diff-tool`, for ease-of-use and those who use screen readers or +similar accessibility tools that may not react well to `flupdt`. diff --git a/app/main.py b/app/main.py deleted file mode 100644 index 7422015..0000000 --- a/app/main.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python3 - -from app.flake_show import get_derivations - -def main(): - print(get_derivations("/home/alice/.gitprojects/nix-dotfiles")) - -if __name__ == "__main__": - main() - diff --git a/checks.nix b/checks.nix index 2bc11b6..a24133c 100644 --- a/checks.nix +++ b/checks.nix @@ -4,6 +4,9 @@ formatter, ... }: +let + pkgs = inputs.nixpkgs.legacyPackages.${system}; +in { pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { src = ./.; @@ -43,6 +46,18 @@ # toml hooks check-toml.enable = true; + # markdown hooks + mdl = { + enable = true; + settings.style = + (pkgs.writeText ".mdl_style.rb" '' + #!/usr/bin/env ruby + + all + rule 'MD013', :tables => false + '').outPath; + }; + # git hooks check-merge-conflicts.enable = true; ## prevents committing to main diff --git a/flake.nix b/flake.nix index 16863c0..4f932a0 100644 --- a/flake.nix +++ b/flake.nix @@ -70,10 +70,10 @@ in rec { packages = { - myapp = poetry2nix.mkPoetryApplication poetryConfig // { + flupdt = poetry2nix.mkPoetryApplication poetryConfig // { develop = true; }; - default = self.packages.${system}.myapp; + default = self.packages.${system}.flupdt; }; formatter = pkgs.nixfmt-rfc-style; diff --git a/app/__init__.py b/flupdt/__init__.py similarity index 100% rename from app/__init__.py rename to flupdt/__init__.py diff --git a/flupdt/cli.py b/flupdt/cli.py new file mode 100644 index 0000000..74d1549 --- /dev/null +++ b/flupdt/cli.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +import argparse + + +def parse_inputs(): + parser = argparse.ArgumentParser() + parser.add_argument( + "flake_path", metavar="flake-path", help="path to flake to evaluate" + ) + args = parser.parse_args() + return args diff --git a/app/common.py b/flupdt/common.py similarity index 100% rename from app/common.py rename to flupdt/common.py diff --git a/app/flake_show.py b/flupdt/flake_show.py similarity index 96% rename from app/flake_show.py rename to flupdt/flake_show.py index cc34f52..be53416 100644 --- a/app/flake_show.py +++ b/flupdt/flake_show.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import json -from app.common import bash_wrapper +from flupdt.common import bash_wrapper import shutil diff --git a/flupdt/main.py b/flupdt/main.py new file mode 100644 index 0000000..7d1011e --- /dev/null +++ b/flupdt/main.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +from flupdt.flake_show import get_derivations +from flupdt.cli import parse_inputs + + +def main(): + args = parse_inputs() + print(get_derivations(args.flake_path)) + + +if __name__ == "__main__": + main() diff --git a/flupdt/model.py b/flupdt/model.py new file mode 100644 index 0000000..f1f5329 --- /dev/null +++ b/flupdt/model.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +from sqlalchemy import Column, Integer, String, ForeignKey, Table +from sqlalchemy.orm import relationship, backref +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + +author_publisher = Table( + "author_publisher", + Base.metadata, + Column("author_id", Integer, ForeignKey("author.author_id")), + Column("publisher_id", Integer, ForeignKey("publisher.publisher_id")), +) + +book_publisher = Table( + "book_publisher", + Base.metadata, + Column("book_id", Integer, ForeignKey("book.book_id")), + Column("publisher_id", Integer, ForeignKey("publisher.publisher_id")), +) + + +class Author(Base): + __tablename__ = "author" + author_id = Column(Integer, primary_key=True) + first_name = Column(String) + last_name = Column(String) + books = relationship("Book", backref=backref("author")) + publishers = relationship( + "Publisher", secondary=author_publisher, back_populates="authors" + ) + + +class Book(Base): + __tablename__ = "book" + book_id = Column(Integer, primary_key=True) + author_id = Column(Integer, ForeignKey("author.author_id")) + title = Column(String) + publishers = relationship( + "Publisher", secondary=book_publisher, back_populates="books" + ) + + +class Publisher(Base): + __tablename__ = "publisher" + publisher_id = Column(Integer, primary_key=True) + name = Column(String) + authors = relationship( + "Author", secondary=author_publisher, back_populates="publishers" + ) + books = relationship("Book", secondary=book_publisher, back_populates="publishers") diff --git a/main.py b/main.py deleted file mode 100644 index 1a85479..0000000 --- a/main.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python3 - -from app.flake_show import get_derivations - -print(get_derivations("/home/alice/.gitprojects/nix-dotfiles")) diff --git a/pyproject.toml b/pyproject.toml index 34b3618..deaa1f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,23 @@ [tool.poetry] -name = "app" +name = "flupdt" version = "0.1.0" -description = "" +description = """\ +Nix flake update diff checker. \ +Useful for validating and diffing flakes after updates. \ +Short for fl(ake) up(date) d(iff).\ +""" authors = ["Alice Huston "] license = "MIT" readme = "README.md" +packages = [{ include = "flupdt" }] [tool.poetry.dependencies] python = "^3.11" sqlalchemy = "^2.0.31" [tool.poetry.scripts] -main = "app.main:main" +flupdt = "flupdt.main:main" +flake-update-diff = "flupdt.main:main" [tool.poetry.group.dev.dependencies] ruff = "0.5.5" diff --git a/shell.nix b/shell.nix index f560e1b..cefe7a0 100644 --- a/shell.nix +++ b/shell.nix @@ -31,7 +31,7 @@ let }; # constructs the application in-place - app = pkgs.mkShell { inputsFrom = [ self.packages.${system}.myapp ]; }; + flupdt = pkgs.mkShell { inputsFrom = [ self.packages.${system}.flupdt ]; }; # pull in python/poetry dependencies poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; }; @@ -43,7 +43,7 @@ in inputsFrom = [ pre-commit rad-dev - app + flupdt poetry poetry2nixshell ];