Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: parse manifest template to RawManifest, use toml_edit #1333

Merged
merged 47 commits into from
May 22, 2024

Conversation

oxcabe
Copy link
Contributor

@oxcabe oxcabe commented Apr 17, 2024

Proposed Changes

This PR replaces uses of String::replace for editing and populating placeholders in manifest.toml to use toml_edit instead.

Closes #1064.

Release Notes

N/A.

@oxcabe oxcabe force-pushed the refactor/flox-init/toml-edit-replace branch from 1f8aa58 to 41631b9 Compare April 19, 2024 12:32
@mkenigs
Copy link
Contributor

mkenigs commented Apr 26, 2024

Just a heads up, this is going to have merge conflicts with #1299

@oxcabe
Copy link
Contributor Author

oxcabe commented Apr 26, 2024

Should I finish this ASAP?

@mkenigs
Copy link
Contributor

mkenigs commented Apr 26, 2024

I think honestly it would be better to wait till 1299 gets in and then deal with conflicts :/

@oxcabe oxcabe marked this pull request as ready for review May 8, 2024 22:43
@oxcabe
Copy link
Contributor Author

oxcabe commented May 8, 2024

The implementation design and approach taken could be reviewed. A few failing tests have to be checked before we consider this functionally correct, though.

@oxcabe oxcabe requested review from ysndr and mkenigs May 8, 2024 22:45
ysndr
ysndr previously requested changes May 9, 2024
Copy link
Contributor

@ysndr ysndr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a lot of suggestions, but i think this looks pretty good already. No major concerns. Looking forward to leave string substitution behind soon!

cli/flox-rust-sdk/src/models/environment/mod.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/environment/mod.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
@oxcabe
Copy link
Contributor Author

oxcabe commented May 9, 2024

Thanks! I'll address them later on today 👍

oxcabe and others added 3 commits May 9, 2024 17:00
Co-authored-by: Yannik Sander <7040031+ysndr@users.noreply.github.com>
## Proposed Changes

Resolve any dots in paths when determining the environment name so that
`init -d` works when the final path item is a single or double dot.

We can't use `canonicalize` because it will return an error if the path
doesn't exits which breaks our existing behaviour for init against a
directory that doesn't yet exist:

-
https://doc.rust-lang.org/std/path/struct.Path.html#method.canonicalize

The following implementations all don't resolve a single `.` to a name:

- https://doc.rust-lang.org/std/path/fn.absolute.html
- https://docs.rs/path-absolutize/latest/path_absolutize/
- https://docs.rs/path-clean/latest/path_clean/
-
https://github.com/rust-lang/cargo/blob/0.79.0/crates/cargo-util/src/paths.rs#L76-L109

So the `path-dedot` crate seemed like the most appropriate choice.

I considered adding unit tests for this behaviour but the integration
tests are actually very fast for this functionality, make it simpler to
test changing current working directory in the context of running the
CLI, and give us some reassurance that we haven't affected the
downstream behaviour of creating an environment.

Output of the new tests before the implementation was added:

✗ c2.1: `flox init` with `--dir .` will create an environment in current
working directory. [37]
       tags: init
(from function `assert_success' in file
/nix/store/dhghqmkjk7fqpdbz71clvbh5zxp6p3lf-bats-with-libraries-1.10.0/share/bats/bats-assert/src/assert_success.bash,
line 42,
        in test file init.bats, line 115)
         `assert_success' failed
       ❌ ERROR: Can't init in root

       -- command failed --
       status : 1
       output : ❌ ERROR: Can't init in root
       --

       Last output:
       ❌ ERROR: Can't init in root
✗ c2.1: `flox init` with `--dir ..` will create an environment in parent
working directory. [39]
       tags: init
(from function `assert_success' in file
/nix/store/dhghqmkjk7fqpdbz71clvbh5zxp6p3lf-bats-with-libraries-1.10.0/share/bats/bats-assert/src/assert_success.bash,
line 42,
        in test file init.bats, line 125)
         `assert_success' failed

/var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.VLMq5i/bats-run-ZpmkUP/test/9/test/other
/var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.VLMq5i/bats-run-ZpmkUP/test/9/test
/var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.VLMq5i/flox-cli-tests-2WdbV0
       ❌ ERROR: Can't init in root

       -- command failed --
       status : 1
       output : ❌ ERROR: Can't init in root
       --

       Last output:
       ❌ ERROR: Can't init in root

## Release Notes

Support `flox init -d` where the final part of the path is a `.` or
`..`.
-  Provide tokio to functions called by `spin_with_delay`

The catalog client uses `reqwest` which uses `tokio::time::sleep`. When
the catalog is used in combination with our `spin_with_delay` function,
    this causes a panic:
    ```
there is no reactor running, must be called from the context of a Tokio
1.x runtime
    ```

    Enter the tokio runtime context in the thread spawned by
    `spin_with_delay` to avoid the panic.

- Add functional test for catalog install. Note that this is still
skipped since we're waiting for changes serverside
@oxcabe
Copy link
Contributor Author

oxcabe commented May 12, 2024

How should we approach unit tests?

@oxcabe oxcabe requested review from ysndr and mkenigs May 12, 2024 20:44
@mkenigs
Copy link
Contributor

mkenigs commented May 14, 2024

How should we approach unit tests?

I would add a bunch of tests for new_documented, and I would lean towards checking assertions about RawManifest::to_string rather than RawManifest itself, because we care how it looks to users. Tests cases will probably be brittle and have large walls of text, but I don't think that's much of an issue because it should be easy to update, and I think that's the best way to ensure we get stuff like spacing right. Others may disagree but that's my take 🤷

I would probably add cases for:

  • With no customizations, we get what we expect
  • use_catalog works and doesn't break heading
  • non-empty packages works
  • hook_on_activate works
  • Having some profile scripts works

Copy link
Contributor

@mkenigs mkenigs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look good! Just a few minor comments left, only one blocking

cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Show resolved Hide resolved
cli/flox-rust-sdk/src/models/manifest.rs Outdated Show resolved Hide resolved
@oxcabe oxcabe requested a review from mkenigs May 21, 2024 15:01
@mkenigs mkenigs dismissed stale reviews from ysndr and themself May 21, 2024 19:52

stale

Copy link
Contributor

@mkenigs mkenigs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@mkenigs mkenigs enabled auto-merge May 21, 2024 19:54
@mkenigs
Copy link
Contributor

mkenigs commented May 21, 2024

The newline broke some tests

Co-authored-by: Matthew Kenigsberg <matthew@floxdev.com>
auto-merge was automatically disabled May 21, 2024 19:58

Head branch was pushed to by a user without write access

@oxcabe
Copy link
Contributor Author

oxcabe commented May 21, 2024

The newline broke some tests

Got it. I'll fix them.

@oxcabe oxcabe requested a review from mkenigs May 22, 2024 10:55
@mkenigs mkenigs enabled auto-merge May 22, 2024 14:55
@mkenigs mkenigs added this pull request to the merge queue May 22, 2024
Merged via the queue into flox:main with commit c4c62b4 May 22, 2024
21 of 29 checks passed
@oxcabe oxcabe deleted the refactor/flox-init/toml-edit-replace branch May 22, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use toml_edit instead of custom templating
6 participants