Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 431caac

Browse filesBrowse files
gibfahnalexeagle
andauthored
pip: entry_point: Add support for exit codes (bazel-contrib#550)
Co-authored-by: Alex Eagle <eagle@post.harvard.edu>
1 parent 0b11480 commit 431caac
Copy full SHA for 431caac

File tree

11 files changed

+481
-97
lines changed
Filter options

11 files changed

+481
-97
lines changed

‎examples/pip_install/BUILD

Copy file name to clipboardExpand all lines: examples/pip_install/BUILD
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ py_test(
5252

5353
# For pip dependencies which have entry points, the `entry_point` macro can be
5454
# used from the generated `pip_install` repository to access a runnable binary.
55+
56+
alias(
57+
name = "sphinx-build",
58+
actual = entry_point(
59+
pkg = "sphinx",
60+
script = "sphinx-build",
61+
),
62+
)
63+
5564
alias(
5665
name = "yamllint",
5766
actual = entry_point("yamllint"),
@@ -68,14 +77,16 @@ py_test(
6877
name = "pip_install_test",
6978
srcs = ["pip_install_test.py"],
7079
data = [
80+
":sphinx-build",
7181
":yamllint",
7282
data_requirement("s3cmd"),
7383
dist_info_requirement("boto3"),
7484
],
7585
env = {
86+
"SPHINX_BUILD_ENTRY_POINT": "$(rootpath :sphinx-build)",
7687
"WHEEL_DATA_CONTENTS": "$(rootpaths {})".format(data_requirement("s3cmd")),
7788
"WHEEL_DIST_INFO_CONTENTS": "$(rootpaths {})".format(dist_info_requirement("boto3")),
78-
"WHEEL_ENTRY_POINT": "$(rootpath :yamllint)",
89+
"YAMLLINT_ENTRY_POINT": "$(rootpath :yamllint)",
7990
},
8091
)
8192

‎examples/pip_install/pip_install_test.py

Copy file name to clipboardExpand all lines: examples/pip_install/pip_install_test.py
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
class PipInstallTest(unittest.TestCase):
1010
maxDiff = None
1111

12-
def test_entry_point(self):
13-
env = os.environ.get("WHEEL_ENTRY_POINT")
12+
def test_entry_point_void_return(self):
13+
env = os.environ.get("YAMLLINT_ENTRY_POINT")
1414
self.assertIsNotNone(env)
1515

1616
entry_point = Path(env)
@@ -19,6 +19,27 @@ def test_entry_point(self):
1919
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2020
self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
2121

22+
# yamllint entry_point is of the form `def run(argv=None):`
23+
with self.assertRaises(subprocess.CalledProcessError) as context:
24+
subprocess.run([entry_point, "--option-does-not-exist"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25+
self.assertIn('returned non-zero exit status 2', str(context.exception))
26+
27+
def test_entry_point_int_return(self):
28+
env = os.environ.get("SPHINX_BUILD_ENTRY_POINT")
29+
self.assertIsNotNone(env)
30+
31+
entry_point = Path(env)
32+
self.assertTrue(entry_point.exists())
33+
34+
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
35+
# sphinx-build uses args[0] for its name, only assert the version here
36+
self.assertTrue(proc.stdout.decode("utf-8").strip().endswith('4.2.0'))
37+
38+
# sphinx-build entry_point is of the form `def main(argv: List[str] = sys.argv[1:]) -> int:`
39+
with self.assertRaises(subprocess.CalledProcessError) as context:
40+
subprocess.run([entry_point, "--option-does-not-exist"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41+
self.assertIn('returned non-zero exit status 2', str(context.exception))
42+
2243
def test_data(self):
2344
env = os.environ.get("WHEEL_DATA_CONTENTS")
2445
self.assertIsNotNone(env)

‎examples/pip_install/requirements.in

Copy file name to clipboardExpand all lines: examples/pip_install/requirements.in
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
boto3==1.14.51
2+
s3cmd==2.1.0
3+
sphinx==4.2.0
24
yamllint==1.26.3
3-
s3cmd==2.1.0

‎examples/pip_install/requirements.txt

Copy file name to clipboardExpand all lines: examples/pip_install/requirements.txt
+182-36Lines changed: 182 additions & 36 deletions
Large diffs are not rendered by default.

‎examples/pip_parse/BUILD

Copy file name to clipboardExpand all lines: examples/pip_parse/BUILD
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ py_test(
5050

5151
# For pip dependencies which have entry points, the `entry_point` macro can be
5252
# used from the generated `pip_parse` repository to access a runnable binary.
53+
5354
alias(
54-
name = "yamllint",
55-
# If `pkg` and `script` are the same, passing a single string to
56-
# `entry_point` would work as well: `entry_point("yamllint")`
55+
name = "sphinx-build",
5756
actual = entry_point(
58-
pkg = "yamllint",
59-
script = "yamllint",
57+
pkg = "sphinx",
58+
script = "sphinx-build",
6059
),
6160
)
6261

62+
alias(
63+
name = "yamllint",
64+
actual = entry_point("yamllint"),
65+
)
66+
6367
# This rule adds a convenient way to update the requirements file.
6468
compile_pip_requirements(
6569
name = "requirements",
@@ -73,13 +77,15 @@ py_test(
7377
name = "pip_parse_test",
7478
srcs = ["pip_parse_test.py"],
7579
data = [
80+
":sphinx-build",
7681
":yamllint",
7782
data_requirement("s3cmd"),
7883
dist_info_requirement("requests"),
7984
],
8085
env = {
86+
"SPHINX_BUILD_ENTRY_POINT": "$(rootpath :sphinx-build)",
8187
"WHEEL_DATA_CONTENTS": "$(rootpaths {})".format(data_requirement("s3cmd")),
8288
"WHEEL_DIST_INFO_CONTENTS": "$(rootpaths {})".format(dist_info_requirement("requests")),
83-
"WHEEL_ENTRY_POINT": "$(rootpath :yamllint)",
89+
"YAMLLINT_ENTRY_POINT": "$(rootpath :yamllint)",
8490
},
8591
)

‎examples/pip_parse/pip_parse_test.py

Copy file name to clipboardExpand all lines: examples/pip_parse/pip_parse_test.py
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
class PipInstallTest(unittest.TestCase):
1010
maxDiff = None
1111

12-
def test_entry_point(self):
13-
env = os.environ.get("WHEEL_ENTRY_POINT")
12+
def test_entry_point_void_return(self):
13+
env = os.environ.get("YAMLLINT_ENTRY_POINT")
1414
self.assertIsNotNone(env)
1515

1616
entry_point = Path(env)
@@ -19,6 +19,27 @@ def test_entry_point(self):
1919
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2020
self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
2121

22+
# yamllint entry_point is of the form `def run(argv=None):`
23+
with self.assertRaises(subprocess.CalledProcessError) as context:
24+
subprocess.run([entry_point, "--option-does-not-exist"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25+
self.assertIn('returned non-zero exit status 2', str(context.exception))
26+
27+
def test_entry_point_int_return(self):
28+
env = os.environ.get("SPHINX_BUILD_ENTRY_POINT")
29+
self.assertIsNotNone(env)
30+
31+
entry_point = Path(env)
32+
self.assertTrue(entry_point.exists())
33+
34+
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
35+
# sphinx-build uses args[0] for its name, only assert the version here
36+
self.assertTrue(proc.stdout.decode("utf-8").strip().endswith('4.2.0'))
37+
38+
# sphinx-build entry_point is of the form `def main(argv: List[str] = sys.argv[1:]) -> int:`
39+
with self.assertRaises(subprocess.CalledProcessError) as context:
40+
subprocess.run([entry_point, "--option-does-not-exist"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41+
self.assertIn('returned non-zero exit status 2', str(context.exception))
42+
2243
def test_data(self):
2344
env = os.environ.get("WHEEL_DATA_CONTENTS")
2445
self.assertIsNotNone(env)

‎examples/pip_parse/requirements.txt

Copy file name to clipboardExpand all lines: examples/pip_parse/requirements.txt
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
requests==2.25.1
2+
s3cmd==2.1.0
3+
sphinx==4.2.0
24
yamllint==1.26.3
3-
s3cmd==2.1.0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.