Skip to content

Commit

Permalink
Clean up script entry points (#185)
Browse files Browse the repository at this point in the history
Two factors here:
1. Ensure that each script has an explicit main() function.
2. Ensure that the return value of main() is the return value of the
   program when the script is invoked directly.
  • Loading branch information
cottsay authored Jun 28, 2024
1 parent b4f8881 commit 6015280
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/rosdistro
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def main():


if __name__ == "__main__":
main()
sys.exit(main())
4 changes: 2 additions & 2 deletions scripts/rosdistro_build_cache
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def main():
ignore_local=args.ignore_local, include_source=args.include_source, debug=args.debug)
except RuntimeError as e:
print(str(e), file=sys.stderr)
sys.exit(1)
return 1

for dist_name, cache in caches.items():
if args.dist_names and dist_name not in args.dist_names:
Expand All @@ -101,4 +101,4 @@ def main():


if __name__ == '__main__':
main()
sys.exit(main())
6 changes: 5 additions & 1 deletion scripts/rosdistro_convert
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,14 @@ def convert_doc(dist_name):
f.write(yaml_str)


if __name__ == '__main__':
def main():
targets = get_targets()
for distro in ['groovy', 'hydro']:
print('\nConverting "%s"\n' % distro)
convert_release(distro, targets)
convert_source(distro)
convert_doc(distro)


if __name__ == '__main__':
sys.exit(main())
2 changes: 1 addition & 1 deletion scripts/rosdistro_freeze_source
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ def main():


if __name__ == '__main__':
main()
sys.exit(main())
2 changes: 1 addition & 1 deletion scripts/rosdistro_generate_cache
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def main():


if __name__ == "__main__":
main()
sys.exit(main())
7 changes: 6 additions & 1 deletion scripts/rosdistro_migrate_to_rep_141
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import gzip
import os
import sys

try:
from cStringIO import StringIO
Expand Down Expand Up @@ -163,9 +164,13 @@ def get_dict_parts(d, keys):
return data


if __name__ == "__main__":
def main():
parser = argparse.ArgumentParser(description='Migrate the distros from REP 137 to REP 141.')
parser.add_argument('index', help='The index.yaml file to migrate')
args = parser.parse_args()

migrate(args.index)


if __name__ == "__main__":
sys.exit(main())
7 changes: 6 additions & 1 deletion scripts/rosdistro_migrate_to_rep_143
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import sys

from rosdistro.verify import _yaml_header_lines

Expand Down Expand Up @@ -32,9 +33,13 @@ def index_to_yaml(data):
return yaml_str


if __name__ == "__main__":
def main():
parser = argparse.ArgumentParser(description='Migrate the distros from REP 141 to REP 143.')
parser.add_argument('index', help='The index.yaml file to migrate')
args = parser.parse_args()

migrate(args.index)


if __name__ == "__main__":
sys.exit(main())
8 changes: 6 additions & 2 deletions scripts/rosdistro_reformat
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def parse_args(args=sys.argv[1:]):
return parser.parse_args(args)


if __name__ == '__main__':
def main():
args = parse_args()
index = args.index
if os.path.isfile(index):
Expand All @@ -64,4 +64,8 @@ if __name__ == '__main__':
success = verify_files_identical(index)
else:
success = reformat_files(index)
sys.exit(0 if success else 1)
return 0 if success else 1


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 6015280

Please sign in to comment.