Skip to content

Instantly share code, notes, and snippets.

@janosh
Last active August 14, 2021 18:42
Show Gist options
  • Save janosh/ce1fee6d8749f9ec9272aea5b11a256b to your computer and use it in GitHub Desktop.
Save janosh/ce1fee6d8749f9ec9272aea5b11a256b to your computer and use it in GitHub Desktop.
Shell script to upgrade a Python 2 project to Python 3.
#!/bin/sh
# Shell script to upgrade a Python 2 project to Python 3.
# If it's a TensorFlow project consider running afterwards:
# tf_upgrade_v2 --intree . --outtree . --reportfile tf2_report.txt
# [ -x "$(command -v some_binary)" ] checks whether some_binary is
# in path and executable. See https://stackoverflow.com/a/26759734.
if [ -x "$(command -v 2to3)" ]; then
2to3 -w -n .
fi
# pip install black
if [ -x "$(command -v black)" ]; then
black **/*.py
fi
# pip install pyupgrade
if [ -x "$(command -v pyupgrade)" ]; then
pyupgrade --py39-plus **/*.py
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment