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 #361 from dephell/package-changelog
Browse files Browse the repository at this point in the history
`package changelog` command
  • Loading branch information
orsinium committed Jan 27, 2020
2 parents 6136384 + cb19cd4 commit bc5abdc
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 16 deletions.
1 change: 1 addition & 0 deletions dephell/commands/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'jail try',

'package bug',
'package changelog',
'package downloads',
'package install',
'package list',
Expand Down
5 changes: 2 additions & 3 deletions dephell/commands/inspect_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
class InspectVersioningCommand(BaseCommand):
"""Inspect the versioning rules of the project.
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = cls._get_default_parser()
@staticmethod
def build_parser(parser) -> ArgumentParser:
builders.build_config(parser)
builders.build_from(parser)
builders.build_output(parser)
Expand Down
5 changes: 2 additions & 3 deletions dephell/commands/jail_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
class JailShowCommand(BaseCommand):
"""Show info about the package isolated environment.
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = cls._get_default_parser()
@staticmethod
def build_parser(parser) -> ArgumentParser:
builders.build_config(parser)
builders.build_venv(parser)
builders.build_output(parser)
Expand Down
5 changes: 2 additions & 3 deletions dephell/commands/package_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
class PackageBugCommand(BaseCommand):
"""Report bug in a package.
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = cls._get_default_parser()
@staticmethod
def build_parser(parser) -> ArgumentParser:
builders.build_config(parser)
builders.build_venv(parser)
builders.build_output(parser)
Expand Down
68 changes: 68 additions & 0 deletions dephell/commands/package_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# built-in
import os
from argparse import REMAINDER, ArgumentParser

# external
import requests
from dephell_changelogs import get_changelog_url, parse_changelog

# app
from ..config import builders
from .base import BaseCommand


DEFAULT_WIDTH = int(os.environ.get('COLUMNS', 90))


class PackageChangelogCommand(BaseCommand):
"""Find project changelog.
"""
@staticmethod
def build_parser(parser) -> ArgumentParser:
builders.build_config(parser)
builders.build_venv(parser)
builders.build_output(parser)
builders.build_api(parser)
builders.build_other(parser)
parser.add_argument('name', nargs=REMAINDER, help='package name')
return parser

def __call__(self) -> bool:
url = get_changelog_url(self.args.name[0])
if not url:
self.logger.error('cannot find changelog URL')
return False
self.logger.debug('changelog url found', extra=dict(url=url))

response = requests.get(url=url)
if not response.ok:
self.logger.error('cannot get changelog content', extra=dict(
url=url,
reason=response.reason,
))
return False
content = response.text

if len(self.args.name) == 1:
print(content)
return True

changelog = parse_changelog(content=content)
if len(changelog) == 1:
self.logger.warning('cannot parse changelog', extra=dict(url=url))
print(content)
return True
self.logger.debug('changelog parsed', extra=dict(versions=list(changelog)))

for version in self.args.name[1:]:
if version not in changelog:
self.logger.error('cannot find version in changelog', extra=dict(
url=url,
version=version,
))
return False

for version in self.args.name[1:]:
print('\n## Release {}\n'.format(version))
print(changelog[version].strip('\n'))
return True
3 changes: 3 additions & 0 deletions dephell/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ class ReturnCodes(Enum):

DEPHELL_ECOSYSTEM = (
'dephell_archive',
'dephell_argparse',
'dephell_changelogs',
'dephell_discover',
'dephell_licenses',
'dephell_links',
'dephell_markers',
'dephell_pythons',
'dephell_setuptools',
'dephell_shells',
'dephell_specifier',
'dephell_venvs',
Expand Down
1 change: 1 addition & 0 deletions docs/cmd-package-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ $ dephell package bug --repo conda textdistance

## See also

1. [dephell package changelog](cmd-package-changelog) to find changelog for a package or release.
1. [dephell package show](cmd-package-show) to get information about package.
1. [dephell package search](cmd-package-search) to search packages on [PyPI](https://pypi.org/).
29 changes: 29 additions & 0 deletions docs/cmd-package-changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# dephell package changelog

Find changelog for a package or release.

For package:

```bash
dephell package changelog pytest
```

For releases:

```bash
dephell package changelog pytest 3.0.7 3.0.6
```

The changelog will be printed as-is, with original grammar. So, you can redirect it into a file to render it then with an external tool:

```bash
dephell package changelog pytest > pytest_changelog.rst
```

The current implementation works for 80% cases. The changelog must be in one file and uploaded in the GitHub repository of the project.

## See also

1. [dephell package bug](cmd-package-bug) to find bugtracker for a package.
1. [dephell package show](cmd-package-show) to get information about package.
1. [dephell package search](cmd-package-search) to search packages on [PyPI](https://pypi.org/).
1 change: 1 addition & 0 deletions docs/index-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Manage: [install](cmd-package-install), [remove](cmd-package-remove), [remove wi
:maxdepth: 1
cmd-package-bug
cmd-package-changelog
cmd-package-downloads
cmd-package-install
cmd-package-list
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ yapf = {optional = true, version = "*"}
# dephell ecosystem
dephell-archive = ">=0.1.5"
dephell-argparse = ">=0.1.1"
dephell-changelogs = "*"
dephell-discover = ">=0.2.6"
dephell-licenses = ">=0.1.6"
dephell-links = ">=0.1.4"
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
package_data={"dephell": ["templates/*.j2", "templates/*.sh"]},
install_requires=[
'aiohttp', 'attrs>=19.2.0', 'cerberus>=1.3', 'dephell-archive>=0.1.5',
'dephell-argparse>=0.1.1', 'dephell-discover>=0.2.6',
'dephell-licenses>=0.1.6', 'dephell-links>=0.1.4',
'dephell-markers>=1.0.0', 'dephell-pythons>=0.1.11',
'dephell-setuptools>=0.2.1', 'dephell-shells>=0.1.3',
'dephell-specifier>=0.1.7', 'dephell-venvs>=0.1.16',
'dephell-versioning', 'jinja2', 'm2r', 'packaging', 'pip>=18.0',
'requests', 'tomlkit', 'yaspin'
'dephell-argparse>=0.1.1', 'dephell-changelogs',
'dephell-discover>=0.2.6', 'dephell-licenses>=0.1.6',
'dephell-links>=0.1.4', 'dephell-markers>=1.0.0',
'dephell-pythons>=0.1.11', 'dephell-setuptools>=0.2.1',
'dephell-shells>=0.1.3', 'dephell-specifier>=0.1.7',
'dephell-venvs>=0.1.16', 'dephell-versioning', 'jinja2', 'm2r',
'packaging', 'pip<=19.3.1,>=18.0', 'requests', 'tomlkit', 'yaspin'
],
extras_require={
"dev": [
Expand Down

0 comments on commit bc5abdc

Please sign in to comment.