From 10c6cf537f68b7abcf8220f6878cccb1676fb039 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 22 Feb 2019 18:16:15 +0000 Subject: [PATCH] Bug 21892: Purposefully update codespell This detects if codespell has -L option, and if not, it purposefully uninstalls it, and then installs the version it needs via 'pip install'. It also tweaks the detection of codespell installation. --- QohA/File.pm | 32 +++++++++++++++++++++++++++++++- koha-qa.pl | 7 ++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/QohA/File.pm b/QohA/File.pm index 863bb92..e37afb4 100644 --- a/QohA/File.pm +++ b/QohA/File.pm @@ -96,10 +96,40 @@ sub check_forbidden_patterns { : 1; } +sub codespell_has_L_option { + my $cmd = q{codespell --help | grep "\-L" | wc -l}; + my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); + my $result = $full_buf->[0]; + return $result + 0; +} + +sub remove_codespell { + my $cmd = q{sudo apt remove -y codespell}; + my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); + $cmd = q{sudo -H pip uninstall -y codespell}; + ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); +} + +sub install_codespell { + my $cmd = q{sudo -H pip install codespell}; + my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); +} + +sub tell_bash_to_unhash_codespell { + my $cmd = q{hash -d codespell}; + my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); +} + sub check_spelling { my ($self) = @_; - my $cmd = q{codespell -L Sheat -d } . $self->path; + if (! codespell_has_L_option()) { + print STDERR "\nCodespell missing required -L option!\n"; + remove_codespell; + install_codespell; + tell_bash_to_unhash_codespell; + } + my $cmd = q{codespell -L sheat -d } . $self->path; my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); return 0 unless @$full_buf; diff --git a/koha-qa.pl b/koha-qa.pl index 609f922..098393a 100755 --- a/koha-qa.pl +++ b/koha-qa.pl @@ -41,8 +41,13 @@ BEGIN { } our @tests_to_skip = (); +# Check for codespell +my $have_codespell = 0; +if ( -f '/usr/bin/codespell' || -f '/usr/local/bin/codespell' ) { + $have_codespell = 1; +} # Assuming codespell is in /usr/bin -unless ( -f '/usr/bin/codespell' ) { +if (! $have_codespell ) { warn "You should install codespell\n"; push @tests_to_skip, 'spelling'; } -- 2.11.0