Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add torchfix --version #14

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions torchfix/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import io

from .torchfix import TorchCodemod, TorchCodemodConfig
from .torchfix import TorchCodemod, TorchCodemodConfig, __version__ as TorchFixVersion
from .common import CYAN, ENDC


Expand All @@ -14,7 +14,8 @@ def main() -> None:

parser.add_argument(
"path",
nargs="+",
nargs="*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior is intentional to mimic ruff's API.

Copy link
Contributor Author

@seemethere seemethere Jan 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torchfix --version won't work otherwise since the invocation will have to look like torchfix --version .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context this is what this looks like if you don't change that:

❯ torchfix --version
usage: torchfix [-h] [--fix] [-j JOBS] [--select {ALL}] [--version] [--show-stderr] path [path ...]
torchfix: error: the following arguments are required: path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's a bigger change, but torchfix --version should work, and just torchfix should print help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nargs is fine, but without default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay changed!

default=["."],
help=("Path to check/fix. Can be a directory, a file, or multiple of either."),
)
parser.add_argument(
Expand All @@ -36,6 +37,11 @@ def main() -> None:
"ALL",
],
)
parser.add_argument(
"--version",
action="store_true",
help="Print current version.",
)

# XXX TODO: Get rid of this!
# Silence "Failed to determine module name"
Expand All @@ -47,6 +53,11 @@ def main() -> None:

args = parser.parse_args()

if args.version:
# TODO: Perhaps add commit hash here if we can
print(f"{TorchFixVersion}")
sys.exit(0)

files = codemod.gather_files(args.path)

# Filter out files that don't have "torch" string in them.
Expand Down
Loading