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 #361 from dephell/package-changelog
`package changelog` command
- Loading branch information
Showing
11 changed files
with
117 additions
and
16 deletions.
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
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
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,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 |
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
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/). |
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