config.yml~ (backup file) overrides config.yml #254

Open
waynedpj opened this Issue Dec 15, 2013 · 10 comments

Comments

Projects
None yet
3 participants

ahoy all,

i am sure this is a major brain misfire happening on my end, but for hours now i cannot get a single ruhoh project to read/use the config.yml (or config.json) file. so an example is that a simple declaration like this:


---
crazy:
  use: "ignore"

will not work and the crazy folder will be compiled.

anyway, i am wondering how i can get more debug information than is provided by bundle exec --verbose ruhoh -verbose compile?

for background, here is my setup:

$ bundle list --verbose
Gems included by the bundle:
  * bundler (1.3.5)
  * directory_watcher (1.4.1)
  * json (1.8.1)
  * mini_portile (0.5.2)
  * mustache (0.99.5)
  * nokogiri (1.6.0)
  * rack (1.5.2)
  * redcarpet (2.3.0)
  * ruhoh (2.6 4993b07)
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
$ more Gemfile
gem 'ruhoh', :git => 'git://github.com/ruhoh/ruhoh.rb.git'
gem 'json'

any help would in getting more info on the problem would be greatly appreciated.

peace, w

update: switching back to ruhoh 2.5 has things working again. so it seems that there may be a bug in the current 2.6/ master? if i can figure out how to get some more debug info i would be happy to help tracking this down.

Owner

plusjade commented Dec 15, 2013

@waynedpj I setup a test blog here and have successfully run it on my machine: https://github.com/ruhoh/test

You can see that the compiled folder does not have the file "hi". Can you run this on your end and see if you are able to successfully compile the test blog? Thanks!

@plusjade thanks for the quick response. i cloned your test repo and the first error was

$ ruhoh --version
/home/waynedpj/.gem/ruby/1.9.1/bundler/gems/ruhoh.rb-4993b07d12b5/lib/ruhoh.rb:3:in `require': cannot load such file -- json (LoadError)
    from /home/waynedpj/.gem/ruby/1.9.1/bundler/gems/ruhoh.rb-4993b07d12b5/lib/ruhoh.rb:3:in `<top (required)>'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /usr/lib64/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /home/waynedpj/.gem/ruby/1.9.1/bundler/gems/ruhoh.rb-4993b07d12b5/bin/ruhoh:9:in `<top (required)>'
    from /home/waynedpj/.gem/ruby/1.9.1/bin/ruhoh:23:in `load'
    from /home/waynedpj/.gem/ruby/1.9.1/bin/ruhoh:23:in `<main>'

which i had already experienced [https://github.com/ruhoh/ruhoh.rb/issues/238]. my temp solution of adding in gem 'json' to the Gemfile got ruhoh running again and it indeed works with your test blog (i.e. commenting/uncommenting use: "ignore" will enable/disable the crazy folder being included in the compiled output). so now i am thoroughly confused ;)

i even took your Gemfile, Gemfile.lock, config.yml files, copied them to a new+clean directory, created a crazy directory, tried it and no luck. i will restart just in case but this is very strange.

some ideas: is there some kind of caching happening? i also get this error

$ bundle exec ruhoh compile
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1
Compiling for environment: ''

when i run ruhoh.

is there anyway to see what ruhoh thinks is the config file? or do i need to start putting puts inside the code?

thanks again.

update: i believe i have found the problem. i use Emacs and it generates a config.yml~ backup file after each edit of config.yml. when that config.yml~ is there the config.yml is ignored and ruhoh acts like there is no config. is there a place where ruhoh could be ignoring ~ files and mistakenly ignore a file with the same name as the ~ file?

update 2: OK, ruhoh seems to be using the config.yml~ file instead of config.yml once it is created. thus changes made to config.yml~ are being picked up by ruhoh and the data in config.yml is ignored/overriden.

i do not understand the code well yet but perhaps the problem is here? unless ruhoh really wants to take config.anything as valid config files, not just config.yml or config.json? i assume it finds both and the cascade/merge order causes the ~ file to override the original.

thanks for the help and let me know what else i can do to help fix this possible bug.

peace, w

Owner

plusjade commented Dec 15, 2013

Cool! That's very good to know. I can update the config handler to account
for the issue in question. Feel free to give it a go as well if your
want!
On Dec 14, 2013 8:52 PM, "waynedpj" notifications@github.com wrote:

update 2: OK, ruhoh seems to be using the config.yml~ file instead of
config.yml once it is created. thus changes made to config.yml~ are being
picked up by ruhoh and the data in config.yml is ignored/overriden.

i do not understand the code well yet but perhaps the problem is herehttps://github.com/ruhoh/ruhoh.rb/blob/6fee3b185337df08a9c176ffadba36d85f8a93da/lib/ruhoh/config.rb#L57?
unless ruhoh really wants to take config.anything as valid config files,
not just config.yml or config.json? i assume it finds both and the
cascade/merge order causes the ~ file to override the original.

thanks for the help and let me know what else i can do to help fix this
possible bug.

peace, w


Reply to this email directly or view it on GitHubhttps://github.com/ruhoh/ruhoh.rb/issues/254#issuecomment-30598239
.

Il giorno sab, 14/12/2013 alle 20.58 -0800, Jade Dominguez ha scritto:

Cool! That's very good to know. I can update the config handler to
account
for the issue in question. Feel free to give it a go as well if your
want!

i have never programmed in Ruby nor used git, but i assume i will be

learning it using ruhoh. if i was going to clone the repo locally and
make some changes, how do i have Bundler use my local version of ruhoh?
can i just change the Gemfile to point to my local git file (e.g. gem
'ruhoh', :git => '/home/waynedpj/myruhoh/ruhoh.rb.git'?

thanks again.

peace, w

Owner

plusjade commented Dec 16, 2013

@waynedpj you'd use :path

gem 'ruhoh', :path => '/Users/jade/Dropbox/gems/ruhoh'

where the path points to wherever you git clone'd ruhoh.

Il giorno lun, 16/12/2013 alle 00.44 -0800, Jade Dominguez ha scritto:

@waynedpj you'd use :path

gem 'ruhoh', :path => '/Users/jade/Dropbox/gems/ruhoh'

where the path points to wherever you git clone'd ruhoh.


Reply to this email directly or view it on GitHub.

thanks again, i will do that and fix this bug (i think i already have
the code working here).

one other question: i cloned your repo locally and will apply my patch,
but then how do i submit the patch back to you? i looked at the GitHub
help docs and i see that i can do it via a pull request, but i would
rather not clone the repo on GitHub and locally. it seems to me easier
to simply have a clone of your main repo on my machine, create a branch
for my work, and submit the "branch changes" that have 2 cloned repos.
however, i am very new to git and perhaps it is easier to do it the
GitHub way? regardless, let me know your preference for how i should
work with your repo.

peace, w

Contributor

richtera commented Dec 16, 2013

This is related to #251. Basically the config file is loaded by name without the extension and during load time, there is no sorting about which extensions are preferred but it will use the alphabetically first extension for the particular name.

This code will find the first ID with the matching name and return it regardless of the extension.
It seems it should only allow "yml,yaml,json"

    def merge_data_file(key)
      realpaths = []
      paths.map{ |a| a['path'] }.each do |path|
        FileUtils.cd(path) { 
          match = Dir["*"].find { |id|
            File.exist?(id) &&
              FileTest.file?(id) &&
                id.gsub(/.[^.]+$/, '') == key
          }
          next unless match
          realpaths << File.realpath(match)
        }
      end

      return nil unless realpaths && !realpaths.empty?

      data = {}
      realpaths.each do |path|
        data = Ruhoh::Utils.deep_merge(data, (Ruhoh::Parse.data_file(path) || {}))
      end

      data
    end

So maybe like this:

    def merge_data_file(key)
      realpaths = []
      paths.map{ |a| a['path'] }.each do |path|
        FileUtils.cd(path) { 
          match = Dir["*"].find { |id|
            File.exist?(id) &&
              FileTest.file?(id) &&
                id.gsub(/.(yml|yaml|json)$/, '') == key
          }
          next unless match
          realpaths << File.realpath(match)
        }
      end

      return nil unless realpaths && !realpaths.empty?

      data = {}
      realpaths.each do |path|
        data = Ruhoh::Utils.deep_merge(data, (Ruhoh::Parse.data_file(path) || {}))
      end

      data
    end

I'll make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment