Bazel-ify most of the Python scripts. (#229)

This commit is contained in:
Jon Meow
2020-12-28 16:37:55 -08:00
committed by GitHub
parent 4290e1845b
commit d76f8a1eff
14 changed files with 133 additions and 43 deletions
+35
View File
@@ -0,0 +1,35 @@
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
py_library(
name = "proposals",
srcs = ["proposals.py"],
)
py_test(
name = "proposals_test",
srcs = ["proposals_test.py"],
deps = [":proposals"],
)
py_binary(
name = "new_proposal",
srcs = ["new_proposal.py"],
)
py_test(
name = "new_proposal_test",
srcs = ["new_proposal_test.py"],
data = ["//proposals:template.md"],
deps = [":new_proposal"],
)
# This is a directly runnable script, but should not be run via bazel.
py_library(
name = "update_proposal_list",
srcs = ["update_proposal_list.py"],
deps = [":proposals"],
)
-6
View File
@@ -9,9 +9,3 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Scripts for use with proposals.
See individual scripts for more details.
Please use `pytest` for testing:
```
$ pip install pytest
```
+3 -2
View File
@@ -12,7 +12,7 @@ import os
import unittest
from unittest import mock
from proposals.scripts import new_proposal
from carbon.proposals.scripts import new_proposal
class FakeExitError(Exception):
@@ -61,7 +61,8 @@ class TestNewProposal(unittest.TestCase):
def test_run_failure(self):
with mock.patch(
"proposals.scripts.new_proposal._exit", side_effect=_fake_exit
"carbon.proposals.scripts.new_proposal._exit",
side_effect=_fake_exit,
):
self.assertRaises(FakeExitError, new_proposal._run, ["false"])
+1 -1
View File
@@ -8,7 +8,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import unittest
from proposals.scripts import proposals
from carbon.proposals.scripts import proposals
class TestProposal(unittest.TestCase):
+10 -6
View File
@@ -10,15 +10,19 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import io
import os
import importlib.util
import re
import sys
# To support direct runs, ensure the pythonpath has the repo root.
_PYTHONPATH = os.path.realpath(os.path.join(os.path.dirname(__file__), "../.."))
if _PYTHONPATH not in sys.path:
sys.path.insert(0, _PYTHONPATH)
from proposals.scripts import proposals
# Do some extra work to support direct runs.
try:
from carbon.proposals.scripts import proposals
except ImportError:
proposals_spec = importlib.util.spec_from_file_location(
"proposals", os.path.join(os.path.dirname(__file__), "proposals.py")
)
proposals = importlib.util.module_from_spec(proposals_spec)
proposals_spec.loader.exec_module(proposals)
if __name__ == "__main__":
proposals_path = proposals.get_path()