Skip to content

Instantly share code, notes, and snippets.

@cosmicexplorer
Last active May 11, 2019 01:48
Show Gist options
  • Save cosmicexplorer/e6908a1af816351944a4584e1db7f89c to your computer and use it in GitHub Desktop.
Save cosmicexplorer/e6908a1af816351944a4584e1db7f89c to your computer and use it in GitHub Desktop.
checking out https://github.com/pantsbuild/pants at 4dafc870ece338be7bbba4e44ee1e416e27e9afb, then running test-bisect.zsh, should show that pex==1.5.3 suceeds, and pex==1.6.0 errors out at import time for the google-cloud-bigquery package.
diff --git a/3rdparty/python/requirements.txt b/3rdparty/python/requirements.txt
index 9c0e693..0b93f20 100644
--- a/3rdparty/python/requirements.txt
+++ b/3rdparty/python/requirements.txt
@@ -17,7 +17,7 @@ more-itertools<6.0.0 ; python_version<'3'
packaging==16.8
parameterized==0.6.1
pathspec==0.5.9
-pex==1.6.6
+pex==1.5.3
psutil==5.4.8
pycodestyle==2.4.0
pyflakes==2.0.0
diff --git a/examples/3rdparty/python/BUILD b/examples/3rdparty/python/BUILD
index 1cee054..474b97b 100644
--- a/examples/3rdparty/python/BUILD
+++ b/examples/3rdparty/python/BUILD
@@ -4,6 +4,13 @@
# see/edit requirements.txt in this directory to change deps.
python_requirements()
+python_requirement_library(
+ name='google-cloud-bigquery',
+ requirements=[
+ python_requirement('google-cloud-bigquery==1.10.0'),
+ ],
+)
+
remote_sources(
name='tensorflow-framework',
dest=packaged_native_library,
diff --git a/examples/tests/python/example_test/pkg_resources_access/BUILD b/examples/tests/python/example_test/pkg_resources_access/BUILD
new file mode 100644
index 0000000..bb0d334
--- /dev/null
+++ b/examples/tests/python/example_test/pkg_resources_access/BUILD
@@ -0,0 +1,17 @@
+# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
+# Licensed under the Apache License, Version 2.0 (see LICENSE).
+
+python_tests(
+ dependencies=[
+ 'tests/python/pants_test:int-test',
+ 'examples/3rdparty/python:google-cloud-bigquery',
+ ],
+)
+
+python_binary(
+ name='bin',
+ source='main.py',
+ dependencies=[
+ 'examples/3rdparty/python:google-cloud-bigquery',
+ ],
+)
diff --git a/examples/tests/python/example_test/pkg_resources_access/__init__.py b/examples/tests/python/example_test/pkg_resources_access/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/examples/tests/python/example_test/pkg_resources_access/main.py b/examples/tests/python/example_test/pkg_resources_access/main.py
new file mode 100644
index 0000000..e52939c
--- /dev/null
+++ b/examples/tests/python/example_test/pkg_resources_access/main.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
+# Licensed under the Apache License, Version 2.0 (see LICENSE).
+
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+from google.cloud import bigquery
+
+
+print('bigquery, version {}'.format(bigquery.__version__))
diff --git a/examples/tests/python/example_test/pkg_resources_access/test_bigquery_python_run.py b/examples/tests/python/example_test/pkg_resources_access/test_bigquery_python_run.py
new file mode 100644
index 0000000..a749827
--- /dev/null
+++ b/examples/tests/python/example_test/pkg_resources_access/test_bigquery_python_run.py
@@ -0,0 +1,25 @@
+# coding=utf-8
+# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
+# Licensed under the Apache License, Version 2.0 (see LICENSE).
+
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+from google.cloud import bigquery
+from pants_test.pants_run_integration_test import PantsRunIntegrationTest
+
+
+# TODO: ???/explain how you as a user can write pants integration tests, e.g. for binaries you want
+# to make sure work in CI.
+class TestBigqueryPythonRun(PantsRunIntegrationTest):
+
+ # TODO: is this test definitely run in CI?
+ def test_bigquery_python_run(self):
+ pants_run = self.do_command(
+ # "--python-setup-interpreter-constraints=['CPython>=2.7,<3']",
+ 'run',
+ 'examples/tests/python/example_test/pkg_resources_access:bin',
+ )
+ # Using `-q` in self.do_command() doesn't appear to be making pants run quietly here, but we can
+ # rely on the output containing exactly this line.
+ self.assertIn('\nbigquery, version {}\n'.format(bigquery.__version__),
+ pants_run.stdout_data)
#!/usr/bin/env zsh
set -euxo pipefail
export MODE=debug
export PANTS_ENABLE_PANTSD=False
if [[ ! -f 'examples/tests/python/example_test/pkg_resources_access/BUILD' ]]; then
git apply repro-bigquery.diff
trap "git checkout -- examples/ && git clean -xfd -- examples/" EXIT
fi
./pants clean-all
./pants test examples/tests/python/example_test/pkg_resources_access -- -vs
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment