-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 518: enable source installs for build dependencies #5336
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for installing PEP 518 build dependencies from source. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from __future__ import absolute_import | ||
|
||
import contextlib | ||
import errno | ||
import hashlib | ||
import logging | ||
import os | ||
|
||
from pip._internal.utils.temp_dir import TempDirectory | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RequirementTracker(object): | ||
|
||
def __init__(self): | ||
self._root = os.environ.get('PIP_REQ_TRACKER') | ||
if self._root is None: | ||
self._temp_dir = TempDirectory(delete=False, kind='req-tracker') | ||
self._temp_dir.create() | ||
self._root = os.environ['PIP_REQ_TRACKER'] = self._temp_dir.path | ||
logger.debug('Created requirements tracker %r', self._root) | ||
else: | ||
self._temp_dir = None | ||
logger.debug('Re-using requirements tracker %r', self._root) | ||
self._entries = set() | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.cleanup() | ||
|
||
def _entry_path(self, link): | ||
hashed = hashlib.sha224(link.url_without_fragment.encode()).hexdigest() | ||
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. Noting here that I did briefly think that we should split the folder name, to be like pip's cache.
I understand the cache might be this way to prevent far too many files in a single directory. I doubt that build-trees would get all that large though, considering that we only have a tracker for what's being built right now. |
||
return os.path.join(self._root, hashed) | ||
|
||
def add(self, req): | ||
link = req.link | ||
info = str(req) | ||
entry_path = self._entry_path(link) | ||
try: | ||
with open(entry_path) as fp: | ||
# Error, these's already a build in progress. | ||
raise LookupError('%s is already being built: %s' | ||
% (link, fp.read())) | ||
except IOError as e: | ||
if e.errno != errno.ENOENT: | ||
raise | ||
assert req not in self._entries | ||
with open(entry_path, 'w') as fp: | ||
fp.write(info) | ||
self._entries.add(req) | ||
logger.debug('Added %s to build tracker %r', req, self._root) | ||
|
||
def remove(self, req): | ||
link = req.link | ||
self._entries.remove(req) | ||
os.unlink(self._entry_path(link)) | ||
logger.debug('Removed %s from build tracker %r', req, self._root) | ||
|
||
def cleanup(self): | ||
for req in set(self._entries): | ||
self.remove(req) | ||
remove = self._temp_dir is not None | ||
if remove: | ||
self._temp_dir.cleanup() | ||
logger.debug('%s build tracker %r', | ||
'Removed' if remove else 'Cleaned', | ||
self._root) | ||
|
||
@contextlib.contextmanager | ||
def track(self, req): | ||
self.add(req) | ||
yield | ||
self.remove(req) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include pyproject.toml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "pep518_forkbomb"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from setuptools import setup | ||
|
||
setup(name='pep518_forkbomb', | ||
version='235', | ||
py_modules=['pep518_forkbomb']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include pyproject.toml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "pep518_twin_forkbombs_second"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from setuptools import setup | ||
|
||
setup(name='pep518_twin_forkbombs_first', | ||
version='234', | ||
py_modules=['pep518_twin_forkbombs_first']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include pyproject.toml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "pep518_twin_forkbombs_first"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from setuptools import setup | ||
|
||
setup(name='pep518_twin_forkbombs_second', | ||
version='238', | ||
py_modules=['pep518_twin_forkbombs_second']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,10 +100,6 @@ def packages2(self): | |
def packages3(self): | ||
return self.root.join("packages3") | ||
|
||
@property | ||
def packages4(self): | ||
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. bye bye packages4! 👋 |
||
return self.root.join("packages4") | ||
|
||
@property | ||
def src(self): | ||
return self.root.join("src") | ||
|
@@ -132,10 +128,6 @@ def find_links2(self): | |
def find_links3(self): | ||
return path_to_url(self.packages3) | ||
|
||
@property | ||
def find_links4(self): | ||
return path_to_url(self.packages4) | ||
|
||
def index_url(self, index="simple"): | ||
return path_to_url(self.root.join("indexes", index)) | ||
|
||
|
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.
Could you remove the period?
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.
Why?
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 said that for consistency across news files -- I usually commit them without periods. Looking at the directory currently, it's inconsistent already so I guess this doesn't matter all that much.
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.
Yeah, I'd definitely say this doesn't matter. FWIW personally I prefer complete sentences (i.e., periods).
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.
Same.