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 #296 from jaibhageria/inspect-project
added inspect project command
- Loading branch information
Showing
5 changed files
with
104 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
'inspect gadget', | ||
'inspect self', | ||
'inspect venv', | ||
'inspect project', | ||
|
||
'jail install', | ||
'jail list', | ||
|
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,50 @@ | ||
# built-in | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
# app | ||
from ..actions import make_json | ||
from ..config import builders | ||
from ..converters import CONVERTERS | ||
from .base import BaseCommand | ||
|
||
|
||
class InspectProjectCommand(BaseCommand): | ||
"""Inspect the current project. | ||
""" | ||
@classmethod | ||
def get_parser(cls) -> ArgumentParser: | ||
parser = cls._get_default_parser() | ||
builders.build_config(parser) | ||
builders.build_from(parser) | ||
builders.build_output(parser) | ||
builders.build_api(parser) | ||
builders.build_other(parser) | ||
return parser | ||
|
||
def __call__(self) -> bool: | ||
if 'from' not in self.config: | ||
self.logger.error('`--from` is required for this command') | ||
return False | ||
|
||
loader = CONVERTERS[self.config['from']['format']] | ||
loader = loader.copy(project_path=Path(self.config['project'])) | ||
root = loader.load(path=self.config['from']['path']) | ||
|
||
result = dict( | ||
name=root.raw_name, | ||
version=root.version, | ||
description=root.description, | ||
) | ||
if root.python: | ||
result['python'] = str(root.python) | ||
if root.links: | ||
result['links'] = root.links | ||
|
||
print(make_json( | ||
data=result, | ||
key=self.config.get('filter'), | ||
colors=not self.config['nocolors'], | ||
table=self.config['table'], | ||
)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# dephell inspect project | ||
|
||
Shows metainfo from the `from` dependency file, like project name, version, required python, etc. | ||
|
||
```bash | ||
$ dephell inspect project | ||
{ | ||
"description": "Dependency resolution for Python", | ||
"links": { | ||
"documentation": "https://dephell.org/docs/", | ||
"homepage": "https://dephell.org/", | ||
"repository": "https://github.com/dephell/dephell" | ||
}, | ||
"name": "dephell", | ||
"python": ">=3.5", | ||
"version": "0.7.8" | ||
} | ||
``` | ||
|
||
## See also | ||
|
||
1. [dephell project validate](cmd-project-validate) to check project metadata for compatibility issues and missed information. | ||
1. [dephell inspect config](cmd-inspect-config) to get information about the project configuration. |
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,13 +1,14 @@ | ||
# **inspect**: info about environment | ||
|
||
Commands to get information about environment: [dephell config](cmd-inspect-config), [dephell ecosystem versions](cmd-inspect-self), [virtual environment](cmd-inspect-venv), [stored credentials](cmd-inspect-auth). | ||
Commands to get information about environment: [dephell config](cmd-inspect-config), [dephell ecosystem versions](cmd-inspect-self), [project metainfo](cmd-inspect-project), [virtual environment](cmd-inspect-venv), [stored credentials](cmd-inspect-auth). | ||
|
||
```eval_rst | ||
.. toctree:: | ||
:maxdepth: 1 | ||
cmd-inspect-auth | ||
cmd-inspect-config | ||
cmd-inspect-project | ||
cmd-inspect-self | ||
cmd-inspect-venv | ||
``` |
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,28 @@ | ||
# built-in | ||
import json | ||
from pathlib import Path | ||
|
||
# project | ||
from dephell.commands import InspectProjectCommand | ||
from dephell.config import Config | ||
|
||
|
||
def test_inspect_project_command(temp_path: Path, requirements_path: Path, capsys): | ||
from_path = str(requirements_path / 'poetry.toml') | ||
config = Config() | ||
config.attach({ | ||
'from': {'format': 'poetry', 'path': from_path}, | ||
'project': str(temp_path), | ||
'nocolors': True, | ||
}) | ||
|
||
command = InspectProjectCommand(argv=[], config=config) | ||
result = command() | ||
assert result is True | ||
|
||
captured = capsys.readouterr() | ||
print(captured.out) | ||
output = json.loads(captured.out) | ||
assert set(output) == {'name', 'version', 'description', 'links', 'python'} | ||
assert output['name'] == 'my-package' | ||
assert output['version'] == '0.1.0' |