Skip to content

Commit

Permalink
add changelog (#109)
Browse files Browse the repository at this point in the history
* add changelog

* fix script
  • Loading branch information
koxudaxi committed Apr 23, 2020
1 parent d78089d commit dfae149
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -39,4 +39,5 @@ hs_err_pid*
/out/
/pydantic-pycahrm-plugin/out/
/venv/
/site
/site
/docs/changelog.md
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,7 @@ install:

script:
- travis_wait ./gradlew buildPlugin test jacocoTestReport
- python scripts/build_changelog.py
- mkdocs build --verbose --clean --strict
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
6 changes: 5 additions & 1 deletion docs/install.md
Expand Up @@ -12,5 +12,9 @@ The releases section of this repository contains a compiled version of the plugi
After downloading this file, you can install the plugin from disk by following [the JetBrains instructions here](https://www.jetbrains.com/help/pycharm/plugins-settings.html).

### Source
Alternatively, you can clone this repository and follow the instructions under the "Building the plugin" heading below to build from source. The build process will create the file `build/distributions/pydantic-pycharm-plugin.zip`. This file can be installed as a PyCharm plugin from disk following the same instructions.
Alternatively, you can clone this repository and follow the instructions under the "Building the plugin" heading below to build from source.
The build process will create the file `build/distributions/pydantic-pycharm-plugin.zip`.
This file can be installed as a PyCharm plugin from disk following the same instructions.



11 changes: 7 additions & 4 deletions docs/type-checking.md
@@ -1,7 +1,9 @@
### Inspection for type-checking
**Experimental**

**In version 0.1.1, This feature is broken. Please use it in [0.1.2](https://github.com/koxudaxi/pydantic-pycharm-plugin/releases/tag/0.1.2) or later.**
!!! warning
**Experimental feature**

!!! info
**In version 0.1.1, This feature is broken. Please use it in [0.1.2](https://github.com/koxudaxi/pydantic-pycharm-plugin/releases/tag/0.1.2) or later.**

This plugin provides an inspection for type-checking, which is compatible with pydantic.

Expand Down Expand Up @@ -50,7 +52,8 @@ acceptable-type-highlight = "disable"
```

### Acceptable Type
**This feature is in version [0.1.3](https://github.com/koxudaxi/pydantic-pycharm-plugin/releases/tag/0.1.3) or later.**
!!! info
**This feature is in version [0.1.3](https://github.com/koxudaxi/pydantic-pycharm-plugin/releases/tag/0.1.3) or later.**

Pydantic can always parse a few types to other types. For example, `int` to `str`. It always succeeds.
You can set it as an acceptable type. The message is `Field is of type 'x', 'y' is set as an acceptable type in pyproject.toml`.
Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Expand Up @@ -9,6 +9,7 @@ theme:

markdown_extensions:
- codehilite
- admonition

repo_name: koxudaxi/pydantic-pycharm-plugin
repo_url: https://github.com/koxudaxi/pydantic-pycharm-plugin
Expand All @@ -23,7 +24,7 @@ nav:
- Usage:
- Inspection for type-checking: type-checking.md
- Development: development.md

- Changelog: changelog.md

plugins:
- search
68 changes: 68 additions & 0 deletions scripts/build_changelog.py
@@ -0,0 +1,68 @@
import re
import xml.etree.ElementTree
from enum import Enum
from html.parser import HTMLParser
from pathlib import Path
from typing import List

PROJECT_ROOT = Path(__file__).parent.parent

GITHUB_PR_URL: str = 'https://github.com/koxudaxi/pydantic-pycharm-plugin/pull/'


class Tag(Enum):
Version = 'h2'
ChangeType = 'p'
ChangeBody = 'ul'
ChangeContent = 'li'


def get_markdown_hyperlinks(text: str) -> List[str]:
return [
f'[#{pr_number}]({GITHUB_PR_URL}/{pr_number})'
for pr_number in re.findall(r'#(\d+)', text)
]


class HistoryHTMLParser(HTMLParser):
def error(self, message):
pass

def __init__(self):
super().__init__()
self.current_tag: Tag = Tag.Version
self.markdown: str = ''

def handle_starttag(self, tag: str, attrs):
self.current_tag = Tag(tag)

def handle_endtag(self, tag):
pass

def handle_data(self, data: str):
if not data.strip():
return
if self.current_tag == Tag.Version:
self.markdown += f'## {data.replace("version ", "")}\n'
elif self.current_tag == Tag.ChangeType:
self.markdown += f'### {data}\n'
elif self.current_tag == Tag.ChangeContent:
links = get_markdown_hyperlinks(data)
converted_data = re.sub(r'\[[^]].+\]', f'[{", ".join(links)}]', data)
self.markdown += f'- {converted_data}\n'


def main():
plugin_xml = PROJECT_ROOT / 'resources/META-INF/plugin.xml'
tree = xml.etree.ElementTree.parse(str(plugin_xml))
root = tree.getroot()
history: str = root.find('change-notes').text

html_parser = HistoryHTMLParser()
html_parser.feed(history)
with open(PROJECT_ROOT / 'docs/changelog.md', 'w') as f:
f.write(html_parser.markdown)


if __name__ == '__main__':
main()

0 comments on commit dfae149

Please sign in to comment.