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

pathutil.rb:502: warning: Using the last argument as keyword parameters is deprecated #4

Open
3 of 18 tasks
kindrowboat opened this issue Jun 9, 2020 · 7 comments · May be fixed by #5
Open
3 of 18 tasks

pathutil.rb:502: warning: Using the last argument as keyword parameters is deprecated #4

kindrowboat opened this issue Jun 9, 2020 · 7 comments · May be fixed by #5

Comments

@kindrowboat
Copy link

  • I tried updating to the latest version
    • I can't, there is an issue
    • This is about an < latest
      • I understand older versions may be unsupported
  • I Am on Windows
    • Ubuntu Bash on Windows
    • Fedora Bash on Windows
    • Other Bash on Windows
  • I Am on Linux
    • Ubuntu
    • Fedora
    • CentOS
    • Redhat
    • Debian
  • I am on macOS 10.13
  • I am on macOS 10.14
  • I'm on Docker
    • I understand Docker may be unsupported

Description

Using ruby 2.7.0, when starting a local development jekyll server (which uses pathutil 16.2), I see the following warning:

/home/motevets/workspace/test/vendor/bundle/ruby/2.7.0/gems/pathutil-0.16.2/lib/pathutil.rb:502: warning: Using the last argument as keyword parameters is deprecated.

It looks like this deprecation warning is in preparation for ruby 3. See "Separation of positional and keyword arguments in Ruby 3.0".

Steps

  • install ruby 2.7.0
  • install latest Jekyll
  • create new Jekyll project, which will use the latest pathutil (16.2)
  • run local development server

Output

gem install jekyll #latest
git init test
cd test
jekyll new .
bundle exec jekyll serve
Configuration file: /home/motevets/workspace/test/_config.yml
            Source: /home/motevets/workspace/test
       Destination: /home/motevets/workspace/test/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
                    done in 0.389 seconds.
/home/motevets/workspace/test/vendor/bundle/ruby/2.7.0/gems/pathutil-0.16.2/lib/pathutil.rb:502: warning: Using the last argument as keyword parameters is deprecated
 Auto-regeneration: enabled for '/home/motevets/workspace/test'
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

Note the warning after the Jekyll Feed step.

Expected

Configuration file: /home/motevets/workspace/test/_config.yml
            Source: /home/motevets/workspace/test
       Destination: /home/motevets/workspace/test/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
                    done in 0.389 seconds.
 Auto-regeneration: enabled for '/home/motevets/workspace/test'
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

Note the lack warning after the Jekyll Feed step.

kindrowboat added a commit to kindrowboat/pathutil that referenced this issue Jun 9, 2020
In ruby 2.7, using the last argument as keyword parameters became
deprecated in preparation for ruby 3.0. When running the tests, we saw
numerous deprecation warnings. This commit fixes up those deprecation
warnings by explicitly passing the last argument(s) as keyword
argument(s).

See: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

Fixes envygeeks#4

Side note: this commit did not fix the `#binread` method because it was
untested, and when attempting to add tests, we got the following failing
test:

```
1) Pathutil#binread when set to normalize should use encode to convert CRLF to LF
   Failure/Error:
     File.binread(self, *args, kwd).encode({
       :universal_newline => true
     })

   TypeError:
     no implicit conversion of Hash into Integer
   # ./lib/pathutil.rb:509:in `binread'
   # ./lib/pathutil.rb:509:in `binread'
   # ./spec/tests/lib/pathutil_spec.rb:943:in `block (4 levels) in <top (required)>'
```

...which appears to be occuring because of an interface mismatch as
`IO#binread` does not take keyword arguments.

https://ruby-doc.org/core-2.7.1/IO.html#method-c-binread
@kindrowboat kindrowboat linked a pull request Jun 9, 2020 that will close this issue
5 tasks
@ISSOtm
Copy link

ISSOtm commented May 9, 2021

Apparently this is now causing the gem to outright break under Ruby 3.0.0...

jekyll 3.9.0 | Error:  no implicit conversion of Hash into Integer
/SNIP/vendor/bundle/ruby/3.0.0/gems/pathutil-0.16.2/lib/pathutil.rb:502:in `read': no implicit conversion of Hash into Integer (TypeError)

@nis130
Copy link

nis130 commented May 18, 2021

@ISSOtm I am also stuck with the same issue, did you find any solution for that?

@ISSOtm
Copy link

ISSOtm commented May 18, 2021

I reverted to bundler-2.7. I could fix that issue by using the new keyword syntax (*args or something like that IIRC), but it stumbled further, and I'm not proficient enough in Ruby to fix that one.

@harsh183
Copy link

I got this on a jekyll project as well with ruby 3.0.1. Reverted to Ruby2.7 for the time being but I hope this is fixed soon.

@nis130
Copy link

nis130 commented May 22, 2021

I was able to make it work on ruby 3.0.1 by the changes suggested in this #5 PR.

@danman01
Copy link

More explicit steps for those intimidated by the process of editing a file such as pathutil.rb ...

  • in the error output stack trace, take note of the location of the pathutil.rb file. For users of rbenv, you can open the file for editing with a command that looks something like:
    vim /home/<YOUR-USERNAME>/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/pathutil-0.16.2/lib/pathutil.rb

Then find occurrences of kwd that are changed to **kwd as mentioned in the issue #5 commit 3451a10#diff-5372ed4218752c3077f741296df57da67756dca1d282c64fcced144fc82cd204

For example, the read method starting around line 498 will now look like (also added a comment referencing the commit above):

def read(*args, **kwd)
    kwd[:encoding] ||= encoding

    if normalize[:read]
      # updates based on https://github.com/envygeeks/pathutil/pull/5/commits/3451a10c362fc867b20c7e471a551b31c40a0246#diff-5372ed4218752c3077f741296df57da67756dca1d282c64fcced144fc82cd204
      File.read(self, *args, **kwd).encode(universal_newline: true)
    else
      File.read(
        self, *args, **kwd
      )
    end
  end

Repeat for other occurrences, save, then try something like bundle exec jekyll serve or whatever command you were doing...good luck .

That updated file is now saved just on your system, under that specific ruby version.

@danielhjacobs
Copy link

Jekyll v3.9.2 finally removed Jekyll's main dependency on pathutil (jekyll/jekyll@55e3648). Now that Github Pages updated to that version of Jekyll (see github/pages-gem#833), this issue shouldn't affect Github pages or Jekyll anymore.

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 a pull request may close this issue.

6 participants