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

It would be nice to be able to run the plugin in Docker #1241

Closed
dhughes opened this issue Jun 3, 2022 · 7 comments
Closed

It would be nice to be able to run the plugin in Docker #1241

dhughes opened this issue Jun 3, 2022 · 7 comments

Comments

@dhughes
Copy link

dhughes commented Jun 3, 2022

Metadata

  • Operating system: Mac OS
  • Ruby version: varies
  • Node version: varies
  • @prettier/plugin-ruby or prettier gem version: 3.1.2
  • syntax_tree version: 2.7.1

Input

N/A

Suggestion

My team uses Docker for development. We run a set of containers that host our application and its assorted dependencies. We write code in whatever editor an engineer chooses on our local machines. Most of us use Macs, since that's what the company supplies, but one engineer prefers Windows. When provided to engineers, the Macs are minimally provisioned with most of the requirements for development work. Since we don't use Ruby on the host machine for development, the provisioning process doesn't install Ruby, which leaves engineers with the system Ruby as a default. Our application currently runs on Ruby 2.7.4. It uses gems that are difficult to install on Mac, such as rmagick (and I have no idea if they can be installed on Windows). The Mac system version of Ruby is currently 2.6.x, I think.

All of that is to say, our application won't even run on Mac OS out of the box due to the default Ruby version and gem challenges. Maybe it could be made to, but it'd be really difficult. I'm just trying to give some context on this request....

With plugin-ruby depending on a few gems, it seems logical that we could just add them to our gem file, bundle install, and start using Prettier with plugin-ruby. That works just fine in Docker, but not on our host Macs. (Side note: we don't have problems with Prettier for JS and JSX, since we happen to have a useful version of Node installed and there are no dependencies that won't install. For the ruby side of things, we can't even run a bundle install. This makes plugin-ruby unusable on the Mac side of things.

I did try manually installing Ruby 2.7.4 (which plugin-ruby supports) and manually installing the gems with gem install bundler prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs, but for some reason Prettier reports that some gems aren't installed and an error is printed:

% PRETTIER_RUBY_TIMEOUT_MS=5000 ./node_modules/.bin/prettier -w path/to/some_ruby_file.rb
path/to/some_ruby_file.rbCould not find rmagick-2.15.4, sassc-rails-2.1.1, sassc-2.0.1 in any of the sources
Run `bundle install` to install missing gems.

[error] path/to/some_ruby_file.rb: Error:
[error]       We failed to spawn our parser server. Please report this error on GitHub
[error]       at https://github.com/prettier/plugin-ruby. The error message was:
[error]
[error]         /Users/doughughes/Projects/foo/bar/node_modules/@prettier/plugin-ruby/src/getInfo.js:12
[error]   throw new Error(`Failed to get information from parse server in time. If this
[error]   ^
[error]
[error] Error: Failed to get information from parse server in time. If this
[error]     happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
[error]     variable beyond 5000.
[error]     at Timeout._onTimeout (/Users/doughughes/Projects/Adwerx/promote/node_modules/@prettier/plugin-ruby/src/getInfo.js:12:9)
[error]     at listOnTimeout (node:internal/timers:564:17)
[error]     at process.processTimers (node:internal/timers:507:7)
[error]
[error] Node.js v18.2.0
[error] .
[error]
[error]     at spawnServer (/Users/doughughes/Projects/foo/bar/node_modules/@prettier/plugin-ruby/src/parseSync.js:155:11)
[error]     at parseSync (/Users/doughughes/Projects/foo/bar/node_modules/@prettier/plugin-ruby/src/parseSync.js:180:18)
[error]     at Object.parse (/Users/doughughes/Projects/foo/bar/node_modules/@prettier/plugin-ruby/src/plugin.js:85:16)
[error]     at Object.parse (/Users/doughughes/Projects/foo/bar/node_modules/prettier/index.js:7361:23)
[error]     at coreFormat (/Users/doughughes/Projects/foo/bar/node_modules/prettier/index.js:8672:18)
[error]     at formatWithCursor2 (/Users/doughughes/Projects/foo/bar/node_modules/prettier/index.js:8864:18)
[error]     at Object.formatWithCursor (/Users/doughughes/Projects/foo/bar/node_modules/prettier/index.js:39174:12)
[error]     at format (/Users/doughughes/Projects/foo/bar/node_modules/prettier/cli.js:12043:24)
[error]     at formatFiles2 (/Users/doughughes/Projects/foo/bar/node_modules/prettier/cli.js:12122:20)
[error]     at async main (/Users/doughughes/Projects/foo/bar/node_modules/prettier/cli.js:12327:5)

We've been using plugin-ruby version 2.0.0 with a bit of success, though there are some formatting errors that prevent us from really using it as a team.

Anyhow, it would be really nice if, somehow, we could optionally use the Ruby dependencies for plugin-ruby in a Docker container. I realize this would be significantly slower, but it would help out team get over this hurdle.

FWIW, I tried creating a wrapper for Prettier that would just run the prettier command in docker. This works from the command line, but won't work for the code editors I've looked at (VS Code and Rubymine) since they both depend on the path in node_modules.

I'd be interested in suggestions you may have and wanted to share my teams experience. I appreciate the hard work on this project!

@kddnewton
Copy link
Member

I will attempt to fix this, but I highly suggest you just run with https://github.com/ruby-syntax-tree/syntax_tree, it's going to make your life a lot easier.

@brerx
Copy link

brerx commented Jun 28, 2022

We solved this by adding the prettier gem in the Gemfile

group :prettier do
  gem 'prettier'
end

and then running something like this in the Dockerfile

RUN bundle config set without default development production test && bundle install

RUN npm run prettier

(default development production test) being the other groups defined in the Gemfile.

This way, it just installs the prettier group without the other stuff you don't need for linting.

@darrenterhune
Copy link

We've been getting this same error in CircleCI and haven't been able to sort out a solution for it yet. It's working locally and in my editor (Atom) unsure on VSCode yet. But the main problem is CI.


Read 5191 lines of filename(s)
Bucket 0: assigning 1039 filename(s), total weight 1039
[error] Gemfile: Error: 
[error]       We failed to spawn our parser server. Please report this error on GitHub
[error]       at https://github.com/prettier/plugin-ruby. The error message was:
[error] 
[error]         /home/circleci/project/node_modules/@prettier/plugin-ruby/src/getInfo.js:12
[error]   throw new Error(`Failed to get information from parse server in time. If this
[error]   ^
[error] 
[error] Error: Failed to get information from parse server in time. If this
[error]     happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
[error]     variable beyond 5000.
[error]     at Timeout._onTimeout (/home/circleci/project/node_modules/@prettier/plugin-ruby/src/getInfo.js:12:9)
[error]     at listOnTimeout (node:internal/timers:559:17)
[error]     at processTimers (node:internal/timers:502:7)

I've tried about everything in terms of putting the gems in our Gemfile and/or gem install prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs.

I'm currently trying to bump ruby to 3.1.2 but because of some issues with psych I had to bump this gem and node package.

@kddnewton are you suggesting to replace plugin-ruby with syntax_tree for formatting ruby files?

@kddnewton
Copy link
Member

@darrenterhune, yeah I would highly suggest going with syntax tree for formatting. It is only Ruby, so the setup should be much simpler.

@kddnewton
Copy link
Member

@dhughes I'm really not sure what the issue is to be honest. It seems like you probably don't have all of the right gems installed OR they're not on a path that Ruby can find them. If they were on a path where Ruby could find them, you'd be able to run the stree executable. Can you do that in your docker environment?

Another thing to try for debugging would be bundle exec prettier ... which could help by setting the right environment variables.

@kddnewton
Copy link
Member

Also, #1232 (comment) might provide more insight into what you're facing.

@kddnewton
Copy link
Member

@dhughes can you let me know if this is still a problem once you have the dependencies? I'll close for now.

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

No branches or pull requests

4 participants