Skip to content

Commit

Permalink
Dedup and merge reqs to pass into pip
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Sep 11, 2018
1 parent 5d25cfd commit 851d756
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pep517/envbuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Build wheels/sdists by installing build deps to a temporary environment.
"""

import re
import os
import logging
import pytoml
Expand All @@ -14,13 +15,35 @@

log = logging.getLogger(__name__)


def _load_pyproject(source_dir):
with open(os.path.join(source_dir, 'pyproject.toml')) as f:
pyproject_data = pytoml.load(f)
buildsys = pyproject_data['build-system']
return buildsys['requires'], buildsys['build-backend']


REQUIREMENT_PATTERN = re.compile(r'^(?P<name>[^~><=!]+)(?P<spec>.*)$')


def _as_req_list(reqs):
specs = {}
for req in reqs:
match = REQUIREMENT_PATTERN.match(req)
if not match:
specs[req] = []
continue
name, spec = match.group('name', 'spec')
try:
specs[name].append(spec)
except KeyError:
specs[name] = [spec]
return [
'{}{}'.format(name, ','.join(s for s in spec if s))
for name, spec in specs.items()
]


class BuildEnvironment(object):
"""Context manager to install build deps in a simple temporary environment
Expand Down Expand Up @@ -90,7 +113,7 @@ def pip_install(self, reqs):
return
log.info('Calling pip to install %s', reqs)
check_call([sys.executable, '-m', 'pip', 'install', '--ignore-installed',
'--prefix', self.path] + list(reqs))
'--prefix', self.path] + _as_req_list(reqs))

def __exit__(self, exc_type, exc_val, exc_tb):
if self._cleanup and (self.path is not None) and os.path.isdir(self.path):
Expand Down

0 comments on commit 851d756

Please sign in to comment.