don't use sys.exit(...) inside main(), but only under if __name__ == "__main__"
The convention is that sys.exit(...) is called only if a module is run as a script, and that main() entry points use return statements to report exit codes: 0 (or None) for successful execution, or any non-zero integer for errors. E.g. see the console scripts generated when installing with pip.
This commit is contained in:
parent
ae05b2a583
commit
b7bb391033
@ -1,7 +1,8 @@
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import sys
|
||||
|
||||
|
||||
def main(args=None):
|
||||
import sys
|
||||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
|
||||
@ -27,5 +28,6 @@ def main(args=None):
|
||||
import runpy
|
||||
runpy.run_module(mod, run_name='__main__')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -262,10 +262,10 @@ def main(args=None):
|
||||
args = sys.argv[1:]
|
||||
if len(args) < 1:
|
||||
print("usage: pyftinspect font...", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return 1
|
||||
for arg in args:
|
||||
Inspect(arg)
|
||||
gtk.main()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -932,7 +932,7 @@ def main(args=None):
|
||||
|
||||
if len(args) < 1:
|
||||
print("usage: pyftmerge font...", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return 1
|
||||
|
||||
configLogger(level=logging.INFO if options.verbose else logging.WARNING)
|
||||
if options.timing:
|
||||
@ -948,4 +948,4 @@ def main(args=None):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -1151,11 +1151,14 @@ def build(f, font, tableTag=None):
|
||||
return parseTable(lines, font, tableTag=tableTag)
|
||||
|
||||
|
||||
def main(args, font=None):
|
||||
def main(args=None, font=None):
|
||||
import sys
|
||||
from fontTools import configLogger
|
||||
from fontTools.misc.testTools import MockFont
|
||||
|
||||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
|
||||
# configure the library logger (for >= WARNING)
|
||||
configLogger()
|
||||
# comment this out to enable debug messages from mtiLib's logger
|
||||
@ -1186,6 +1189,7 @@ def main(args, font=None):
|
||||
writer.endtag(tag)
|
||||
writer.newline()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
main (sys.argv[1:])
|
||||
sys.exit(main())
|
||||
|
@ -2872,7 +2872,7 @@ def main(args=None):
|
||||
|
||||
if '--help' in args:
|
||||
print(__doc__)
|
||||
sys.exit(0)
|
||||
return 0
|
||||
|
||||
options = Options()
|
||||
try:
|
||||
@ -2885,11 +2885,11 @@ def main(args=None):
|
||||
except options.OptionError as e:
|
||||
usage()
|
||||
print("ERROR:", e, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
return 2
|
||||
|
||||
if len(args) < 2:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
return 1
|
||||
|
||||
configLogger(level=logging.INFO if options.verbose else logging.WARNING)
|
||||
if options.timing:
|
||||
@ -2995,4 +2995,4 @@ __all__ = [
|
||||
]
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import print_function, division, absolute_import
|
||||
from fontTools.misc.py23 import *
|
||||
import sys
|
||||
from fontTools.subset import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -414,4 +414,4 @@ def main(args=None):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -449,7 +449,6 @@ def main(args=None):
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) > 1:
|
||||
main()
|
||||
#sys.exit(0)
|
||||
sys.exit(main())
|
||||
import doctest, sys
|
||||
sys.exit(doctest.testmod().failed)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import print_function, division, absolute_import
|
||||
from fontTools.misc.py23 import *
|
||||
import sys
|
||||
from fontTools.varLib import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -337,7 +337,6 @@ def main(args=None):
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) > 1:
|
||||
main()
|
||||
#sys.exit(0)
|
||||
sys.exit(main())
|
||||
import doctest, sys
|
||||
sys.exit(doctest.testmod().failed)
|
||||
|
@ -60,7 +60,6 @@ def main(args=None):
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) > 1:
|
||||
main()
|
||||
#sys.exit(0)
|
||||
sys.exit(main())
|
||||
import doctest, sys
|
||||
sys.exit(doctest.testmod().failed)
|
||||
|
@ -140,4 +140,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
import sys
|
||||
sys.exit(main())
|
||||
|
@ -13,7 +13,7 @@ def main(args=None):
|
||||
args = sys.argv[1:]
|
||||
if len(args) < 1:
|
||||
print("One argument, the input filename, must be provided.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
outfilename = makeOutputFileName(filename, outputDir=None, extension='.woff2')
|
||||
@ -26,4 +26,4 @@ def main(args=None):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
@ -23,7 +23,7 @@ def main(args=None):
|
||||
args = sys.argv[1:]
|
||||
if len(args) < 1:
|
||||
print("One argument, the input filename, must be provided.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
outfilename = make_output_name(filename)
|
||||
@ -36,4 +36,4 @@ def main(args=None):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(main())
|
||||
|
Loading…
x
Reference in New Issue
Block a user