Skip to content

Commit

Permalink
Merge pull request #180 from figsoda/escape
Browse files Browse the repository at this point in the history
fix attribute name escaping
  • Loading branch information
Mic92 committed Aug 2, 2023
2 parents e880e38 + cc8d7d2 commit e10a733
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion nix_update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def nix_shell(options: Options) -> None:
check=False,
)
else:
expr = f"with import {options.import_path} {{}}; mkShell {{ buildInputs = [ {options.attribute} ]; }}"
expr = f"let pkgs = import {options.import_path} {{}}; in pkgs.mkShell {{ buildInputs = [ pkgs.{options.escaped_attribute} ]; }}"
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, "default.nix")
with open(path, "w") as f:
Expand Down
4 changes: 3 additions & 1 deletion nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def eval_expression(


def eval_attr(opts: Options) -> Package:
expr = eval_expression(opts.import_path, opts.attribute, opts.flake, opts.system)
expr = eval_expression(
opts.import_path, opts.escaped_attribute, opts.flake, opts.system
)
cmd = [
"nix",
"eval",
Expand Down
2 changes: 1 addition & 1 deletion nix_update/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class Options:
extra_flags: List[str] = field(default_factory=list)

def __post_init__(self) -> None:
self.attribute = json.dumps(self.attribute)
self.escaped_attribute = json.dumps(self.attribute)
4 changes: 2 additions & 2 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def replace_hash(filename: str, current: str, target: str) -> None:

def get_package(opts: Options) -> str:
return (
f'(let flake = builtins.getFlake "{opts.import_path}"; in flake.packages.${{builtins.currentSystem}}.{opts.attribute} or flake.{opts.attribute})'
f'(let flake = builtins.getFlake "{opts.import_path}"; in flake.packages.${{builtins.currentSystem}}.{opts.escaped_attribute} or flake.{opts.escaped_attribute})'
if opts.flake
else f"(import {opts.import_path} {disable_check_meta(opts)}).{opts.attribute}"
else f"(import {opts.import_path} {disable_check_meta(opts)}).{opts.escaped_attribute}"
)


Expand Down
3 changes: 1 addition & 2 deletions tests/test_flake.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ def test_main(helpers: conftest.Helpers) -> None:
check=True,
).stdout.strip()
print(commit)
assert version in commit
assert "crate" in commit
assert f"crate: 8.0.0 -> {version}" in commit
assert "https://diff.rs/fd-find/8.0.0/" in commit
3 changes: 1 addition & 2 deletions tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def test_main(helpers: conftest.Helpers) -> None:
check=True,
).stdout.strip()
print(commit)
assert version in commit
assert "pypi" in commit
assert f"pypi: 2.0.0 -> {version}" in commit
assert (
f"https://github.com/Mic92/python-mpd2/blob/{version}/doc/changes.rst"
in commit
Expand Down

0 comments on commit e10a733

Please sign in to comment.