Skip to content

Commit

Permalink
nix-flake: Fix scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Renkhoff <[email protected]>
  • Loading branch information
Irockasingranite committed Jan 22, 2024
1 parent 2ee7d5e commit 958a777
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/west-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ west-commands:
- name: bridle-export
class: BridleExport
help: export Bridle installation as a CMake config package

- file: scripts/west_commands/nix_update.py
commands:
- name: nix-update
Expand Down
6 changes: 3 additions & 3 deletions scripts/west_commands/nix_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def do_add_parser(self, parser_adder):
return parser

def do_run(self, args, unknown_args):

## Update Python dependencies from requirements.txt files

# Get paths of requirements.txt we care about
Expand All @@ -44,13 +44,13 @@ def do_run(self, args, unknown_args):
# Generate nix expression based on requirements
log.inf(f"Parsing python dependencies in {(', ').join(requirements_paths)}")
nix_expr = generate_nix_from_paths(requirements_paths)

# Write nix expression to file
nix_expr_path = os.path.join(bridle_path, 'nix/python-dependencies.nix')
log.inf(f"Writing nix expression for python dependencies into {nix_expr_path}")
with open(nix_expr_path, "w") as file:
file.write(nix_expr)

## Update workspace flake from west manifest

# Generate flake contents
Expand Down
10 changes: 5 additions & 5 deletions scripts/west_commands/nix_update_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from packaging.requirements import Marker

def python_dependencies(path: str):

# Get raw file contents
with open(path, "r") as file:
contents = file.read()
Expand Down Expand Up @@ -54,7 +54,7 @@ def filter_special_cases(names: str):
"clang-format", # Included as an application directly from nixpkgs
"gitlint", # Included as an application directly from nixpkgs
]

return [n for n in names if not n in special_cases]


Expand All @@ -78,15 +78,15 @@ def generate_nix_from_paths(paths: [str]):
return nix_list(deps)

def main():

# Handle arguments
if len(sys.argv) < 3:
print("Usage: python nix_update_python.py <output> <input> [<input>]")
return

output_filename = sys.argv[1]
paths = sys.argv[2:]

nix_list = generate_nix_from_paths(paths)

# Format as nix expression and write to file
Expand Down
6 changes: 4 additions & 2 deletions scripts/west_commands/nix_update_workspace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import parse

from west.manifest import Manifest
from west.manifest import Project
import parse

def inputs_str(ps: [Project]):
# Assume all our inputs are github hosted
Expand Down Expand Up @@ -131,7 +133,7 @@ def main():

# Write output
with open(output_filename, "w") as file:
file.write(flake_str(manifest))
file.write(flake_str)

return

Expand Down

0 comments on commit 958a777

Please sign in to comment.