Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Add self uncache command #312

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dephell/commands/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'project test',
'project validate',

'self uncache',
'self upgrade',

'vendor download',
Expand Down
31 changes: 31 additions & 0 deletions dephell/commands/self_uncache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# built-in
from argparse import ArgumentParser
from pathlib import Path
from shutil import rmtree

# app
from ..actions import format_size, get_path_size
from ..config import builders
from .base import BaseCommand


class SelfUncacheCommand(BaseCommand):
"""Remove dephell cache.
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = cls._get_default_parser()
builders.build_config(parser)
builders.build_output(parser)
builders.build_other(parser)
return parser

def __call__(self) -> bool:
path = Path(self.config['cache']['path'])
if path.exists():
size = format_size(get_path_size(path))
rmtree(str(path))
self.logger.info('cache removed', extra=dict(size=size))
else:
self.logger.warning('no cache found')
return True
4 changes: 3 additions & 1 deletion dephell/commands/self_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def _upgrade_repo(self, path: Path) -> bool:

def _upgrade_package(self) -> bool:
manager = PackageManager(executable=sys.executable)
args = ['-U', '--upgrade-strategy=eager']
args = ['-U']
if manager.is_global:
args.append('--user')
else:
args.append('--upgrade-strategy=eager')
code = manager.run('install', *args, 'dephell')
return (code == 0)
2 changes: 2 additions & 0 deletions docs/cmd-inspect-self.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ $ dephell inspect self

## See also

1. [dephell self uncache](cmd-self-uncache) to remove dephell cache.
1. [dephell self upgrade](cmd-self-upgrade) to upgrade dephell and dependencies to the latest version.
1. [dephell autocomplete](cmd-venv-create) to enable params autocomplete for commands in your shell.
1. [dephell inspect config](cmd-inspect-config) to get information about config parameters.
12 changes: 12 additions & 0 deletions docs/cmd-self-uncache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# dephell self uncache

Remove dephell cache.

```bash
$ dephell self uncache
INFO cache removed (size=64.98Mb)
```

## See also

1. [dephell inspect self](cmd-inspect-self) to get information about dephell installation like current cache size.
11 changes: 11 additions & 0 deletions docs/cmd-self-upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# dephell self upgrade

Upgrade dephell to the latest version. If dephell installed in venv or jail, it also updates all dependencies.

```bash
$ dephell self upgrade
```

## See also

1. [dephell inspect self](cmd-inspect-self) to get information about dephell installation like current cache size.
11 changes: 11 additions & 0 deletions docs/index-self.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# **self**: manage dephell

Commands to manage dephell installation: [upgrade to the latest version](cmd-self-upgrade), [clear cache](cmd-self-uncache).

```eval_rst
.. toctree::
:maxdepth: 1

cmd-self-uncache
cmd-self-upgrade
```
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ And that's it! Now you can use any tools with any Python project. Every other co
index-jail
index-package
index-project
index-self
index-vendor
index-venv
index-other
Expand Down