Watchdir seems not working for plugins

91 views
Skip to first unread message

Edoardo Tenani

unread,
Mar 24, 2013, 8:06:43 PM3/24/13
to guar...@googlegroups.com
Hello everyone... I'm facing a strange behaviour in the --watchdir option from the command line. Seems that plugins ( for example Guard Sass ) completely ignore this setting. Is this possible? How can I fix this?

My setup is ( dots are only for brevity ):
  • the Guardfile is in /.../code/ruby/guard/projects/test
  • the project file are in /.../guardprojects/test
What I'm trying to do is to run guard from a not relevant path, watching the files in the project folder I specify using the specified Guardfile.

For example my guard command looks like this:
~$ guard start -G /.../code/ruby/guard/projects/test/Guardfile -w /.../guardprojects/test

So, from my home folder I'm starting guard with both an absolute path to the Guardfile and an absolute path to the watched folder ( which is different from Dir.pwd ).

For unknown reason the command do not work: files inside /.../guardprojects/test when modified raise an exception:
ERROR - Guard::Sass failed to achieve its <run_on_changes>, exception was:
> [#] Errno::ENOENT: No such file or directory - theme/sass/screen.sass

It seems that Guard watch the correct folder, while Guard Sass use only the relative path ( to the current folder in which Guard is started ) to perform their actions. I did not found the @watchdir variable to be passed to the plugin instance when created, so I'm reporting here this question.

Shell output for raised by the command: http://pastebin.com/qStnTuQG

My laptop:
  • Ubuntu 12.04 64 bit
  • RVM version 1.16.17
  • ruby version 1.8.7 (2012-10-12 patchlevel 371)
  • guard version 1.6.2
  • guard-sass 1.0.2

Thanks for your help, Edoardo

Michael Kessler

unread,
Mar 25, 2013, 3:26:46 AM3/25/13
to guar...@googlegroups.com
Hi Edoardo

Guard doesn't do much with the `--watchdir` option, it only passes it to Listen, which in turn uses it as base directory for catching file changes, but we do not change the current working directory. So if a Guard plugin shells out to an external tool, it still sees the directory from where you stared Guard as current directory and not the one you've specified as watchdir.

I'd try to change the work directory in your Guardfile by adding:

Dir.chdir(Guard.options[:watchdir]) if Guard.options[:watchdir]

and see if this solves your issue.

Michael
> --
> You received this message because you are subscribed to the Google Groups "guard-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to guard-dev+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Edoardo Tenani

unread,
Mar 25, 2013, 7:26:59 AM3/25/13
to guar...@googlegroups.com
That did it! :) Thanks a lot man! The solution is so damn easy but I struggled on it the whole afternoon yesterday! :) 

I tried the modified guardfile with some of the guard plugins and everything seems to work fine!

I'll report back in case I found some issue using this approach.

Again, thanks
Edoardo


2013/3/25 Michael Kessler <mi...@netzpiraten.ch>

Michael Kessler

unread,
Mar 25, 2013, 7:31:08 AM3/25/13
to guar...@googlegroups.com
Great to hear! Now the big question is, should Guard do this automatically when setting a watchdir? I think we should, but are there any implications that I do not see yet?

Any thoughts Rémy, Thibaud, Maher, …?

Rémy Coutable

unread,
Mar 25, 2013, 7:39:55 AM3/25/13
to guar...@googlegroups.com
Hey guys!

It's probably the most common use case (and thus the least surprising solution) when one's using the --watchdir option so I'm in favor of doing it by default and then if someone has a concern or a use case where it's not ideal, then we could add another option to disable the auto-chdir when --watchdir is present (something like --no-chdir-to-watchdir).

Thoughts?

Rémy

Edoardo Tenani

unread,
Mar 25, 2013, 12:37:28 PM3/25/13
to guar...@googlegroups.com
Why not handling it directly in plugins? That would be probably the cleanest way, as every plugin can or cannot need the watchdir argument ( I'm thinking about the guard-listen plugin, for example ). Unfortunately this approach needs work from plugin maintainers, so I don't know if is the best approach.

Michael Kessler

unread,
Mar 25, 2013, 2:00:00 PM3/25/13
to guar...@googlegroups.com
Edoardo,

> Why not handling it directly in plugins?

To not duplicate effort...

> That would be probably the cleanest way, as every plugin can or cannot need the watchdir argument ( I'm thinking about the guard-listen plugin, for example ).

Do you mean https://github.com/guard/listen or what is this guard-listen plugin you're talking about?

> Unfortunately this approach needs work from plugin maintainers, so I don't know if is the best approach.

From all existing Guard plugins only a bunch are actively maintained, so we preferably fix it within Guard.

Michael

Edoardo Tenani

unread,
Mar 26, 2013, 12:04:51 PM3/26/13
to guar...@googlegroups.com
> That would be probably the cleanest way, as every plugin can or cannot need the watchdir argument ( I'm thinking about the guard-listen plugin, for example ).
Do you mean https://github.com/guard/listen or what is this guard-listen plugin you're talking about?

Exactly. But maybe I misunderstood the purpose of that gem...

> Unfortunately this approach needs work from plugin maintainers, so I don't know if is the best approach.
From all existing Guard plugins only a bunch are actively maintained, so we preferably fix it within Guard.

I didn't know this... I guess that this will settle down my arguments :)

Thanks for your efforts!
Reply all
Reply to author
Forward
0 new messages