format python, add poetry shell
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
		@@ -21,7 +21,7 @@ def configure_logger(level: str = "INFO") -> None:
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def bash_wrapper(command: str, path:str = '.') -> tuple[str, int]:
 | 
					def bash_wrapper(command: str, path: str = ".") -> tuple[str, int]:
 | 
				
			||||||
    """Execute a bash command and capture the output.
 | 
					    """Execute a bash command and capture the output.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Args:
 | 
					    Args:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,13 +4,17 @@ import json
 | 
				
			|||||||
from app.common import bash_wrapper
 | 
					from app.common import bash_wrapper
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def traverse_json_base(json_dict: dict, path: list[str]):
 | 
					def traverse_json_base(json_dict: dict, path: list[str]):
 | 
				
			||||||
    final_paths = []
 | 
					    final_paths = []
 | 
				
			||||||
    for (key,value) in json_dict.items():
 | 
					    for key, value in json_dict.items():
 | 
				
			||||||
        if isinstance(value, dict):
 | 
					        if isinstance(value, dict):
 | 
				
			||||||
            keys = value.keys()
 | 
					            keys = value.keys()
 | 
				
			||||||
            if 'type' in keys and value['type'] in ['nixos-configuration','derivation']:
 | 
					            if "type" in keys and value["type"] in [
 | 
				
			||||||
                final_paths += ['.'.join(path + [key])]
 | 
					                "nixos-configuration",
 | 
				
			||||||
 | 
					                "derivation",
 | 
				
			||||||
 | 
					            ]:
 | 
				
			||||||
 | 
					                final_paths += [".".join(path + [key])]
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                final_paths += traverse_json_base(value, path + [key])
 | 
					                final_paths += traverse_json_base(value, path + [key])
 | 
				
			||||||
    return final_paths
 | 
					    return final_paths
 | 
				
			||||||
@@ -19,6 +23,7 @@ def traverse_json_base(json_dict:dict ,path: list[str]):
 | 
				
			|||||||
def traverse_json(json_dict: dict):
 | 
					def traverse_json(json_dict: dict):
 | 
				
			||||||
    return traverse_json_base(json_dict, [])
 | 
					    return traverse_json_base(json_dict, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_derivations(path_to_flake: str):
 | 
					def get_derivations(path_to_flake: str):
 | 
				
			||||||
    nix_path = shutil.which("nix")
 | 
					    nix_path = shutil.which("nix")
 | 
				
			||||||
    flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
 | 
					    flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								flake.nix
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								flake.nix
									
									
									
									
									
								
							@@ -23,7 +23,7 @@
 | 
				
			|||||||
      self,
 | 
					      self,
 | 
				
			||||||
      nixpkgs,
 | 
					      nixpkgs,
 | 
				
			||||||
      flake-utils,
 | 
					      flake-utils,
 | 
				
			||||||
      poetry2nix,
 | 
					      pre-commit-hooks,
 | 
				
			||||||
      ...
 | 
					      ...
 | 
				
			||||||
    }@inputs:
 | 
					    }@inputs:
 | 
				
			||||||
    flake-utils.lib.eachDefaultSystem (
 | 
					    flake-utils.lib.eachDefaultSystem (
 | 
				
			||||||
@@ -31,11 +31,30 @@
 | 
				
			|||||||
      let
 | 
					      let
 | 
				
			||||||
        # see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
 | 
					        # see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
 | 
				
			||||||
        pkgs = nixpkgs.legacyPackages.${system};
 | 
					        pkgs = nixpkgs.legacyPackages.${system};
 | 
				
			||||||
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
 | 
					        poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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; };
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        poetryConfig = {
 | 
				
			||||||
 | 
					          inherit overrides;
 | 
				
			||||||
 | 
					          projectDir = self;
 | 
				
			||||||
 | 
					          python = pkgs.python312;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
      in
 | 
					      in
 | 
				
			||||||
      rec {
 | 
					      rec {
 | 
				
			||||||
        packages = {
 | 
					        packages = {
 | 
				
			||||||
          myapp = mkPoetryApplication { projectDir = self; };
 | 
					          myapp = poetry2nix.mkPoetryApplication poetryConfig // {
 | 
				
			||||||
 | 
					            develop = true;
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
          default = self.packages.${system}.myapp;
 | 
					          default = self.packages.${system}.myapp;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -44,6 +63,8 @@
 | 
				
			|||||||
        devShells = import ./shell.nix {
 | 
					        devShells = import ./shell.nix {
 | 
				
			||||||
          inherit
 | 
					          inherit
 | 
				
			||||||
            self
 | 
					            self
 | 
				
			||||||
 | 
					            poetryConfig
 | 
				
			||||||
 | 
					            poetry2nix
 | 
				
			||||||
            inputs
 | 
					            inputs
 | 
				
			||||||
            system
 | 
					            system
 | 
				
			||||||
            checks
 | 
					            checks
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,7 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  self,
 | 
					  self,
 | 
				
			||||||
 | 
					  poetryConfig,
 | 
				
			||||||
 | 
					  poetry2nix,
 | 
				
			||||||
  inputs,
 | 
					  inputs,
 | 
				
			||||||
  checks,
 | 
					  checks,
 | 
				
			||||||
  system,
 | 
					  system,
 | 
				
			||||||
@@ -24,6 +26,7 @@ let
 | 
				
			|||||||
      treefmt
 | 
					      treefmt
 | 
				
			||||||
      statix
 | 
					      statix
 | 
				
			||||||
      nixfmt-rfc-style
 | 
					      nixfmt-rfc-style
 | 
				
			||||||
 | 
					      ruff
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,6 +35,8 @@ let
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  # pull in python/poetry dependencies
 | 
					  # pull in python/poetry dependencies
 | 
				
			||||||
  poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
 | 
					  poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  poetry2nixshell = poetry2nix.mkPoetryEnv poetryConfig;
 | 
				
			||||||
in
 | 
					in
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  default = pkgs.mkShell {
 | 
					  default = pkgs.mkShell {
 | 
				
			||||||
@@ -40,6 +45,7 @@ in
 | 
				
			|||||||
      rad-dev
 | 
					      rad-dev
 | 
				
			||||||
      app
 | 
					      app
 | 
				
			||||||
      poetry
 | 
					      poetry
 | 
				
			||||||
 | 
					      poetry2nixshell
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user