-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from jaraco/feature/cached-installs
Add support for cached installs
- Loading branch information
Showing
9 changed files
with
215 additions
and
34 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
v9.3.0 | ||
====== | ||
|
||
#52: ``pip-run`` now honors a ``PIP_RUN_MODE``. | ||
|
||
v9.2.1 | ||
====== | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
import textwrap | ||
|
||
import jaraco.path | ||
import pytest | ||
|
||
import pip_run.persist | ||
|
||
|
||
collect_ignore = ['examples'] | ||
|
||
|
||
@pytest.fixture | ||
def reqs_files(tmp_path): | ||
"""Create a couple of requirements files.""" | ||
jaraco.path.build( | ||
{ | ||
'reqs1.txt': textwrap.dedent( | ||
""" | ||
abc | ||
def | ||
""" | ||
).lstrip(), | ||
'reqs2.txt': textwrap.dedent( | ||
""" | ||
uvw | ||
xyz | ||
""" | ||
).lstrip(), | ||
}, | ||
tmp_path, | ||
) | ||
return tmp_path.glob('reqs*.txt') | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def monkeypatch_session(): | ||
with pytest.MonkeyPatch.context() as mp: | ||
yield mp | ||
|
||
|
||
@pytest.fixture(autouse=True, scope='session') | ||
def alt_cache_dir(monkeypatch_session, tmp_path_factory): | ||
alt_cache = tmp_path_factory.mktemp('cache') | ||
|
||
class Paths: | ||
user_cache = alt_cache | ||
user_cache_dir = alt_cache | ||
|
||
monkeypatch_session.setattr(pip_run.persist, 'paths', Paths) | ||
|
||
|
||
@pytest.fixture(params=['persist', 'ephemeral']) | ||
def run_mode(monkeypatch, request): | ||
monkeypatch.setenv('PIP_RUN_MODE', request.param) |
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,6 @@ | ||
import sys | ||
import platform | ||
|
||
subprocess_path = ( | ||
str if sys.version_info < (3, 9) and platform.system() == 'Windows' else lambda x: x | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import contextlib | ||
import tempfile | ||
import shutil | ||
import pathlib | ||
|
||
|
||
@contextlib.contextmanager | ||
def context(args): | ||
target = pathlib.Path(tempfile.mkdtemp(prefix='pip-run-')) | ||
try: | ||
yield target | ||
finally: | ||
shutil.rmtree(target) |
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,54 @@ | ||
import hashlib | ||
import contextlib | ||
|
||
import app_paths | ||
|
||
from . import deps | ||
|
||
|
||
paths = app_paths.AppPaths.get_paths(appname='pip run', appauthor=False) | ||
|
||
|
||
class Hash: | ||
""" | ||
Hash class with support for unicode text. | ||
""" | ||
|
||
def __init__(self, name): | ||
self._hash = hashlib.new(name) | ||
|
||
def update(self, text): | ||
self._hash.update(text.encode('utf-8')) | ||
|
||
def hexdigest(self): | ||
return self._hash.hexdigest() | ||
|
||
|
||
def cache_key(args): | ||
""" | ||
Generate a cache key representing the packages to be installed. | ||
>>> reqs1, reqs2 = getfixture('reqs_files') | ||
>>> cache_key(['-r', str(reqs1), '--requirement', str(reqs2), 'requests']) | ||
'88d9f8a3a4009c1f685a7a724519bd5187e1227d72be6bc7f20a4a02f36d14b3' | ||
The key should be insensitive to order. | ||
>>> cache_key(['--requirement', str(reqs2), 'requests', '-r', str(reqs1)]) | ||
'88d9f8a3a4009c1f685a7a724519bd5187e1227d72be6bc7f20a4a02f36d14b3' | ||
>>> cache_key(['--foo', '-q']) | ||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' | ||
""" | ||
parsed = deps.Install.parse(args) | ||
hash = Hash('sha256') | ||
for req in sorted(parsed.package): | ||
hash.update(req + '\n') | ||
for file in sorted(parsed.requirement): | ||
hash.update('req:\n' + file.read_text()) | ||
return hash.hexdigest() | ||
|
||
|
||
@contextlib.contextmanager | ||
def context(args): | ||
yield paths.user_cache.joinpath(cache_key(args)) |
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