-
Notifications
You must be signed in to change notification settings - Fork 104
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
(SDK-144) Add option to run validate in parallel #144
Conversation
b5501f0
to
502fd09
Compare
@@ -15,6 +15,7 @@ module PDK::CLI | |||
|
|||
flag nil, :list, _('list all available validators') | |||
flag :a, 'auto-correct', _('automatically correct problems (where possible)') | |||
flag nil, :parallel, _('run validations in parallel') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the upcoming community release, we'll need to comment this line and hardcode line 74 with false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary to comment it out, can just make it a hidden flag (like --answer-file), so that it's still available for dev & testing but not shown in the help output.
e77123e
to
dcef710
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of refactors, and a behaviour change I'm not sure if we want.
Also, it looks like the de po file has been changed with some bad unicode substitutions (ü
=> Ÿ
etc)?
lib/pdk/cli/validate.rb
Outdated
mod_root = PDK::Util.module_root | ||
unless mod_root | ||
raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)') | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block can be replaced with PDK::CLI::Util.ensure_in_module!
however i'm not sure that we can to restrict validators to run in a module (for example, a module consumer would probably want to run pdk validate
from the root of their control repo to run validation on everything at once).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not view this as a behavior change. previously we had this code around the console command call in cli/exec.rb. This had to be brought out to this level because Dir.chdir changes the working dir of the process, not the thread.
@@ -14,13 +14,29 @@ def self.pattern | |||
'metadata.json' | |||
end | |||
|
|||
def self.spinner_text(targets = []) | |||
_('Checking metadata syntax (%{targets})') % { | |||
targets: targets.map { |t| Pathname.new(t).absolute? ? Pathname.new(t).relative_path_from(Pathname.pwd) : t }.join(' '), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is now being used in multiple places, we should probably split it out into a helper method (PDK::Util.targets_relative_to_pwd
or something) to avoid duplicating the logic.
@rodjek The de po file has been removed entirely from this build. It contained outdated strings which were causing problems when creating new threads. I did not see any way to update a po file while keeping the old strings. |
14aea40
to
c385e98
Compare
Lots has changed in the PDK and in the parallel validation, so it could use another look over before we merge.
c385e98
to
5e4ef24
Compare
lib/pdk/cli/spinner.rb
Outdated
|
||
# This is a placeholder until we integrate ansicon into Windows packaging | ||
# or come up with some other progress indicator for Windows. | ||
class WindowsSpinner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ansicon is already integrated. we can drop this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need unicode before our ✔️ or ✖️ will show up in windows. We could default to the text passed
or failed
on windows, ie
[passed] Checking metadata (metadata.json)
Would we rather have that so we can have the spinner on Windows? And do we want to do that in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having the words instead of the unicode chars is a good idea. I wouldn't block the PR for the change, but we need to do it at one point....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll leave it as is for now, but get a fix for that up once we get this through.
lib/pdk/cli/spinner.rb
Outdated
module CLI | ||
module Spinner | ||
PREFIX = 'spinner_key'.freeze | ||
LOCK = Monitor.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
locks should be private to avoid other callers violating expectations.
lib/pdk/cli/validate.rb
Outdated
threads.each(&:join) | ||
exit_codes.sort! | ||
|
||
if exit_codes.last != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit_codes.all? { |c| c == 0 }
https://ruby-doc.org/core-2.4.1/Enumerable.html#method-i-all-3F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sorted them to return the highest error code with last in order to mirror the functionality in base_validator.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that also needs fixing then: http://ruby-doc.org/core-2.4.0/Enumerable.html#method-i-max
lib/pdk/util.rb
Outdated
|
||
# Returns the targets' paths relative to the working directory | ||
# | ||
# @ return Array<String> The absolute or path to the target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should that be @return
instead of @ return
?
Where/how can we check the YARD output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a rake task to generate YARD output https://github.com/lsegal/yard#generating-documentation
I'll fix the typo and we can have another PR for that if we want to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed, just not shown as outdated for some reason
locales/de/pdk.po
Outdated
@@ -1,604 +0,0 @@ | |||
# German translations for puppet development kit package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file should not be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file caused a lot of problems for threads because it was no longer up to date with the current pdk.pot file, and when talking to the i18n folks they were confused why we even had a PO file in our repo as they will be managed by transifex. We should discuss this in more detail if you have concerns, but if we would like both the German PO file and threading the German PO file must be kept up to date and in sync with the pdk.pot file.
An important note, keeping a PO file in sync with the POT file without deleting all the existing translations is not a feature provided by the gettext-setup-gem we use because the Transifex workflow creates brand new PO files and populates them with the previous translations that match current strings. So we would be responsible for figuring out how to do that (most likely using msgmerge
).
Another potential solution would be for you to keep the German file locally and not checked in to the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be interested how the non-up-to-date de.po file causes issues with threading, especially outside the de
locale.
rake gettext:update_pot
and rake gettext:po[de]
worked fine until now to update the po file as needed, and to the right thing for gettext. I'm sure transifex can one-time import the existing translations once we get around to integrating.
Another potential solution would be for you to keep the German file locally and not checked in to the repo.
I'm not even using the thing, what value would it have on my local machine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we ran into two error messages, one involves fuzzy messages and the other is for old messages it leaves in comments at the bottom.
Commented
Warning: obsolete msgid exists.
#~ msgstr "Verwende ein eigenes Vorlagerepository für dieses Modul."
Fuzzy
Warning: fuzzy message was used.
: msgid 'Unable to write '%{file}': %{msg}'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure transifex can one-time import the existing translations once we get around to integrating.
In my interactions with i18n for this problem, I don't think they are willing to ship a translation that wasn't done by Transifex or whichever company does the translations through Transifex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a Rake task that cleans the file for us, one extra step to make sure it works, but we can keep the German file now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, @austb . Thank you very much for your attention here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(specifically to discovering the root cause of the uninitialized threads)
I've had a few comments/change requests on first reading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some relatively minor things before we merge today. Austin and I talked about a larger refactor that we try to do before 1.0 release.
lib/pdk/cli/exec.rb
Outdated
@@ -105,7 +104,13 @@ def add_spinner(message, opts = {}) | |||
@success_message = opts.delete(:success) | |||
@failure_message = opts.delete(:failure) | |||
|
|||
@spinner = Gem.win_platform? ? WindowsSpinner.new(message, opts) : TTY::Spinner.new("[:spinner] #{message}", opts) | |||
PDK::Util.spinner_opts_for_platform(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should return a new hash and you should merge
with existing opts rather than mutating arg.
lib/pdk/cli/exec.rb
Outdated
@@ -1,7 +1,6 @@ | |||
require 'bundler' | |||
require 'childprocess' | |||
require 'tempfile' | |||
require 'tty-spinner' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to not explicitly require this here anymore?
lib/pdk/cli/exec.rb
Outdated
Dir.chdir(mod_root) do | ||
::Bundler.with_clean_env do | ||
run_process! | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason to remove all this, the parallel validate can still call the util method to abort early but I feel like removing this is pushing responsibility in the wrong direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can test Dir.pwd
so that we only try to chdir
if we aren't already in the right place. That should keep the child threads from complaining.
targets = parse_targets(options) | ||
|
||
return 0 if targets.empty? | ||
|
||
return_val = 0 | ||
@return_val = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason this had to become an instance var? Something to do with threads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not merge this currently, as it is not passing the internal pipeline for the packaging.
af21753
to
8570f99
Compare
49ccaa5
to
5727304
Compare
@jbondpdx Austin is going to add a blurb to the README about this feature and then we plan to merge. Despite the size of the PR, the actual user impact/README stuff should be pretty simple. |
This adds the `--parallel` flag to the `pdk validate` command. This flag will cause the validations to run in their own threads.
cbe341b
to
6e45cd2
Compare
This addes the
--parallel
flag to thepdk validate
command. Thisflag will cause the validations to run in their own threads.
UPDATE: waiting for release of
tty-spinner
gem (also probably need to wait for a release oftty-prompt
with compatibletty-cursor
range.Remaining
tty-spinner
andtty-prompt
gems