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

Commit

Permalink
Merge branch 'command-outdated'
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Apr 3, 2019
2 parents ca750df + d4659b5 commit d3a0e7c
Show file tree
Hide file tree
Showing 39 changed files with 397 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ build/
pip-wheel-metadata/

Pipfile.lock
poetry.lock
poetry.lock.toml

.tox
.mypy_cache

Expand Down
2 changes: 1 addition & 1 deletion dephell/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def format_help(self):


parser = PatchedParser(
description='Lock and convert dependencies between formats.',
description='Manage dependencies, projects, virtual environments.',
)
parser.add_argument('command', choices=commands.keys(), nargs='?', help='command to execute')

Expand Down
3 changes: 3 additions & 0 deletions dephell/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .deps_convert import DepsConvertCommand
from .deps_install import DepsInstallCommand
from .deps_licenses import DepsLicensesCommand
from .deps_outdated import DepsOutdatedCommand
from .generate_authors import GenerateAuthorsCommand
from .generate_config import GenerateConfigCommand
from .generate_editorconfig import GenerateEditorconfigCommand
Expand Down Expand Up @@ -32,6 +33,7 @@
'DepsConvertCommand',
'DepsInstallCommand',
'DepsLicensesCommand',
'DepsOutdatedCommand',
'GenerateAuthorsCommand',
'GenerateConfigCommand',
'GenerateEditorconfigCommand',
Expand Down Expand Up @@ -60,6 +62,7 @@
'deps convert': DepsConvertCommand,
'deps install': DepsInstallCommand,
'deps licenses': DepsLicensesCommand,
'deps outdated': DepsOutdatedCommand,
# 'deps remove': ...,
# 'deps sync': ...,
'generate authors': GenerateAuthorsCommand,
Expand Down
16 changes: 7 additions & 9 deletions dephell/commands/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
)


DUMPERS = (
('setuppy', 'setup.py'),
('egginfo', '.'),
('sdist', 'dist/'),
('wheel', 'dist/'),
)
class AutocompleteCommand(BaseCommand):
"""Enable DepHell commands autocomplete for current shell.
https://dephell.readthedocs.io/en/latest/cmd-autocomplete.html
"""

class AutocompleteCommand(BaseCommand):
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell autocomplete',
description='Enable dephell commands autocomplete for current shell',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
Expand Down Expand Up @@ -93,7 +90,8 @@ def _zsh(self):
command_name, _sep, subcommand = command_name.partition(' ')
first_words.add(command_name)
if subcommand:
tree[command_name].add((subcommand, command.get_parser().description))
description = command.get_parser().description.lstrip().split('\n', maxsplit=1)[0]
tree[command_name].add((subcommand, description))

arguments = defaultdict(list)
for command_name, command in commands.items():
Expand Down
6 changes: 5 additions & 1 deletion dephell/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@


class BuildCommand(BaseCommand):
"""Create dist archives for project.
https://dephell.readthedocs.io/en/latest/cmd-build.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell build',
description='Create dist archives for project',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_from(parser)
Expand Down
14 changes: 9 additions & 5 deletions dephell/commands/deps_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@


class DepsConvertCommand(BaseCommand):
"""Convert dependencies between formats.
https://dephell.readthedocs.io/en/latest/cmd-deps-convert.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell deps convert',
description='Convert dependencies between formats',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_from(parser)
Expand Down Expand Up @@ -48,25 +52,25 @@ def __call__(self):

# merge (without full graph building)
if not should_be_resolved:
self.logger.info('merging...')
self.logger.debug('merging...')
resolved = resolver.resolve(level=1)
if not resolved:
conflict = analize_conflict(resolver=resolver)
self.logger.warning('conflict was found')
print(conflict)
return False
self.logger.info('merged')
self.logger.debug('merged')

# resolve (and merge)
if should_be_resolved:
self.logger.info('resolving...')
self.logger.debug('resolving...')
resolved = resolver.resolve()
if not resolved:
conflict = analize_conflict(resolver=resolver)
self.logger.warning('conflict was found')
print(conflict)
return False
self.logger.info('resolved')
self.logger.debug('resolved')

# dump
dumper.dump(
Expand Down
8 changes: 6 additions & 2 deletions dephell/commands/deps_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@


class DepsInstallCommand(BaseCommand):
"""Install project dependencies.
https://dephell.readthedocs.io/en/latest/cmd-deps-install.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell deps install',
description='Install project dependencies',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_from(parser)
builders.build_to(parser)
builders.build_resolver(parser)
builders.build_api(parser)
builders.build_venv(parser)
Expand Down
6 changes: 5 additions & 1 deletion dephell/commands/deps_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@


class DepsLicensesCommand(BaseCommand):
"""Show licenses for all project dependencies.
https://dephell.readthedocs.io/en/latest/cmd-deps-licenses.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell deps licenses',
description='Show licenses for all project dependencies',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_from(parser)
Expand Down
71 changes: 71 additions & 0 deletions dephell/commands/deps_outdated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# built-in
from argparse import ArgumentParser
from pathlib import Path

# app
from ..config import builders
from ..repositories import WareHouseRepo
from .base import BaseCommand
from ..venvs import VEnvs
from ..converters import CONVERTERS, InstalledConverter


class DepsOutdatedCommand(BaseCommand):
"""Show outdated project dependencies.
https://dephell.readthedocs.io/en/latest/cmd-deps-outdated.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell deps outdated',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_to(parser)
builders.build_output(parser)
builders.build_api(parser)
builders.build_other(parser)
return parser

def __call__(self):
loader_config = self.config.get('to', self.config['from'])
loader = CONVERTERS[loader_config['format']]
if loader.lock:
self.logger.info('get dependencies from lockfile', extra=dict(
format=loader_config['format'],
path=loader_config['path'],
))
root = loader.load(path=loader_config['path'])
else:
venvs = VEnvs(path=self.config['venv'])
venv = venvs.get(Path(self.config['project']), env=self.config.env)
if venv.exists():
self.logger.info('get packages from project environment', extra=dict(
path=str(venv.path),
))
path = venv.lib_path
else:
path = None
self.logger.info('get packages from global python lib')

converter = InstalledConverter()
root = converter.load(path)

repo = WareHouseRepo()
data = []
for dep in root.dependencies:
releases = repo.get_releases(dep)
latest = str(releases[0].version)
installed = str(dep.constraint).replace('=', '').split(' || ')
if latest in installed:
continue
data.append(dict(
name=dep.name,
latest=latest,
installed=installed,
updated=str(releases[0].time.date()),
description=dep.description,
))
print(self.get_value(data=data, key=self.config.get('filter')))
return True
8 changes: 6 additions & 2 deletions dephell/commands/generate_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@


class GenerateAuthorsCommand(BaseCommand):
"""Create AUTHORS file for project by git log.
https://dephell.readthedocs.io/en/latest/cmd-generate-authors.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='python3 -m dephell generate authors',
description='Create AUTHORS file for project by git log',
prog='dephell generate authors',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
Expand Down
8 changes: 6 additions & 2 deletions dephell/commands/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@


class GenerateConfigCommand(BaseCommand):
"""Create config file for DepHell.
https://dephell.readthedocs.io/en/latest/cmd-generate-config.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='python3 -m dephell generate config',
description='Create config file for dephell',
prog='dephell generate config',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
Expand Down
9 changes: 7 additions & 2 deletions dephell/commands/generate_editorconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@


class GenerateEditorconfigCommand(BaseCommand):
"""Create EditorConfig for project.
https://dephell.readthedocs.io/en/latest/cmd-generate-editorconfig.html
https://editorconfig.org/
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='python3 -m dephell generate editorconfig',
description='Create EditorConfig for project',
prog='dephell generate editorconfig',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
Expand Down
17 changes: 13 additions & 4 deletions dephell/commands/generate_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@


class GenerateLicenseCommand(BaseCommand):
"""Create LICENSE file.
https://dephell.readthedocs.io/en/latest/cmd-generate-license.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='python3 -m dephell generate license',
description='Create LICENSE file',
prog='dephell generate license',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
builders.build_other(parser)
parser.add_argument('name', nargs=REMAINDER, help='licnse name')
parser.add_argument('name', nargs=REMAINDER, help='license name')
return parser

def __call__(self):
name = ' '.join(self.args.name)
# get license object
name = ' '.join(self.args.name).strip()
if not name:
name = 'MIT'
license = licenses.get_by_id(name)
if license is None:
license = licenses.get_by_name(name)
if license is None:
self.logger.error('cannot find license with given name')
return False

# generate license text
text = license.make_text(copyright='{year} {name}'.format(
year=datetime.now().year,
name=getuser().title(),
Expand Down
7 changes: 6 additions & 1 deletion dephell/commands/inspect_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@


class InspectConfigCommand(BaseCommand):
"""Show current config.
https://dephell.readthedocs.io/en/latest/cmd-inspect-config.html
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell inspect config',
description='Show current config',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_from(parser)
Expand All @@ -25,3 +29,4 @@ def get_parser(cls):

def __call__(self):
print(self.get_value(data=self.config._data, key=self.config.get('filter')))
return True
7 changes: 6 additions & 1 deletion dephell/commands/inspect_gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@


class InspectGadgetCommand(BaseCommand):
"""Show Inspector Gadget.
This command shouldn't be documented.
"""
@classmethod
def get_parser(cls):
parser = ArgumentParser(
prog='dephell inspect config',
description='Show Inspector Gadget',
description=cls.__doc__,
)
builders.build_config(parser)
return parser

def __call__(self):
print(GADGET)
return True

0 comments on commit d3a0e7c

Please sign in to comment.