Skip to content

Commit

Permalink
Disallow versionless Python shebangs (pytorch#58275)
Browse files Browse the repository at this point in the history
Summary:
Some machines don't have a versionless `python` on their PATH, which breaks these existing shebangs.

I'm assuming that all the existing versionless `python` shebangs are meant to be `python3` and not `python2`; please let me know if my assumption was incorrect for any of these.

Pull Request resolved: pytorch#58275

Test Plan: CI.

Reviewed By: zhouzhuojie

Differential Revision: D28428143

Pulled By: samestep

fbshipit-source-id: 6562be3d12924db72a92a0207b060ef740f61ebf
  • Loading branch information
samestep authored and facebook-github-bot committed May 14, 2021
1 parent e6adc06 commit 2e26976
Show file tree
Hide file tree
Showing 32 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .circleci/ecr_gc_docker/docker_hub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from collections import namedtuple

Expand Down
2 changes: 1 addition & 1 deletion .circleci/ecr_gc_docker/gc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import boto3
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/generate_linux_ci_workflows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from pathlib import Path

Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/lint_native_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''
Verify that it is possible to round-trip native_functions.yaml via ruamel under some
configuration. Keeping native_functions.yaml consistent in this way allows us to
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/regenerate_cancel_redundant_workflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''
This file verifies that the workflows that are potentially canceled in our cancel_redundant_workflow.yml
match the workflows we have running on pull requests (found in .github/workflows). This way, anytime a
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ jobs:
if: always()
run: |
(! git --no-pager grep -In $'#include "' -- ./c10 ./aten ./torch/csrc ':(exclude)aten/src/ATen/native/quantized/cpu/qnnpack/**' || (echo "The above lines have include with quotes; please convert them to #include <xxxx>"; false))
- name: Ensure no versionless Python shebangs
if: always()
run: |
(! git --no-pager grep -In '#!.*python$' -- . || (echo "The above lines have versionless Python shebangs; please specify either python2 or python3"; false))
- name: Ensure no unqualified noqa
if: always()
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import subprocess
import os
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ quick_checks:
--step 'Ensure no tabs' \
--step 'Ensure no non-breaking spaces' \
--step 'Ensure canonical include' \
--step 'Ensure no versionless Python shebangs' \
--step 'Ensure no unqualified noqa' \
--step 'Ensure no unqualified type ignore' \
--step 'Ensure no direct cub include' \
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/quantized/cpu/qnnpack/configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion binaries/bench_gen/bench_gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import ast
Expand Down
2 changes: 1 addition & 1 deletion caffe2/contrib/aten/gen_op.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/env python
#!/bin/env python3

# Copyright (c) 2016-present, Facebook, Inc.
#
Expand Down
2 changes: 1 addition & 1 deletion caffe2/contrib/gloo/gloo_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3



Expand Down
2 changes: 1 addition & 1 deletion caffe2/core/nomnigraph/op_gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3



Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/allcompare_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3



Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/benchmark_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3



Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/lazy_dyndep_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3



Expand Down
2 changes: 1 addition & 1 deletion scripts/model_zoo/update-caffe2-models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

import os
import subprocess
Expand Down
2 changes: 1 addition & 1 deletion scripts/model_zoo/update-models-from-caffe2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

import onnx.backend

Expand Down
2 changes: 1 addition & 1 deletion test/run_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import copy
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/run_cuda_memcheck.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""This script runs cuda-memcheck on the specified unit test. Each test case
is run in its isolated process with a timeout so that:
Expand Down
8 changes: 4 additions & 4 deletions test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def test_assert_messages(self, device):
def test_cuda_assert_should_stop_common_utils_test_suite(self, device):
# test to ensure common_utils.py override has early termination for CUDA.
stderr = TestCase.runWithPytorchAPIUsageStderr("""\
#!/usr/bin/env python
#!/usr/bin/env python3
import torch
from torch.testing._internal.common_utils import (TestCase, run_tests, slowTest)
Expand Down Expand Up @@ -522,7 +522,7 @@ def test_trivial_passing_test_case_on_cpu_cuda(self):
def test_cuda_assert_should_stop_common_device_type_test_suite(self, device):
# test to ensure common_device_type.py override has early termination for CUDA.
stderr = TestCase.runWithPytorchAPIUsageStderr("""\
#!/usr/bin/env python
#!/usr/bin/env python3
import torch
from torch.testing._internal.common_utils import (TestCase, run_tests, slowTest)
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_trivial_passing_test_case_on_cpu_cuda(self, device):
def test_cuda_assert_should_not_stop_common_distributed_test_suite(self, device):
# test to ensure common_distributed.py override should not early terminate CUDA.
stderr = TestCase.runWithPytorchAPIUsageStderr("""\
#!/usr/bin/env python
#!/usr/bin/env python3
import torch
from torch.testing._internal.common_utils import (run_tests, slowTest)
Expand Down Expand Up @@ -698,7 +698,7 @@ def test_calculate_2_shards_against_optimal_shards(self):
def test_filtering_env_var(self):
# Test environment variable selected device type test generator.
test_filter_file_template = """\
#!/usr/bin/env python
#!/usr/bin/env python3
import torch
from torch.testing._internal.common_utils import (TestCase, run_tests)
Expand Down
2 changes: 1 addition & 1 deletion tools/amd_build/build_amd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3


import os
Expand Down
2 changes: 1 addition & 1 deletion tools/clang_tidy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
A driver script to run clang-tidy on changes detected via git.
Expand Down
2 changes: 1 addition & 1 deletion tools/code_coverage/oss_coverage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import time

from package.oss.cov_json import get_json_report
Expand Down
2 changes: 1 addition & 1 deletion tools/export_slow_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import json
Expand Down
2 changes: 1 addition & 1 deletion tools/flake8_hook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import sys

Expand Down
2 changes: 1 addition & 1 deletion tools/git-clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# ===- git-clang-format - ClangFormat Git Integration ---------*- python -*--===#
#
Expand Down
2 changes: 1 addition & 1 deletion torch/_appdirs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2005-2010 ActiveState Software Inc.
# Copyright (c) 2013 Eddy Petrișor
Expand Down
2 changes: 1 addition & 1 deletion torch/utils/hipify/hipify_python.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
""" The Python Hipify script.
##
# Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion torch/utils/model_dump/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
model_dump: a one-stop shop for TorchScript model inspection.
Expand Down
2 changes: 1 addition & 1 deletion torch/utils/model_dump/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
from . import main

Expand Down

0 comments on commit 2e26976

Please sign in to comment.