-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satisfy python_dist setup_requires with a pex to resolve transitive d…
…eps, and some other unrelated native toolchain changes (#6275) ### Problem This PR solves two separate problems at once. It should have been split into two separate PRs earlier, but has undergone significant review and it would be a significant amount of unnecessary effort to do that at this point. #### Problem 1 The `setup_requires` kwarg of `python_dist()` holds addresses for `python_requirement_library()` targets. Currently, these requirements are fetched into a directory which is added to `PYTHONPATH`. This currently produces an invalid set of packages (for reasons I'm not quite sure of), which can cause errors on `import` statements within the `setup.py`. #### Problem 2 *See #6273 for more context on this second issue:* `distutils` does all sorts of things with our environment variables (e.g. adding `CFLAGS` to `LDFLAGS`), so until #6273 is merged, trying to modify anything but the `PATH` in the environment in which we invoke `setup.py` in for `python_dist()` targets causes lots of failures in many scenarios. ### Solution #### Solution 1: - Extract out the pex-building logic from the `Conan` subsystem into an `ExecutablePexTool` base class. - Collect `setup_requires` into a pex, using `ExecutablePexTool`. #### Solution 2 - Only modify the `PATH` in the environment dict produced from `SetupPyExecutionEnvironment`, no other env vars relevant to compilation. - Also, prepend our toolchain to the current PATH (commented inline, with a TODO pointing to #6273). - Add `LC_ALL=C` to the environment as well so compilation error output doesn't have decode errors on smart quotes. ### Result #### Result 1 `setup_requires` now fetches all necessary transitive deps into a pex, which means you can reliably import python requirements declared in `setup_requires` in the `python_dist()`'s `setup.py`. #### Result 2 Some of the native toolchain code is slightly simplified until #6273 is merged.
- Loading branch information
1 parent
81af00b
commit 6b11c59
Showing
17 changed files
with
296 additions
and
198 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
examples/src/python/example/python_distribution/hello/pants_setup_requires/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
main_file = 'main.py' | ||
|
||
python_dist( | ||
sources=rglobs('*.py', exclude=[main_file]), | ||
setup_requires=[ | ||
'testprojects/pants-plugins/3rdparty/python/pants', | ||
], | ||
) | ||
|
||
# TODO: add another python_binary() with compatibility=['CPython>=3.5'] once pants is released using | ||
# python 3. | ||
python_binary( | ||
name='bin', | ||
sources=[main_file], | ||
dependencies=[':pants_setup_requires'], | ||
) |
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions
13
examples/src/python/example/python_distribution/hello/pants_setup_requires/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 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 | ||
|
||
import pkg_resources | ||
|
||
|
||
hello_module_version = pkg_resources.get_distribution('hello_again').version | ||
|
||
if __name__ == '__main__': | ||
print(hello_module_version) |
15 changes: 15 additions & 0 deletions
15
examples/src/python/example/python_distribution/hello/pants_setup_requires/setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 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 setuptools import setup, find_packages | ||
|
||
from pants.version import VERSION as pants_version | ||
|
||
setup( | ||
name='hello_again', | ||
version=pants_version, | ||
packages=find_packages(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.