Skip to content

Commit

Permalink
Debug session 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Livingston committed Jan 30, 2018
1 parent c340abf commit 4b65461
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# Like Hello world, but built with a python_distribution.
# python_distribution allows you to use setup.py to depend on C/C++ extensions.

python_distribution(
python_dist(
name='superhello',
sources=[
'super_greet.c',
'hello.py',
'hello_package/hello.py',
'hello_package/__init__.py',
'setup.py'
]
)
Expand Down
Empty file.
1 change: 1 addition & 0 deletions src/python/pants/backend/python/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def build_file_aliases():
PythonLibrary.alias(): PythonLibrary,
PythonTests.alias(): PythonTests,
PythonDistribution.alias(): TargetMacro.Factory.wrap(PythonDistribution.create, PythonDistribution),
'python_dist': PythonDistribution,
'python_requirement_library': PythonRequirementLibrary,
Resources.alias(): Resources,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os

from twitter.common.collections import maybe_list

Expand Down Expand Up @@ -63,11 +64,7 @@ def __init__(self,
except ValueError as e:
raise TargetDefinitionException(self, str(e))


@classmethod
def alias(cls):
def get_alias(cls):
return 'python_dist'

def __init__(self, **kwargs):
payload = Payload()
super(PythonDistribution, self).__init__(sources=[], payload=payload, **kwargs)
19 changes: 3 additions & 16 deletions src/python/pants/backend/python/tasks/pex_build_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.backend.python.targets.python_tests import PythonTests
from pants.backend.python.tasks2.setup_py import SetupPyRunner
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.build_graph.files import Files
Expand Down Expand Up @@ -193,21 +192,9 @@ def build_python_distribution(dist_tgt, interpreter, workdir, log):
for source in sources:
shutil.copyfile(os.path.join(buildroot, source), os.path.join(tmp_dir_for_dist, source))

# build the whl from pex API using tempdir and get its location
install_dir = os.path.join(dist_target_dir, 'dist')
if not install_dir:
safe_mkdir(install_dir)
setup_runner = SetupPyRunner(tmp_dir_for_dist, 'bdist_wheel', interpreter=interpreter, install_dir=install_dir)
setup_runner.run()

# return the location of the whl on disk (somewhere in pantsd or dist)
dists = os.listdir(self.install_tmp)
if len(dists) == 0:
raise TaskError('No distributions were produced by python_create_distribution task.')
elif len(dists) > 1:
raise TaskError('Ambiguous whls found: %s' % (' '.join(dists)))
else:
return os.path.join(self.install_tmp, dists[0])

return (tmp_dir_for_dist, install_dir)



def _resolve_multi(interpreter, requirements, platforms, find_links):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from pex.pex_info import PexInfo

from pants.backend.python.targets.python_binary import PythonBinary
from pants.backend.python.tasks2.pex_build_util import (dump_python_distributions,
dump_requirements, dump_sources,
from pants.backend.python.tasks2.pex_build_util import (dump_requirements, dump_sources,
has_python_requirements, has_python_sources,
has_resources, is_local_python_dist)
from pants.base.build_environment import get_buildroot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pex.pex import PEX
from pex.pex_builder import PEXBuilder

from pants.backend.python.tasks2.pex_build_util import dump_python_distributions, dump_requirements
from pants.backend.python.tasks2.pex_build_util import dump_requirements
from pants.invalidation.cache_manager import VersionedTargetSet
from pants.task.task import Task
from pants.util.dirutil import safe_concurrent_creation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
dump_requirements, dump_sources,
has_python_requirements, has_python_sources,
has_resources, is_local_python_dist)
from pants.backend.python.tasks2.setup_py import SetupPyRunner
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.build_graph.target_scopes import Scopes
Expand Down Expand Up @@ -77,8 +78,20 @@ def _create_dist(self, dist_tgt):

whl_location = ''
# build whl from python_dist target
whl = build_python_distribution(dist_tgt, interpreter, self.workdir, self.context.log)
if whl:
whl_location = whl

return whl_location
dist_target_dir, install_dir = build_python_distribution(dist_tgt, interpreter, self.workdir, self.context.log)

# build the whl from pex API using tempdir and get its location
install_dir = os.path.join(dist_target_dir, 'dist')
if not install_dir:
safe_mkdir(install_dir)
setup_runner = SetupPyRunner(tmp_dir_for_dist, 'bdist_wheel', interpreter=interpreter, install_dir=install_dir)
setup_runner.run()

# return the location of the whl on disk (somewhere in pantsd or dist)
dists = os.listdir(install_dir)
if len(dists) == 0:
raise TaskError('No distributions were produced by python_create_distribution task.')
elif len(dists) > 1:
raise TaskError('Ambiguous whls found: %s' % (' '.join(dists)))
else:
return os.path.join(self.install_tmp, dists[0])

0 comments on commit 4b65461

Please sign in to comment.