@@ -53,7 +53,8 @@ class PweaveDocs(distutils.cmd.Command):
5353 user_options = [
5454 # The format is (long option, short option, description).
5555 ('files=' , 's' , 'Specific files to pweave. Defaults to all in `docs` directory.' ),
56- ('format=' , 'f' , 'Output format type. Defaults to `markdown`' )
56+ ('format=' , 'f' , 'Output format type. Defaults to `markdown`' ),
57+ ('quick=' , 'q' , 'Check to see if the source file is newer than existing output before building. Defaults to `False`.' )
5758 ]
5859
5960 def initialize_options (self ):
@@ -64,6 +65,7 @@ def initialize_options(self):
6465 glob (path .join (here , 'docs' , '*.pymd' ))
6566 )
6667 self .format = 'markdown'
68+ self .quick = False
6769
6870 def finalize_options (self ):
6971 """Post-process options."""
@@ -73,6 +75,11 @@ def finalize_options(self):
7375 # `html` doesn't do quite what one expects... only replaces code blocks, leaving markdown in place
7476 if self .format is 'html' :
7577 self .format = 'pandoc2html'
78+ if isinstance (self .quick , str ):
79+ self .quick = self .quick == 'True' or self .quick == 'true'
80+
81+ def dest_file (self , src_file ):
82+ return path .splitext (src_file )[0 ] + '.md'
7683
7784 def run (self ):
7885 """Run pweave."""
@@ -82,33 +89,36 @@ def run(self):
8289
8390 for file in self .files :
8491 name = path .splitext (path .basename (file ))[0 ]
85- print (_divided ('Running %s' % name ))
86- try :
87- pweave .weave (
88- file = str (file ),
89- doctype = self .format
90- )
91- if self .format == 'markdown' :
92- dest = path .splitext (file )[0 ] + '.md'
93- if not path .exists (dest ):
94- raise FileNotFoundError ("Markdown file '%s' didn't get created as expected" % dest )
95- with open (dest , "r" ) as result :
96- for (n , line ) in enumerate (result ):
97- for word in bad_words :
98- if word in line :
99- raise ChildProcessError ("Error detected on line %s in %s:\n %s" % (n + 1 , dest , line ))
100-
101- except Exception :
102- print (_divided ('%s Failed:' % file ))
103- print (traceback .format_exc ())
104- exit (1 )
92+ dest = self .dest_file (file )
93+
94+ if (not self .quick ) or (not path .exists (dest )) or (path .getmtime (dest ) < path .getmtime (file )):
95+ print (_divided ('Running %s' % name ))
96+ try :
97+ pweave .weave (file = str (file ), doctype = self .format )
98+ if self .format == 'markdown' :
99+ if not path .exists (dest ):
100+ raise FileNotFoundError ("Markdown file '%s' didn't get created as expected" % dest )
101+ with open (dest , "r" ) as result :
102+ for (n , line ) in enumerate (result ):
103+ for word in bad_words :
104+ if word in line :
105+ raise ChildProcessError ("Error detected on line %s in %s:\n %s" % (n + 1 , dest , line ))
106+
107+ except Exception :
108+ print (_divided ('%s Failed:' % file ))
109+ print (traceback .format_exc ())
110+ exit (1 )
111+ else :
112+ print (_divided ('Skipping %s' % file ))
105113
106114
107115class PweaveNotebooks (PweaveDocs ):
108116 def initialize_options (self ):
109117 super ().initialize_options ()
110118 self .format = 'notebook'
111119
120+ def dest_file (self , src_file ):
121+ return path .splitext (src_file )[0 ] + '.ipynb'
112122
113123setup (
114124 name = 'pyrasterframes' ,
0 commit comments