feature/flupdt #1

Merged
ahuston-0 merged 14 commits from feature/flupdt into main 2025-03-02 01:01:15 -05:00
12 changed files with 1183 additions and 41 deletions
Showing only changes of commit 257e30abcb - Show all commits

View File

@ -20,8 +20,19 @@ 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?
## 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`.
## Contributing
### Update procedure
Until `rad_development_python` (`rdp`) is in PyPI, we use the below steps to
ahuston-0 marked this conversation as resolved Outdated

remove rdp references

remove rdp references
update the lock file when there is an update to `rdp`.
1. Run `poetry lock` to update the poetry reference to GitHub
1. Run `poetry2nix lock` to update the overlay which Poetry2Nix uses
1. Run `nix flake check` to verify that all is building as expected

View File

@ -29,6 +29,7 @@ in
deadnix = {
enable = true;
settings = {
exclude = [ "poetry-git-overlay.nix" ];
noUnderscore = true; # ignore variables starting with underscore
# ignore lambda patterns (useful for passing args from ({}@args)
# to other functions)

12
flake.lock generated
View File

@ -96,11 +96,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1722179153,
"narHash": "sha256-ZJ75T0GWpLI4hoaL+YxueHD2pXG+VYpYtPJdwbkERVs=",
"lastModified": 1722589669,
"narHash": "sha256-rxDnGBZK+Sp3df20nCCRrtQzRrJKxY7KtcYNPo5yfg8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dcfb2878c687e5eb5fcbc5116969c45c85be34e2",
"rev": "42015a129a2ae1cd43a44490e8235d2b24c8a2e2",
"type": "github"
},
"original": {
@ -137,11 +137,11 @@
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1721039874,
"narHash": "sha256-XANsG9GYHip8pxZpbqKf/YGv8tIa0xTh289Y+WNBNfw=",
"lastModified": 1722515463,
"narHash": "sha256-6FVPz1WzHak65xJQg8tRjVyFEWMesGxfskKaCxDUnRk=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "d11c01e58587e5f21037ed6477465a7f26a32e27",
"rev": "8c25e871bba3f472e1569bbf6c0f52dcc34bf2a4",
"type": "github"
},
"original": {

View File

@ -42,25 +42,28 @@
nixpkgs,
flake-utils,
pre-commit-hooks,
poetry2nix,
...
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
pkgs = nixpkgs.legacyPackages.${system};
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
pkgs = nixpkgs.legacyPackages.${system}.extend poetry2nix.overlays.default;
overrides = poetry2nix.overrides.withDefaults (
_final: prev: {
# prefer binary wheels instead of source distributions for rust based dependencies
# avoids needing to build them from source. technically a security risk
polars = prev.polars.override { preferWheel = true; };
ruff = prev.ruff.override { preferWheel = true; };
greenlet = prev.greenlet.override { preferWheel = true; };
sqlalchemy = prev.sqlalchemy.override { preferWheel = true; };
}
pyOverrides = _final: prev: {
# prefer binary wheels instead of source distributions for rust based dependencies
# avoids needing to build them from source. technically a security risk
polars = prev.polars.override { preferWheel = true; };
ruff = prev.ruff.override { preferWheel = true; };
greenlet = prev.greenlet.override { preferWheel = true; };
sqlalchemy = prev.sqlalchemy.override { preferWheel = true; };
};
overlay = pkgs.lib.composeExtensions pyOverrides (
import ./poetry-git-overlay.nix { inherit pkgs; }
);
overrides = pkgs.poetry2nix.overrides.withDefaults overlay;
poetryConfig = {
inherit overrides;
@ -69,8 +72,9 @@
};
in
rec {
inherit pkgs;
packages = {
flupdt = poetry2nix.mkPoetryApplication poetryConfig // {
flupdt = pkgs.poetry2nix.mkPoetryApplication poetryConfig // {
develop = true;
};
default = self.packages.${system}.flupdt;
@ -81,8 +85,8 @@
devShells = import ./shell.nix {
inherit
self
pkgs
poetryConfig
poetry2nix
inputs
system
checks

View File

@ -8,7 +8,7 @@ def parse_inputs():
"flake_path", metavar="flake-path", help="path to flake to evaluate"
)
parser.add_argument(
"--keep-hydra", action="store_true",help="allow evaluating Hydra jobs"
"--keep-hydra", action="store_true", help="allow evaluating Hydra jobs"
)
args = parser.parse_args()
return args

View File

@ -5,9 +5,10 @@ from typing import Optional
from flupdt.common import bash_wrapper
ahuston-0 marked this conversation as resolved Outdated

this should be common.py

this should be common.py
import re
drv_re = re.compile(r'.*(/nix/store/.*\.drv).*')
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")
def evaluate_output(path:str, output: str) -> Optional[str]:
def evaluate_output(path: str, output: str) -> Optional[str]:
logging.info(f"evaluating {output}")
out = bash_wrapper(f"nix eval {path}#{output}")
logging.debug(out[0])

View File

@ -7,8 +7,8 @@ import logging
import re
output_regexes = [
ahuston-0 marked this conversation as resolved Outdated

this should be common.py

this should be common.py
re.compile(r'checking derivation (.*)...'),
re.compile(r'checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\.')
re.compile(r"checking derivation (.*)..."),
re.compile(r"checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\."),
]
@ -31,11 +31,16 @@ def traverse_json_base(json_dict: dict, path: list[str]) -> list[str]:
def traverse_json(json_dict: dict) -> list[str]:
return traverse_json_base(json_dict, [])
def get_derivations_from_check(nix_path:str,path_to_flake:str)-> list[str]:
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going", path=path_to_flake)
def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
flake_check = bash_wrapper(
f"{nix_path} flake check --verbose --keep-going", path=path_to_flake
)
if flake_check[2] != 0:
logging.warn("nix flake check returned non-zero exit code, collecting all available outputs")
error_out = flake_check[1].split('\n')
logging.warn(
"nix flake check returned non-zero exit code, collecting all available outputs"
)
error_out = flake_check[1].split("\n")
possible_outputs = filter(lambda s: s.startswith("checking"), error_out)
derivations = []
for output in possible_outputs:
@ -47,20 +52,23 @@ def get_derivations_from_check(nix_path:str,path_to_flake:str)-> list[str]:
derivations += [match.groups()[0]]
return derivations
def get_derivations(path_to_flake: str) -> list[str]:
nix_path = shutil.which("nix")
derivations = []
if nix_path is None:
raise RuntimeError("nix is not available in the PATH, please verify that it is installed")
raise RuntimeError(
"nix is not available in the PATH, please verify that it is installed"
)
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
if flake_show[2] != 0:
logging.error("flake show returned non-zero exit code")
logging.warn("falling back to full evaluation via nix flake check")
derivations = get_derivations_from_check(nix_path, path_to_flake)
derivations = get_derivations_from_check(nix_path, path_to_flake)
else:
flake_show_json = json.loads(flake_show[0])
derivations = traverse_json(flake_show_json)
for i in range(len(derivations)):
if derivations[i].startswith("nixosConfigurations"):
derivations[i] += ".config.system.build.toplevel"
derivations[i] += ".config.system.build.toplevel"
return derivations

View File

@ -5,13 +5,19 @@ from flupdt.cli import parse_inputs
from flupdt.flake_eval import evaluate_output
from flupdt.common import configure_logger
import logging
ahuston-0 marked this conversation as resolved Outdated

should be common.py

should be common.py
import rad_development_python as rd
def main():
configure_logger("INFO")
rd.configure_logger("INFO")
args = parse_inputs()
print("hi")
flake_path = args.flake_path
derivations = get_derivations(flake_path)
if not args.keep_hydra and len(list(filter(lambda s: s.startswith("hydraJobs"), derivations))) > 0:
if (
not args.keep_hydra
and len(list(filter(lambda s: s.startswith("hydraJobs"), derivations))) > 0
):
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
derivations = filter(lambda s: not s.startswith("hydraJobs"), derivations)
logging.info(f"derivations: {list(derivations)}")

12
poetry-git-overlay.nix Normal file
View File

@ -0,0 +1,12 @@
{ pkgs }:
final: prev: {
rad-development-python = prev.rad-development-python.overridePythonAttrs (_: {
src = pkgs.fetchgit {
url = "https://github.com/RAD-Development/rad-development-python";
rev = "4ee897ab983234eda6f12dfcfd822bffab01f740";
sha256 = "1hxdqnjrznx0c07qn5cdx7p7f7sz2ysydx5l82w0r7rdadj69ik2";
};
});
}

1098
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ packages = [{ include = "flupdt" }]
[tool.poetry.dependencies]
python = "^3.11"
sqlalchemy = "^2.0.31"
rad_development_python = {git = "https://github.com/RAD-Development/rad-development-python", branch = "feature/nix"}
ahuston-0 marked this conversation as resolved Outdated

remove rdp referecnes

remove rdp referecnes
[tool.poetry.scripts]
flupdt = "flupdt.main:main"

View File

@ -1,16 +1,13 @@
{
self,
pkgs,
poetryConfig,
poetry2nix,
inputs,
checks,
system,
...
}:
let
inherit (inputs) nixpkgs;
pkgs = nixpkgs.legacyPackages.${system};
# construct the shell provided by pre-commit for running hooks
pre-commit = pkgs.mkShell {
@ -34,9 +31,14 @@ let
flupdt = pkgs.mkShell { inputsFrom = [ self.packages.${system}.flupdt ]; };
# pull in python/poetry dependencies
poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
poetry = pkgs.mkShell {
packages = [
pkgs.poetry
pkgs.poetry2nix.cli
];
};
poetry2nixshell = poetry2nix.mkPoetryEnv poetryConfig;
poetry2nixshell = pkgs.poetry2nix.mkPoetryEnv poetryConfig;
in
{
default = pkgs.mkShell {