Skip to content

Commit 0509d31

Browse files
arthaudmeta-codesync[bot]
authored andcommitted
Replace --run-from-* boolean flags with a single --run-from option
Reviewed By: tianhan0 Differential Revision: D108142946 fbshipit-source-id: e302f70c047af6aee7854bd18e209e62d3578e43
1 parent 2d9b433 commit 0509d31

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

documentation/deliberately_vulnerable_flask_app/run_integration_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
cd "$(dirname "$0")" || exit
88
exec python3 ../../tools/pysa_integration_tests/run.py \
99
--skip-model-verification \
10-
--run-from-source \
10+
--run-from=python-package \
1111
--ignore-positions \
1212
--write-actual-results-on-failure \
1313
"$@"

tools/pysa_integration_tests/run.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def main(
3030
filter_issues: bool,
3131
skip_model_verification: bool,
3232
skip_model_verification_with_pyrefly: bool,
33-
run_from_source: bool,
34-
run_from_buck: bool,
33+
run_from: test_runner_lib.RunFrom,
3534
passthrough_args: Optional[List[str]],
3635
save_results_to: Optional[Path],
3736
typeshed: Optional[Path],
@@ -67,8 +66,7 @@ def main(
6766
pysa_results = test_runner_lib.run_pysa(
6867
passthrough_args=passthrough_args,
6968
skip_model_verification=skip_model_verification,
70-
run_from_source=run_from_source,
71-
run_from_buck=run_from_buck,
69+
run_from=run_from,
7270
save_results_to=save_results_to,
7371
typeshed=typeshed,
7472
compact_ocaml_heap=compact_ocaml_heap,
@@ -108,15 +106,21 @@ def main(
108106
action="store_true",
109107
help="Skip model verification when using pyrefly",
110108
)
109+
parser.add_argument(
110+
"--run-from",
111+
choices=[run_from.value for run_from in test_runner_lib.RunFrom],
112+
default=test_runner_lib.RunFrom.PYRE_IN_PATH.value,
113+
help="How to run pysa: `pyre-in-path` (default; uses the `pyre` client on PATH), `python-package` (open source setup, runs `python -mpyre-check.client.pyre`), `internal-buck` (runs `buck run fbcode//tools/pyre/facebook/client:pysa`), or `oss-buck` (runs `buck run fbcode//tools/pyre/client:pyre`).",
114+
)
111115
parser.add_argument(
112116
"--run-from-source",
113117
action="store_true",
114-
help="Run pysa from source with the open source setup",
118+
help="Deprecated alias for --run-from=python-package",
115119
)
116120
parser.add_argument(
117121
"--run-from-buck",
118122
action="store_true",
119-
help="Run pysa from buck with `buck run fbcode//tools/pyre/facebook/client:pysa`",
123+
help="Deprecated alias for --run-from=internal-buck",
120124
)
121125
parser.add_argument(
122126
"--require-pyre-env",
@@ -169,13 +173,17 @@ def main(
169173
)
170174

171175
parsed: argparse.Namespace = parser.parse_args()
176+
run_from = test_runner_lib.RunFrom(parsed.run_from)
177+
if parsed.run_from_source:
178+
run_from = test_runner_lib.RunFrom.PYTHON_PACKAGE
179+
elif parsed.run_from_buck:
180+
run_from = test_runner_lib.RunFrom.INTERNAL_BUCK
172181
main(
173182
working_directory=parsed.working_directory or Path(os.getcwd()),
174183
filter_issues=parsed.filter_issues,
175184
skip_model_verification=parsed.skip_model_verification,
176185
skip_model_verification_with_pyrefly=parsed.skip_model_verification_with_pyrefly,
177-
run_from_source=parsed.run_from_source,
178-
run_from_buck=parsed.run_from_buck,
186+
run_from=run_from,
179187
passthrough_args=parsed.passthrough_args,
180188
save_results_to=parsed.save_results_to,
181189
typeshed=parsed.typeshed,

tools/pysa_integration_tests/runner_lib.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class ExitCode(enum.IntEnum):
5858
TEST_MODEL_VERIFICATION_ERROR = 31
5959

6060

61+
class RunFrom(enum.Enum):
62+
PYRE_IN_PATH = "pyre-in-path"
63+
PYTHON_PACKAGE = "python-package"
64+
INTERNAL_BUCK = "internal-buck"
65+
OSS_BUCK = "oss-buck"
66+
67+
6168
def is_test_function(define: str, code: int) -> bool:
6269
return f"test_{code}_" in define
6370

@@ -209,8 +216,7 @@ def run_pysa(
209216
isolation_prefix: Optional[str] = None,
210217
repository_root: Optional[Path] = None,
211218
excludes: Optional[Sequence[str]] = None,
212-
run_from_source: bool = False,
213-
run_from_buck: bool = False,
219+
run_from: RunFrom = RunFrom.PYRE_IN_PATH,
214220
typeshed: Optional[Path] = None,
215221
compact_ocaml_heap: bool = False,
216222
check_invariants: bool = False,
@@ -225,20 +231,29 @@ def run_pysa(
225231
skip_buck_dependencies: bool = False,
226232
) -> str:
227233
"""Run pysa for the given test and produce a list of errors in JSON."""
228-
if run_from_source:
234+
if run_from == RunFrom.PYRE_IN_PATH:
235+
command = ["pyre"]
236+
elif run_from == RunFrom.PYTHON_PACKAGE:
229237
command = [
230238
"python",
231239
"-mpyre-check.client.pyre",
232240
]
233-
elif run_from_buck:
241+
elif run_from == RunFrom.INTERNAL_BUCK:
234242
command = [
235243
"buck",
236244
"run",
237245
"fbcode//tools/pyre/facebook/client:pysa",
238246
"--",
239247
]
248+
elif run_from == RunFrom.OSS_BUCK:
249+
command = [
250+
"buck",
251+
"run",
252+
"fbcode//tools/pyre/client:pyre",
253+
"--",
254+
]
240255
else:
241-
command = ["pyre"]
256+
raise ValueError(f"Unexpected run_from value: {run_from}")
242257

243258
command.append("--noninteractive")
244259

0 commit comments

Comments
 (0)