Skip to content

Commit c7c1e8e

Browse files
committed
Merge branch 'develop'
2 parents 8fa302a + 2d7f344 commit c7c1e8e

File tree

4 files changed

+48
-201
lines changed

4 files changed

+48
-201
lines changed

lib/BioX/Workflow/Command/run/Rules/Directives/Types/Path.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ has 'outdir' => (
3838
documentation => q(Output directories for rules and processes),
3939
);
4040

41+
has 'cwd' => (
42+
is => 'rw',
43+
isa => Path,
44+
coerce => 1,
45+
required => 0,
46+
default => sub { cwd(); },
47+
predicate => 'has_cwd',
48+
clearer => 'clear_cwd',
49+
documentation => q(Placeholder for the cwd.),
50+
);
51+
4152
=head3 INPUT OUTPUT
4253
4354
Special variables that can have input/output

lib/BioX/Workflow/Command/run/Utils/Files/ResolveDeps.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ sub add_graph {
4444
my $self = shift;
4545
my $cond = shift;
4646

47-
for my $pair ( $self->files_pairs ) {
48-
my $file = $pair->[0];
47+
for my $file ( $self->all_files ) {
4948
if ( !exists $self->rule_deps->{ $self->rule_name }->{$cond}->{$file} )
5049
{
5150
$self->rule_deps->{ $self->rule_name }->{$cond}->{$file} = 1;

lib/BioX/Workflow/Command/run/Utils/Files/TrackChanges.pm

Lines changed: 30 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -7,249 +7,85 @@ use File::stat;
77
use Time::localtime;
88
use File::Basename;
99
use DateTime::Format::Strptime;
10-
# use Memoize;
1110

1211
with 'BioX::Workflow::Command::Utils::Files::TrackChanges';
1312

1413
=head3 files
1514
1615
Files just for this rule
1716
17+
##TODO Make this a hash?
1818
=cut
1919

20-
has 'files' => (
21-
traits => ['Hash'],
22-
is => 'rw',
23-
isa => 'HashRef',
24-
default => sub { {} },
25-
handles => {
26-
files_pairs => 'kv',
27-
clear_files => 'clear',
28-
},
29-
);
20+
# has 'files' => (
21+
# traits => ['Hash'],
22+
# is => 'rw',
23+
# isa => 'HashRef',
24+
# default => sub { {} },
25+
# handles => {
26+
# files_pairs => 'kv',
27+
# clear_files => 'clear',
28+
# },
29+
# );
3030

31-
32-
#TODO Update this
33-
#No longer seen_modify - since we are not checking for timestamps anymore
34-
has 'seen_modify' => (
35-
traits => ['Hash'],
31+
has 'files' => (
32+
traits => ['Array'],
3633
is => 'rw',
37-
isa => 'HashRef',
38-
default => sub { {} },
34+
isa => 'ArrayRef',
35+
default => sub { [] },
3936
handles => {
40-
seen_modify_pairs => 'kv',
41-
clear_seen_modify => 'clear',
37+
has_files => 'count',
38+
all_files => 'elements',
39+
push_files => 'push',
40+
sort_files => 'sort_in_place',
41+
uniq_files => 'uniq',
4242
},
43+
clearer => 'clear_files',
4344
);
4445

4546
sub walk_FILES {
4647
my $self = shift;
4748
my $attr = shift;
4849

49-
$self->seen_modify->{local} = {};
50-
51-
# my $mod_input = $self->pre_FILES( $attr, 'INPUT' );
5250
$self->pre_FILES( $attr, 'INPUT' );
5351
$self->add_graph('INPUT');
5452
$self->clear_files;
5553

56-
# $self->app_log->info('Between checks...');
57-
# my $mod_output = $self->pre_FILES( $attr, 'OUTPUT' );
58-
$self->pre_FILES($attr, 'OUTPUT');
54+
$self->pre_FILES( $attr, 'OUTPUT' );
5955
$self->add_graph('OUTPUT');
6056
$self->clear_files;
61-
# $self->local_attr->{_modified} = 1 if $mod_input;
62-
63-
# TODO add check for when we have actually modified the output
6457
}
6558

6659
sub pre_FILES {
6760
my $self = shift;
6861
my $attr = shift;
6962
my $cond = shift;
7063

71-
# $self->app_log->info( 'Beginning modification checks for ' . $cond );
72-
# REF check?
7364
walk {
7465
wanted => sub { $self->walk_INPUT(@_) }
7566
},
7667
$attr->$cond;
77-
78-
# Once we get to the input we want to see if we are processing a new file or no
79-
# my $modify = $self->iterate_FILES;
80-
$self->iterate_FILES;
81-
82-
# return $modify;
68+
$self->uniq_files;
69+
$self->sort_files;
8370
}
8471

85-
sub iterate_FILES {
86-
my $self = shift;
72+
=head3 walk_INPUT
8773
88-
# my $modify = 0;
89-
for my $pair ( $self->files_pairs ) {
90-
my $file = $pair->[0];
91-
$self->seen_modify->{local}->{$file} = 1;
92-
# if ( $self->seen_modify->{all}->{$file} ) {
93-
# my $tmodify = $self->seen_modify->{all}->{$file};
94-
# $modify = 1 if $tmodify;
95-
# $self->update_seen( $file, $modify );
96-
# next;
97-
# }
98-
# elsif ( !-e $file ) {
99-
# $self->update_seen( $file, 1 );
100-
# $modify = 1;
101-
# next;
102-
# }
103-
#
104-
# if ( $self->process_file($file) ) {
105-
# $modify = 1;
106-
# }
107-
}
108-
109-
# return $modify;
110-
}
111-
112-
=head3 process_file
74+
walk the INPUT/OUTPUT and catch all Path::Tiny references
11375
11476
=cut
11577

116-
# sub process_file {
117-
# my $self = shift;
118-
# my $file = shift;
119-
#
120-
# $self->seen_modify->{local}->{$file} = 1;
121-
# # my $details = File::Details->new($file);
122-
# # my $mtime = ctime( stat($file)->mtime );
123-
# #
124-
# # if ( exists $self->track_files->{$file}->{mtime} ) {
125-
# #
126-
# # # Check to see if we have a difference
127-
# # my $p_mtime = $self->track_files->{$file}->{mtime};
128-
# # if ( compare_mtimes( $p_mtime, $mtime ) ) {
129-
# # # $self->flag_for_process( $file, $p_mtime, $mtime );
130-
# # $self->update_seen( $file, 1 );
131-
# #
132-
# # return 1;
133-
# # }
134-
# # else {
135-
# # # This is the only time we should return 0
136-
# # $self->update_seen( $file, 0 );
137-
# # return 0;
138-
# # }
139-
# # }
140-
# # else {
141-
# # $self->update_seen( $file, 1 );
142-
# # return 1;
143-
# # }
144-
# }
145-
146-
# This is really more of a sanity check
147-
sub flag_for_process {
148-
my $self = shift;
149-
my $file = shift;
150-
my $p_mtime = shift;
151-
my $mtime = shift;
152-
153-
my $basename = basename($file);
154-
155-
# #TO LOG OR NOT TO LOG
156-
# $self->app_log->warn(
157-
# 'File ' . $file . ' has been modified since your last analysis.' );
158-
# $self->app_log->warn( $basename
159-
# . ":\n\tLast Recorded Modification:\t"
160-
# . $p_mtime
161-
# . "\n\tMost Recent Modification:\t"
162-
# . $mtime );
163-
164-
# TODO We only want this in run...
165-
# TODO Add an override here
166-
# if ( !$self->check_select && !$self->use_timestamps ) {
167-
# $self->app_log->warn( 'You have selected to skip rule '
168-
# . $self->rule_name
169-
# . ', but this file has changed since last your last analysis.' );
170-
#
171-
# }
172-
}
173-
17478
sub walk_INPUT {
17579
my $self = shift;
17680
my $ref = shift;
17781

178-
return if ref($ref);
17982
return unless $ref;
18083

181-
if ( !exists $self->files->{$ref} ) {
182-
$self->files->{$ref} = 1;
183-
}
184-
}
185-
186-
# memoize('compare_mtimes');
187-
# sub compare_mtimes {
188-
# my $pmtime = shift;
189-
# my $mtime = shift;
190-
#
191-
# my $strp = DateTime::Format::Strptime->new(
192-
# pattern => '%a %b %e %T %Y',
193-
# time_zone => 'local',
194-
# );
195-
#
196-
# my $dt1 = $strp->parse_datetime($pmtime);
197-
# my $dt2 = $strp->parse_datetime($mtime);
198-
#
199-
# #For reasons unknown there is something off by 1 second either way
200-
# #my $cmp = DateTime->compare( $dt1, $dt2 );
201-
# my $dur = $dt2->subtract_datetime($dt1);
202-
#
203-
# # TODO Add this formatting to HPC::Runner
204-
# my ( $days, $hours, $minutes, $seconds ) =
205-
# $dur->in_units( 'days', 'hours', 'minutes', 'seconds' );
206-
#
207-
# if ( $days >= 1 || $hours >= 1 || $minutes >= 1 ) {
208-
# return 1;
209-
# }
210-
# elsif ( $seconds >= 2 ) {
211-
# return 1;
212-
# }
213-
# else {
214-
# return 0;
215-
# }
216-
# }
217-
#
218-
# sub update_seen {
219-
# my $self = shift;
220-
# my $file = shift;
221-
# my $update = shift;
222-
#
223-
# # $self->seen_modify->{all}->{$file} = $update;
224-
# $self->seen_modify->{local}->{$file} = $update;
225-
# }
226-
227-
sub write_file_log {
228-
my $self = shift;
84+
my $ref_name = ref($ref);
85+
return unless $ref_name;
86+
return unless $ref_name eq 'Path::Tiny';
22987

230-
my $text = "";
231-
my @files = keys %{ $self->seen_modify->{local} };
232-
@files = sort @files;
233-
234-
$self->seen_modify->{local} = {};
235-
236-
if (@files) {
237-
$text = <<EOF;
238-
; \\
239-
biox file_log \\
240-
\t--exit_code `echo \$\?` \\
241-
EOF
242-
}
243-
244-
my $last = pop(@files);
245-
foreach my $file (@files) {
246-
$text .= <<EOF;
247-
\t--file $file \\
248-
EOF
249-
}
250-
$text .= "\t--file $last\n\n" if $last;
251-
252-
return $text;
88+
$self->push_files( $ref->absolute );
25389
}
25490

25591
1;

lib/BioX/Workflow/Command/stats.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use File::Details;
1010
use File::Basename;
1111
use List::MoreUtils qw(uniq);
1212
use Try::Tiny;
13+
use Path::Tiny;
1314

1415
extends qw( BioX::Workflow::Command );
1516

@@ -78,11 +79,11 @@ has 'table_log' => (
7879
}
7980
);
8081

81-
option 'use_full' => (
82+
option 'use_abs' => (
8283
is => 'rw',
8384
isa => 'Bool',
8485
default => 0,
85-
documentation => 'Use the full path name instead of the basename'
86+
documentation => 'Use the absolute path name instead of the basename'
8687
);
8788

8889
our $human = Number::Bytes::Human->new(
@@ -119,8 +120,8 @@ around 'pre_FILES' => sub {
119120

120121
$self->$orig( $attr, $cond );
121122

122-
for my $pair ( $self->files_pairs ) {
123-
$self->preprocess_row( $pair->[0], $cond );
123+
for my $file ( $self->all_files ) {
124+
$self->preprocess_row( $file, $cond );
124125
}
125126
};
126127

@@ -149,7 +150,7 @@ sub gen_row {
149150

150151
my $rel = '';
151152
$rel = $file;
152-
$rel = File::Spec->abs2rel($file) if $self->use_full;
153+
$rel = path($file)->absolute if $self->use_full;
153154

154155
my $basename = basename($file) unless $self->use_full;
155156

0 commit comments

Comments
 (0)