Commit df00abe6 authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Enforce (almost) all files to be in ASCII

parent 995f0fed
......@@ -99,7 +99,7 @@ If your compute environment uses `Module <http://modules.sourceforge.net/>`__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*Module* provides configuration files (module-files) for the dynamic
modification of the users environment.
modification of the user's environment.
Here is how to list the modules that your system provides:
......
......@@ -26,6 +26,7 @@ no warnings qw( redefine );
use Exporter;
use Carp qw{croak};
use File::Spec;
use File::Temp qw{tempfile};
use Data::Dumper;
......@@ -45,7 +46,7 @@ use Bio::EnsEMBL::Hive::Scripts::StandaloneJob;
our @ISA = qw(Exporter);
our @EXPORT = ();
our %EXPORT_TAGS = ();
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper generate_graph visualize_jobs seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db safe_drop_database);
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper generate_graph visualize_jobs seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db safe_drop_database all_source_files);
our $VERSION = '0.00';
......@@ -599,4 +600,37 @@ sub safe_drop_database {
}
=head2 all_source_files
Arg [n] : Directories to scan.
Example : my @files = all_source_files('modules');
Description: Scans the given directories and returns all found instances of
source code. This includes Perl (pl,pm,t), Java(java), C(c,h) and
SQL (sql) suffixed files.
Returntype : Array of all found files
=cut
sub all_source_files {
my @starting_dirs = @_;
my @files;
my @dirs = @starting_dirs;
my %excluded_dir = map {$_ => 1} qw(_build build lib .git __pycache__);
while ( my $file = shift @dirs ) {
if ( -d $file ) {
opendir my $dir, $file or next;
my @new_files =
grep { !$excluded_dir{$_} && $_ !~ /^\./ }
File::Spec->no_upwards(readdir $dir);
closedir $dir;
push(@dirs, map {File::Spec->catfile($file, $_)} @new_files);
}
if ( -f $file ) {
#next unless $file =~ /(?-xism:\.(?:[cht]|p[lm]|java|sql))/;
push(@files, $file);
}
} # while
return @files;
}
1;
#!/usr/bin/env perl
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# Copyright [2016-2017] EMBL-European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use warnings;
use Cwd;
use File::Spec;
use File::Basename qw/dirname/;
use Test::More;
use Test::Warnings;
use Term::ANSIColor;
use Bio::EnsEMBL::Hive::Utils::Test qw(all_source_files);
if ( not $ENV{TEST_AUTHOR} ) {
my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
plan( skip_all => $msg );
}
#chdir into the file's target & request cwd() which should be fully resolved now.
#then go back
my $file_dir = dirname(__FILE__);
my $original_dir = cwd();
chdir($file_dir);
my $cur_dir = cwd();
chdir($original_dir);
my $root = File::Spec->catdir($cur_dir, File::Spec->updir());
sub is_ascii {
my $filename = shift;
my $has_non_ascii;
open(my $fh, '<', $filename) or die "Cannot open '$filename' because '$!'\n";
while(<$fh>) {
if (/[^[:space:][:print:]]/) {
$has_non_ascii = 1;
s/([^[:space:][:print:]]+)/colored($1, 'on_red')/eg;
diag($filename.' has '.$_);
}
}
close($fh);
if ($has_non_ascii) {
fail($filename);
} else {
pass($filename);
}
}
my @source_files = all_source_files($root);
#Find all files & run
foreach my $f (@source_files) {
# Binary files
next if $f =~ /\.(png|jpg|pdf|pyc|tgz)$/;
# Unicode-art
next if $f =~ /modules\/Bio\/EnsEMBL\/Hive\/(Analysis|HivePipeline)\.pm$/;
next if $f =~ /\/generate_graph\/.*::PipeConfig::.*\.txt$/;
is_ascii($f);
}
done_testing();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment