-
Notifications
You must be signed in to change notification settings - Fork 1.2k
More pex fixes for windows. #614
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@echo off | ||
set PYTHONPATH=%~dp0..\third-party\nailgun | ||
python %~dp0..\programs\buck.py %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
from __future__ import absolute_import | ||
|
||
import contextlib | ||
import os | ||
import subprocess | ||
import tempfile | ||
|
||
|
@@ -58,6 +60,17 @@ def main(root, relpaths): | |
""" | ||
|
||
|
||
@contextlib.contextmanager | ||
def named_temporary_file(): | ||
fp, path = tempfile.mkstemp() | ||
os.close(fp) | ||
try: | ||
with open(path, 'w') as fp: | ||
yield fp | ||
finally: | ||
os.remove(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to try this when I get into the office, but when I was using something like, this, I was getting an exception with the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hit that too, but it wasn't the subprocess call - it was the fp returned by mkstemp |
||
|
||
|
||
class Compiler(object): | ||
class Error(Exception): | ||
"""Indicates an error compiling one or more python source files.""" | ||
|
@@ -78,7 +91,7 @@ def compile(self, root, relpaths): | |
:returns: A list of relative paths of the compiled bytecode files. | ||
:raises: A :class:`Compiler.Error` if there was a problem bytecode compiling any of the files. | ||
""" | ||
with tempfile.NamedTemporaryFile() as fp: | ||
with named_temporary_file() as fp: | ||
fp.write(to_bytes(_COMPILER_MAIN % {'root': root, 'relpaths': relpaths}, encoding='utf-8')) | ||
fp.flush() | ||
process = subprocess.Popen([self._interpreter.binary, fp.name], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,9 @@ def _site_libs(cls): | |
site_libs = set() | ||
site_libs.update([sysconfig.get_python_lib(plat_specific=False), | ||
sysconfig.get_python_lib(plat_specific=True)]) | ||
# On windows getsitepackages() returns the python stdlib too. | ||
if sys.prefix in site_libs: | ||
site_libs.remove(sys.prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find. I wasn't familiar with this issues, and I'm curious how you came across it; care to elaborate here (just on Github; the code is fine as-is). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the crash you saw was an extreme example of the bug - the windows box I used to test doesn't have any packages installed, so the actual thing I saw was an |
||
real_site_libs = set(os.path.realpath(path) for path in site_libs) | ||
return site_libs | real_site_libs | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can actually avoid this path entirely if we just modify the code in
src/com/facebook/buck/python/make_pex.py
to prefer to copy on Windows. I had originally wrote something like this, but @andrewjcg suggested changing Buck's code so it was fewer changes to PEX itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually going to try to upstream these in pex-tool/pex#198
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You rock!