Skip to content

Commit

Permalink
rename old multi subs per TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrowder committed Nov 14, 2024
1 parent 690e172 commit a5b9be7
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 37 deletions.
4 changes: 3 additions & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"perl": "6.d",
"provides": {
"Mi6::Helper": "lib/Mi6/Helper.rakumod",
"Mi6::Helper::Utils": "lib/Mi6/Helper/Utils.rakumod"
"Mi6::Helper::Subs": "lib/Mi6/Helper/Subs.rakumod",
"Mi6::Helper::Utils": "lib/Mi6/Helper/Utils.rakumod",
"Mi6::Helper::Vars": "lib/Mi6/Helper/Vars.rakumod"
},
"resources": [
"linux.yml",
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ NOTE: The next version will remove all 'provides' methods except the use of the
$ mi6-helper lint <dir> # Checks a module directory for errors
# and best practice recommendations

Alternatively, one can use either of two programs as short names for the lint mode:

$ distro-lint <dir>
$ dlint <dir>

**Easily** create the template for a new Raku module repository for management by `App::Mi6` with modifications including:

* Publishing in the **Zef** Raku module ecosystem
Expand Down Expand Up @@ -58,7 +63,7 @@ lint

* lint \<path\>

Checks the module repo in directory \<path\> that the contents of the "resources" list in the 'META6.json' file and the distibution's './resources' directory agree. Modifies them as necessary, displays the proposed changes, and prompts the user for permission to make the changes.
Checks the module repository in directory \<path\> that the contents of the "resources" list in the 'META6.json' file and the distibution's './resources' directory agree. Modifies them as necessary, displays the proposed changes, and prompts the user for permission to make the changes.

Also checks for other configuration improvement possibilities. Note the 'lint' mode will work in repos *not* under App::Mi6 management.

Expand Down
13 changes: 9 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Desired capabilities
====================

Use straight lint sub with no .precomp to check META6.json
Put each action in its own sub whose input includes the collections of
all the user's files. The output should be a string to be concatenated
with the results summary report.

Rename the "action" subs to something batter.

Remove the lint mode from the mi6-helper mode?

Use straight lint sub to check META6.json
files versus /resources to ensure they're in sync

First priority is to check synch between actual 'use'd modules
Expand All @@ -20,7 +28,6 @@ Implement old= mode
# contents?

Implement lint mode
+ Consider using Shell::Command
+ ensure there is a load test for
ALL files in /lib

Expand All @@ -36,5 +43,3 @@ Add a new= method with a config file
My-Module.yml
name: My::Module
provides: Blah blah


10 changes: 6 additions & 4 deletions bin/distro-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
use Mi6::Helper;
use Mi6::Helper::Utils;

my $dir = $*CWD;
my $parent-dir = $*CWD;
my $module-name;
ny $module-dir;

my @args = @*ARGS;
for @args -> $arg {

}

if @*ARGS {
Expand All @@ -16,9 +18,9 @@ if @*ARGS {
when /^ :i L/ {
%*ENV<RAKUDO_NO_PRECOMPILATION> = 1;
}

}
action @*ARGS
run-args @*ARGS
}
else {
# usage
Expand Down
6 changes: 3 additions & 3 deletions bin/mi6-helper
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ if @*ARGS {
when /^ :i L/ {
%*ENV<RAKUDO_NO_PRECOMPILATION> = 1;
}

}
action @*ARGS
run-args @*ARGS
}
else {
# usage
action
help
}

=finish
Expand Down
2 changes: 2 additions & 0 deletions lib/Mi6/Helper/Subs.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unit module Mi6::Helper::Subs;

59 changes: 35 additions & 24 deletions lib/Mi6/Helper/Utils.rakumod
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
unit module Mi6::Helper::Utils;

use Mi6::Helper;
use Mi6::Helper::Subs;

use Pod::Load;
use App::Mi6;
use Text::Utils :normalize-string, :strip-comment;
use File::Find;
use JSON::Fast;

our $res-info = qq:to/RESINFO/;
META6.json and /resources
===========================
In order to reliably download payloads in the /resources directory, the
module author needs to provide a list of the files in the module's
contents.
RESINFO

sub lint-usage() is export {
# usage
print qq:to/HERE/;
Usage: {$*PROGRAM.basename} <dir with .git subdir> [options...]
Checks for issues in the user's selected <dir> which is expected
to be a 'git' repository for one of the user's Raku distributions
(commonly known as 'modules') intended for public (or local)
(commonly known as 'modules') intended for public (or local)
distribution.
Uses the current working directory if it has a .git subdirectory,
Uses the current working directory if it has a .git subdirectory,
otherwise you must select such a directory to continue.
Currently checks for:
+ match of entries in the 'resources' directory of the current directory
+ match of entries in the 'resources' directory of the current directory
and the 'resources' entries in the 'META6.json' file
+ match of entries of modules listed in the 'META6.json' file and those
'use'd in the source code
+ old Perl 6 file name suffixes:
+ old Perl 6 file name suffixes:
.t --> .rakutest
.pl, .p6, .pl6 --> .raku
.pm, .pm6 --> .rakumod
Expand All @@ -34,7 +45,7 @@ sub lint-usage() is export {
exit;
}

multi sub action() is export {
sub help() is export {
# usage
say qq:to/HERE/;
Usage: {$*PROGRAM.basename} <mode> [options...]
Expand All @@ -47,21 +58,21 @@ multi sub action() is export {
See details in the README.
lint - Checks for match of entries in the 'resources' directory of the
current directory (default '.', but see NOTE below)) and the
'resources' entries in the 'META6.json' file. Also looks for
other issues.
current directory (default '.', but see NOTE below)) and the
'resources' entries in the 'META6.json' file. Also looks for
other issues.
Options:
dir=X - Selects directory 'X' for the operations, default is '.'
ver - Shows the version of 'mi6-helper'
NOTE - The default directory will cause an abort if the repository home
NOTE - The default directory will cause an abort if the repository home
of this module is selected.
HERE
} # sub action()

multi sub action(@args) is export {
sub run-args(@args) is export {
# do the work

# modes
Expand Down Expand Up @@ -250,20 +261,20 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
}
=end comment

my $issues = ""; # a Str whose contents will be spurted into a text
my $issues = ""; # a Str whose contents will be spurted into a text
# file whose path name is returned to the user

$issues ~= qq:to/HERE/;
# Checking all 'use'd modules are listed in the 'META6.json' file
# and vice versa.
# types.
#
#
# Modules being used:
HERE

# handle the used files...
my %meta = from-json("META6.json".IO.slurp);
# build-depends, depends, test-depends, resources,
# build-depends, depends, test-depends, resources,
my (%bmods, %dmods, %tmods, %rfils);
my %mmods;

Expand Down Expand Up @@ -313,7 +324,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {

# check 'use' in all files execpt those in .git or .precomp dirs
# (includes all types of user's files)
my @ufils = find :dir('.'), :type<file>,
my @ufils = find :dir('.'), :type<file>,
:exclude( any(/'.precomp'/, /'.git'/) );
if 0 and $debug {
say "DEBUG Files found:";
Expand Down Expand Up @@ -345,15 +356,15 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
say " line-num: '$line-num'" if $debug;
# results hash: key: module name
# <path>{$path} = [ line-numbers...]
if %umods{$mod}<path>{$path}:exists {
if %umods{$mod}<path>{$path}:exists {
%umods{$mod}<path>{$path}.push: $line-num;
}
else {
%umods{$mod}<path>{$path} = [];
%umods{$mod}<path>{$path}.push: $line-num;
}
}
}
}
}

for %umods.keys.sort -> $mod {
Expand All @@ -372,7 +383,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
}
}

# are we missing anything
# are we missing anything
my $mmod-absent = 0;
for %umods.keys.sort {
next if %mmods{$_}:exists;
Expand Down Expand Up @@ -401,11 +412,11 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
# If either a 'resources' dir exists with one or more files
# as contents or the 'META6.json' file has one or more
# paths listed, then report and offer fixes.

$issues ~= qq:to/HERE/;
# Checking mismatch between any files listed in the module's
# /resources directory and those in the 'META6.json' file.
#
#
# Resources mismatch:
HERE

Expand All @@ -421,7 +432,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
@resfils.push: $f;
}
=begin comment
+ old Perl 6 file name suffixes:
+ old Perl 6 file name suffixes:
.t --> .rakutest
.pl, .p6, .pl6 --> .raku
.pm, .pm6 --> .rakumod
Expand Down Expand Up @@ -453,7 +464,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
++$rec-name-change;
}
}

my $resfils-issues = ""; # used to collect results from resources check
if not (@rfils.elems or @resfils.elems) {
say "DEBUG: neither META6 nor /resources list any files";
Expand All @@ -471,7 +482,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
for @rfils -> $path {
# @rfils - from META6.json
my $bnam = $path.IO.basename;
if %m{$bnam}<path>{$path}:exists {
if %m{$bnam}<path>{$path}:exists {
%m{$bnam}<path>{$path} += 1;
}
else {
Expand All @@ -481,7 +492,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
for @resfils -> $path {
# @resfils - from /resources
my $bnam = $path.IO.basename;
if %r{$bnam}<path>{$path}:exists {
if %r{$bnam}<path>{$path}:exists {
%r{$bnam}<path>{$path} += 1;
}
else {
Expand Down Expand Up @@ -657,7 +668,7 @@ sub lint(IO::Path:D $dir, :$debug, --> Str) is export {
#$report;
$issues

} # sub lint($dir, :$debug, --> Str)
} # sub lint($dir, :$debug, --> Str)

sub find-file-suffixes(IO::Path $dir, :%meta, :$debug --> Hash) is export {
# TODO then add the valid names back in for more checks
Expand Down
1 change: 1 addition & 0 deletions lib/Mi6/Helper/Vars.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unit module Mi6::Helper::Vars;

0 comments on commit a5b9be7

Please sign in to comment.