This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
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 #27 from dephell/local-repo
Local repo
- Loading branch information
Showing
35 changed files
with
594 additions
and
75 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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,37 @@ | ||
import subprocess | ||
from logging import getLogger | ||
from pathlib import Path | ||
from typing import Iterable | ||
|
||
|
||
logger = getLogger('dephell.actions.git') | ||
|
||
|
||
def _run(command, project: Path) -> bool: | ||
result = subprocess.run( | ||
command, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
cwd=str(project), | ||
) | ||
if result.returncode != 0: | ||
stderr = result.stderr.decode().strip() | ||
if stderr: | ||
logger.debug(stderr) | ||
stdout = result.stdout.decode().strip() | ||
if stdout: | ||
logger.debug(stdout) | ||
return False | ||
return True | ||
|
||
|
||
def git_commit(message: str, paths: Iterable[Path], project: Path) -> bool: | ||
for path in paths: | ||
ok = _run(['git', 'add', '--update', str(path)], project=project) | ||
if not ok: | ||
return False | ||
return _run(['git', 'commit', '-m', message], project=project) | ||
|
||
|
||
def git_tag(name: str, project: Path) -> bool: | ||
return _run(['git', 'tag', name], project=project) |
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,102 @@ | ||
# built-in | ||
from argparse import ArgumentParser | ||
|
||
# app | ||
from ..actions import attach_deps, get_python_env, make_json | ||
from ..config import builders | ||
from ..controllers import analize_conflict | ||
from ..converters import CONVERTERS, InstalledConverter | ||
from ..models import Requirement | ||
from .base import BaseCommand | ||
|
||
|
||
class DepsCheckCommand(BaseCommand): | ||
"""Show difference between venv and project dependencies. | ||
https://dephell.readthedocs.io/en/latest/cmd-deps-check.html | ||
""" | ||
@classmethod | ||
def get_parser(cls) -> ArgumentParser: | ||
parser = ArgumentParser( | ||
prog='dephell deps check', | ||
description=cls.__doc__, | ||
) | ||
builders.build_config(parser) | ||
builders.build_to(parser) | ||
builders.build_resolver(parser) | ||
builders.build_api(parser) | ||
builders.build_venv(parser) | ||
builders.build_output(parser) | ||
builders.build_other(parser) | ||
return parser | ||
|
||
def __call__(self) -> bool: | ||
loader_config = self.config.get('to') or self.config['from'] | ||
self.logger.info('get dependencies', extra=dict( | ||
format=loader_config['format'], | ||
path=loader_config['path'], | ||
)) | ||
loader = CONVERTERS[loader_config['format']] | ||
resolver = loader.load_resolver(path=loader_config['path']) | ||
attach_deps(resolver=resolver, config=self.config, merge=False) | ||
|
||
# resolve | ||
self.logger.info('build dependencies graph...') | ||
resolved = resolver.resolve(silent=self.config['silent']) | ||
if not resolved: | ||
conflict = analize_conflict(resolver=resolver) | ||
self.logger.warning('conflict was found') | ||
print(conflict) | ||
return False | ||
|
||
# get executable | ||
python = get_python_env(config=self.config) | ||
self.logger.debug('choosen python', extra=dict(path=str(python.path))) | ||
|
||
# get installed packages | ||
installed_root = InstalledConverter().load(paths=python.lib_paths) | ||
installed = {dep.name: str(dep.constraint).strip('=') for dep in installed_root.dependencies} | ||
|
||
# filter deps by envs and markers | ||
resolver.apply_envs(set(self.config['envs'])) | ||
resolver.apply_markers(python=python) | ||
|
||
data = [] | ||
reqs = Requirement.from_graph(graph=resolver.graph, lock=True) | ||
for req in reqs: | ||
version = req.version.strip('=') | ||
# not installed | ||
if req.name not in installed: | ||
data.append(dict( | ||
action='install', | ||
name=req.name, | ||
installed=None, | ||
locked=version, | ||
)) | ||
continue | ||
# installed the same version, skip | ||
if version == installed[req.name]: | ||
continue | ||
# installed old version | ||
data.append(dict( | ||
action='update', | ||
name=req.name, | ||
installed=installed[req.name], | ||
locked=version, | ||
)) | ||
# obsolete | ||
names = set(installed) - {req.name for req in reqs} | ||
for name in names: | ||
data.append(dict( | ||
action='remove', | ||
name=name, | ||
installed=installed[name], | ||
locked=None, | ||
)) | ||
|
||
if data: | ||
print(make_json(data=data, key=self.config.get('filter'))) | ||
return False | ||
|
||
self.logger.info('all packages is up-to-date') | ||
return True |
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,31 @@ | ||
# built-in | ||
from argparse import ArgumentParser | ||
|
||
# app | ||
from ..config import builders | ||
from .deps_install import DepsInstallCommand | ||
|
||
|
||
class DepsSyncCommand(DepsInstallCommand): | ||
"""Install project dependencies with removing all other packages from venv. | ||
https://dephell.readthedocs.io/en/latest/cmd-deps-sync.html | ||
""" | ||
# DepsInstallCommand contains all logic for sync. | ||
# There we just set `sync` flag and change some minor metainfo. | ||
sync = True | ||
|
||
@classmethod | ||
def get_parser(cls) -> ArgumentParser: | ||
parser = ArgumentParser( | ||
prog='dephell deps sync', | ||
description=cls.__doc__, | ||
) | ||
builders.build_config(parser) | ||
builders.build_to(parser) | ||
builders.build_resolver(parser) | ||
builders.build_api(parser) | ||
builders.build_venv(parser) | ||
builders.build_output(parser) | ||
builders.build_other(parser) | ||
return parser |
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
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
Oops, something went wrong.