File tree 4 files changed +94
-1
lines changed
poetry/console/commands/cache
4 files changed +94
-1
lines changed Original file line number Diff line number Diff line change @@ -452,3 +452,15 @@ The `env` command regroups sub commands to interact with the virtualenvs
452
452
associated with a specific project.
453
453
454
454
See [ Managing environments] ( ./managing-environments.md ) for more information about these commands.
455
+
456
+ ## cache
457
+
458
+ The ` cache ` command regroups sub commands to interact with Poetry's cache.
459
+
460
+ ### cache list
461
+
462
+ The ` cache list ` command lists Poetry's available caches.
463
+
464
+ ``` bash
465
+ poetry cache list
466
+ ```
Original file line number Diff line number Diff line change
1
+ from poetry .console .commands .cache .list import CacheListCommand
2
+
1
3
from ..command import Command
2
4
from .clear import CacheClearCommand
3
5
@@ -7,7 +9,7 @@ class CacheCommand(Command):
7
9
name = "cache"
8
10
description = "Interact with Poetry's cache"
9
11
10
- commands = [CacheClearCommand ()]
12
+ commands = [CacheClearCommand (), CacheListCommand () ]
11
13
12
14
def handle (self ):
13
15
return self .call ("help" , self ._config .name )
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ from ..command import Command
4
+
5
+
6
+ class CacheListCommand (Command ):
7
+
8
+ name = "list"
9
+ description = "List Poetry's caches."
10
+
11
+ def handle (self ):
12
+ from poetry .locations import REPOSITORY_CACHE_DIR
13
+
14
+ if os .path .exists (str (REPOSITORY_CACHE_DIR )):
15
+ caches = list (sorted (REPOSITORY_CACHE_DIR .iterdir ()))
16
+ if caches :
17
+ for cache in caches :
18
+ self .line ("<info>{}</>" .format (cache .name ))
19
+ return 0
20
+
21
+ self .line ("<warning>No caches found</>" )
Original file line number Diff line number Diff line change
1
+ import uuid
2
+
3
+ import pytest
4
+
5
+ from cleo .testers import CommandTester
6
+
7
+
8
+ @pytest .fixture
9
+ def repository_cache_dir (monkeypatch , tmpdir ):
10
+ import poetry .locations
11
+ from poetry .utils ._compat import Path
12
+
13
+ path = Path (tmpdir )
14
+ monkeypatch .setattr (poetry .locations , "REPOSITORY_CACHE_DIR" , path )
15
+ return path
16
+
17
+
18
+ @pytest .fixture
19
+ def repository_one ():
20
+ return f"01_{ uuid .uuid4 ()} "
21
+
22
+
23
+ @pytest .fixture
24
+ def repository_two ():
25
+ return f"02_{ uuid .uuid4 ()} "
26
+
27
+
28
+ @pytest .fixture
29
+ def mock_caches (repository_cache_dir , repository_one , repository_two ):
30
+ (repository_cache_dir / repository_one ).mkdir ()
31
+ (repository_cache_dir / repository_two ).mkdir ()
32
+
33
+
34
+ def test_cache_list (app , mock_caches , repository_one , repository_two ):
35
+ command = app .find ("cache list" )
36
+ tester = CommandTester (command )
37
+
38
+ tester .execute ()
39
+
40
+ expected = f"""\
41
+ { repository_one }
42
+ { repository_two }
43
+ """
44
+
45
+ assert expected == tester .io .fetch_output ()
46
+
47
+
48
+ def test_cache_list_empty (app , repository_cache_dir ):
49
+ command = app .find ("cache list" )
50
+ tester = CommandTester (command )
51
+
52
+ tester .execute ()
53
+
54
+ expected = f"""\
55
+ No caches found
56
+ """
57
+
58
+ assert expected == tester .io .fetch_output ()
You can’t perform that action at this time.
0 commit comments