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 #320 from dephell/inspect-versioning
Browse files Browse the repository at this point in the history
Add inspect versioning command
  • Loading branch information
orsinium committed Dec 17, 2019
2 parents db0921e + 8f8fc74 commit 37f44fc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dephell/commands/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
'inspect auth',
'inspect config',
'inspect gadget',
'inspect project',
'inspect self',
'inspect venv',
'inspect project',
'inspect versioning',

'jail install',
'jail list',
Expand Down
54 changes: 54 additions & 0 deletions dephell/commands/inspect_versioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# built-in
from argparse import ArgumentParser
from pathlib import Path

# external
from dephell_versioning import get_rules

# app
from ..actions import make_json
from ..config import builders
from ..converters import CONVERTERS
from .base import BaseCommand


class InspectVersioningCommand(BaseCommand):
"""Inspect the versioning rules of the 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:

version = None
if 'from' in self.config:
loader = CONVERTERS[self.config['from']['format']]
loader = loader.copy(project_path=Path(self.config['project']))
root = loader.load(path=self.config['from']['path'])
version = root.version

scheme = self.config['versioning']
rules = get_rules(scheme=scheme)
data = dict(
version=version,
scheme=scheme,
rules=dict(
supported=sorted(rules),
unsupported=sorted(get_rules() - rules),
),
)

print(make_json(
data=data,
key=self.config.get('filter'),
colors=not self.config['nocolors'],
table=self.config['table'],
))
return True
37 changes: 37 additions & 0 deletions docs/cmd-inspect-versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# dephell inspect versioning

Shows info about project versioning scheme and current version.

```bash
$ dephell inspect versioning
{
"rules": {
"supported": [
"init",
"local",
"major",
"minor",
"patch",
"pre",
"premajor",
"preminor",
"prepatch",
"release"
],
"unsupported": [
"dev",
"post"
]
},
"scheme": "semver",
"version": "0.7.9"
}
```

Read about schemes and rules in [dephell project bump](cmd-project-bump) docs.

## See also

1. [dephell project bump](cmd-project-bump) to bump project version.
1. [dephell inspect project](cmd-inspect-project) to get information about the project metainfo.
1. [dephell inspect config](cmd-inspect-config) to get information about the project configuration.
4 changes: 4 additions & 0 deletions docs/cmd-project-bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,7 @@ Custom version:
$ dephell project bump 0.3.2
INFO generated new version (old=0.1.0.post1.dev1, new=0.3.2)
```

## See also

1. [dephell inspect versioning](cmd-inspect-versioning) to get information about the project versioning scheme and available rules.
3 changes: 2 additions & 1 deletion docs/index-inspect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **inspect**: info about environment

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).
Commands to get information about environment: [dephell config](cmd-inspect-config), [dephell ecosystem versions](cmd-inspect-self), [project metainfo](cmd-inspect-project), [versioning scheme](cmd-inspect-versioning), [virtual environment](cmd-inspect-venv), [stored credentials](cmd-inspect-auth).

```eval_rst
.. toctree::
Expand All @@ -11,4 +11,5 @@ Commands to get information about environment: [dephell config](cmd-inspect-conf
cmd-inspect-project
cmd-inspect-self
cmd-inspect-venv
cmd-inspect-versioning
```

0 comments on commit 37f44fc

Please sign in to comment.