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

Commit

Permalink
Merge pull request #296 from jaibhageria/inspect-project
Browse files Browse the repository at this point in the history
added inspect project command
  • Loading branch information
orsinium committed Nov 19, 2019
2 parents cdf2455 + a5c5a09 commit 6138969
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
1 change: 1 addition & 0 deletions dephell/commands/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'inspect gadget',
'inspect self',
'inspect venv',
'inspect project',

'jail install',
'jail list',
Expand Down
50 changes: 50 additions & 0 deletions dephell/commands/inspect_project.py
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
23 changes: 23 additions & 0 deletions docs/cmd-inspect-project.md
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.
3 changes: 2 additions & 1 deletion docs/index-inspect.md
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
```
28 changes: 28 additions & 0 deletions tests/test_commands/test_inspect_project.py
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'

0 comments on commit 6138969

Please sign in to comment.