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

quote open command with Filename.quote_command and return Lwt process #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nguermond
Copy link

Addresses issue #1.
Changes:

  • return an Lwt process
  • use Filename.quote_command instead of sprintf to quote
  • use Lwt_process.exec builtin functionality to redirect output to /dev/null

I similarly ran into the issue that strings were incorrectly quoted. For example, the original code produced

Format.sprintf "%S" "hél'lo world";;
- : string = "\"h\\195\\169l'lo world\""

but the system does not recognize this filename. We should instead have

Filename.quote "hél'lo world";;
- : string = "'hél'\\''lo world'"

@nguermond
Copy link
Author

Alternatively, you could add a wrapper in_default_app : string -> bool for backwards compatibility?

@smolkaj
Copy link
Owner

smolkaj commented Jun 9, 2023

Thanks for the PR, Nathan. Very nice to get the quoting issue fixed and to have Lwt support.

Two requests:

  1. I would like to keep the non-Lwt version around as well, for those of us who do not use it
  2. Can we make the Lwt dependencies opt-in, so it's only required for people who wish the Lwt version of the function?

Regarding (2), unfortunately I am not an expert on how to best achieve this since I don't use Lwt/Async myself, but I know that many libraries provide multiple packages to achieve this somehow...say open and open.lwt/open_lwt. Perhaps you would know?

Regarding (1), perhaps Open.in_default_app and Open.in_default_app_with_lwt / Open.WithLwt.in_default_app or something like that? I don't feel strongly, just footing ideas.

@nguermond
Copy link
Author

I factored this in two packages, open and open_lwt. The interface is now

val in_default_app : string -> bool (* or bool Lwt.t *)
val in_default_app_status : string -> Unix.process_status (* or Unix.process_status Lwt.t *)

I also had to update the tests, which now build conditionally on dependencies. (I couldn't figure out the Core dependency so I just replaced some of the code with Stdlib builtins).

@nguermond nguermond reopened this Jun 10, 2023
Copy link
Owner

@smolkaj smolkaj left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great! Just a few nits / comments.

src/open_lwt.ml Outdated
@@ -0,0 +1,11 @@

Copy link
Owner

Choose a reason for hiding this comment

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

Nit: remove empty line.

Copy link
Owner

Choose a reason for hiding this comment

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

Same for the other new files

@@ -1,11 +1,32 @@
(executable
(name graphviz)
(libraries open core))
(enabled_if (>= %{ocaml_version} 4.14.0))
Copy link
Owner

Choose a reason for hiding this comment

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

Out of curiosity, why do we neee OCaml 4.14 here?

dune-project Outdated
(generate_opam_files true)

(name open)
(version 0.2.2)
(version 0.3.0)
(license MIT)
(source (github smolkaj/ocaml-open))
(authors "Steffen Smolka <[email protected]>")
Copy link
Owner

Choose a reason for hiding this comment

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

Feel free to add yourself as an author.

|> Open.in_default_app
|> Format.printf "file opened successfully: %b\n"
;;
let _ =
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: let ()

Copy link
Owner

Choose a reason for hiding this comment

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

Same for the let version

@smolkaj smolkaj mentioned this pull request Jun 11, 2023
@smolkaj
Copy link
Owner

smolkaj commented Jun 11, 2023

Unfortunately the continuous integration seems to no longer be working, I opened #3 to track that. I can give this PR a try manually so we don't have to block on that issue.

@smolkaj
Copy link
Owner

smolkaj commented Jun 11, 2023

Unfortunately the continuous integration seems to no longer be working, I opened #3 to track that. I can give this PR a try manually so we don't have to block on that issue.

It works fine on my machine, macOS, with Ocaml 5.0

@nguermond
Copy link
Author

Actually I've been having issues getting dune to skip the examples when lwt is not installed, so I will have to find a way around that.

@smolkaj
Copy link
Owner

smolkaj commented Jun 13, 2023

Unfortunately the continuous integration seems to no longer be working, I opened #3 to track that. I can give this PR a try manually so we don't have to block on that issue.

Fixed

@smolkaj
Copy link
Owner

smolkaj commented Jun 13, 2023

Actually I've been having issues getting dune to skip the examples when lwt is not installed, so I will have to find a way around that.

I actually think that might be fine? I just don't want the non-Lwt opam package to depend on lwt, and you have achieved that AFAIK.

@nguermond
Copy link
Author

I'm afraid opam CI will complain (but not sure).
Funnily enough this pull request for dune from a few days ago would fix this issue if you're willing to wait for it to be merged and depend on the latest version of dune.
Otherwise I can just remove the lwt tests for now.

@smolkaj
Copy link
Owner

smolkaj commented Jun 14, 2023

I'd be happy either way. No rush on my side.

@smolkaj
Copy link
Owner

smolkaj commented Jul 3, 2023

Looks like dune 3.9 with the patch you mentioned just got release :)

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.

2 participants