Skip to content

Commit 2b5fdd0

Browse files
authored
Merge pull request #16 from neatc0der/release/v2.0
Release/v2.0
2 parents a2d7a03 + 0909a10 commit 2b5fdd0

File tree

9 files changed

+130
-47
lines changed

9 files changed

+130
-47
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import json
2+
from typing import Dict, List
3+
from urllib3.poolmanager import PoolManager
4+
from urllib3.response import HTTPResponse
5+
6+
from github.GitRelease import GitRelease
7+
8+
from mkdocs_markmap.__meta__ import PROJECT_NAME
9+
from .common import GithubHandler
10+
11+
12+
PYPI_URL = f'https://pypi.org/pypi/{PROJECT_NAME}/json'
13+
14+
15+
class ReleaseInfo(GithubHandler):
16+
def print(self, github: bool = True, pypi: bool = False) -> None:
17+
if github:
18+
self._print_github()
19+
if pypi:
20+
self._print_pypi()
21+
22+
def _print_github(self) -> None:
23+
release: GitRelease
24+
if self.tag is None:
25+
release = self.repository.get_latest_release()
26+
27+
else:
28+
try:
29+
release = next(r for r in self.repository.get_releases() if r.tag_name == self.tag)
30+
except StopIteration:
31+
print(f'release not found on github: {self.tag}')
32+
return
33+
34+
print(f"""
35+
Release: {release.title}
36+
Url: {release.url}
37+
Created: {release.created_at}
38+
Published: {release.published_at}
39+
Draft: {release.draft}
40+
Prerelease: {release.prerelease}
41+
Assets: {', '.join(a.name for a in release.get_assets())}
42+
""")
43+
44+
def _print_pypi(self) -> None:
45+
http: PoolManager = PoolManager()
46+
response: HTTPResponse = http.request('GET', PYPI_URL)
47+
if response.status != 200:
48+
print(f'error on pypi request: {response._request_url} ({response.status})')
49+
return
50+
51+
project_data = json.loads(response.data)
52+
release_url: str = project_data['info']['release_url']
53+
downloads: Dict[str, int] = project_data['info']['downloads']
54+
55+
version: str
56+
if self.tag is None:
57+
version = project_data['info']['version']
58+
else:
59+
version = self.tag[1:]
60+
release_url = release_url.replace(project_data['info']['version'], version)
61+
62+
try:
63+
assets: List[Dict[str, str]] = project_data['releases'][version]
64+
except KeyError:
65+
print(f'release not found on pypi: {self.tag}')
66+
return
67+
68+
uploaded: str
69+
if not any(assets):
70+
uploaded = 'no assets!'
71+
else:
72+
uploaded = assets[0]['upload_time'].replace('T', ' ')
73+
74+
print(f"""
75+
Release: {version}
76+
Url: {release_url}
77+
Assets: {', '.join(a['filename'] for a in assets)}
78+
Uploaded: {uploaded}
79+
Downloads:
80+
Last Month: {downloads['last_month']}
81+
Last Week: {downloads['last_week']}
82+
Last Day: {downloads['last_day']}
83+
""")

.github/workflows/distribute.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
release:
55
types:
66
- published
7+
- released
78

89
jobs:
910
build:

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ jobs:
3030
- name: Create Release
3131
env:
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
run: inv release --no-dry-run
33+
run: |
34+
inv release --no-dry-run
35+
inv latest --github

README.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pip install mkdocs-markmap
2424
Add this to `mkdocs.yml`:
2525

2626
```yaml
27-
markdown_extensions:
28-
- markmap
2927
plugins:
3028
- markmap
3129
```
@@ -36,12 +34,11 @@ There are more options available for `mkdocs.yml` (shown values are defaults):
3634

3735
```yaml
3836
markdown_extensions:
37+
plugins:
3938
- markmap:
4039
base_path: docs
4140
encoding: utf-8
4241
file_extension: .mm.md
43-
plugins:
44-
- markmap:
4542
d3_version: 6.3.1
4643
lib_version: 0.11.1
4744
view_version: 0.2.1
@@ -62,40 +59,6 @@ extra_javascript:
6259
* `markmap-lib`
6360
* `markmap-view`
6461

65-
## Wait, what?! Do I need an extension or a plugin? :unamused:
66-
67-
_Q: What does the plugin do?_
68-
69-
A: It supports code blocks of markdown as follows:
70-
71-
````markdown
72-
```markmap
73-
# Root
74-
75-
## Branch 1
76-
77-
* Branchlet 1a
78-
* Branchlet 1b
79-
80-
## Branch 2
81-
82-
* Branchlet 2a
83-
* Branchlet 2b
84-
```
85-
````
86-
87-
_Q: What does the extension do?_
88-
89-
A: Well, having such a support is nice, but huge mindmap blocks might be annoying within your tidy markdown files. That is why the extension provides an addition to the markdown syntax. It includes files whereever you need them to be:
90-
91-
```markdown
92-
Look at this beautiful mindmap:
93-
94-
{!mindmap.mm.md!}
95-
```
96-
97-
But you _do_ need the plugin for that. Thus, don't forget to follow the quickstart example above.
98-
9962
## Credits :clap:
10063

10164
Some of the development approaches are based on implementations provided by the following projects:

changelog/v2.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# v2.0
2+
3+
* Simplification for configuration (automated extension registration)
4+
* Extended build commands
5+

mkdocs_markmap/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PACKAGE_NAME = 'mkdocs_markmap'
22
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
3-
PROJECT_VERSION = '1.1.1'
3+
PROJECT_VERSION = '2.0'
44

55
OWNER = 'neatc0der'
66
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'

mkdocs_markmap/extension.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ def run(self, lines: List[str]) -> List[str]:
7272

7373

7474
class MarkmapExtension(Extension):
75+
config_defaults: Dict[str, str] = {
76+
'base_path': ['docs', 'Default location from which to evaluate relative paths for the include statement.'],
77+
'encoding': ['utf-8', 'Encoding of the files used by the include statement.'],
78+
'file_extension': ['.mm.md', 'File extension of mindmap files'],
79+
}
80+
7581
def __init__(self, **configs: Dict[str, str]):
76-
self.config: Dict[str, str] = {
77-
'base_path': ['docs', 'Default location from which to evaluate relative paths for the include statement.'],
78-
'encoding': ['utf-8', 'Encoding of the files used by the include statement.'],
79-
'file_extension': ['.mm.md', 'File extension of mindmap files'],
80-
}
82+
self.config: Dict[str, str] = self.config_defaults
8183
for key, value in configs.items():
8284
self.setConfig(key, value)
8385

mkdocs_markmap/plugin.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from mkdocs_markmap.extension import MarkmapExtension
23
import re
34
from pathlib import Path
45
from typing import Dict, Tuple
@@ -8,7 +9,6 @@
89
from mkdocs.structure.pages import Page
910
from mkdocs.config.base import Config
1011
from mkdocs.config.config_options import Type as PluginType
11-
from mkdocs.utils import copy_file
1212

1313
from .defaults import MARKMAP
1414
from .utils import download
@@ -30,6 +30,9 @@ class MarkmapPlugin(BasePlugin):
3030
(f'{name}_version', PluginType(str, default=module.version))
3131
for name, module in MARKMAP.items()
3232
),
33+
('base_path', PluginType(str, default='docs')),
34+
('encoding', PluginType(str, default='utf-8')),
35+
('file_extension', PluginType(str, default='.mm.md')),
3336
)
3437

3538
def __init__(self):
@@ -78,6 +81,16 @@ def _add_statics(soup: BeautifulSoup):
7881
tag.string = fp.read()
7982
getattr(soup, attribute).append(tag)
8083

84+
def on_config(self, config: Config) -> Config:
85+
config['markdown_extensions'].append('markmap')
86+
config['mdx_configs']['markmap'] = {
87+
key: value
88+
for key, value in config['plugins'].get('markmap').config.items()
89+
if key in MarkmapExtension.config_defaults
90+
}
91+
92+
return config
93+
8194
def on_post_page(self, output_content: str, config: Config, **kwargs) -> str:
8295
soup: BeautifulSoup = BeautifulSoup(output_content, 'html.parser')
8396
page: Page = kwargs.get('page')

tasks.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
sys.path.insert(0, str(PROJECT_PATH / '.build'))
99

1010
from mkdocs_markmap.__meta__ import PROJECT_VERSION
11-
from mkdocs_markmap_build.common import ChangelogLoader
1211
from mkdocs_markmap_build.distribution import DistributionHandler
12+
from mkdocs_markmap_build.info import ReleaseInfo
1313
from mkdocs_markmap_build.release import ReleaseHandler
1414

1515

@@ -49,6 +49,20 @@ def release(c, commit=None, tag=TARGET_TAG, dry_run=True):
4949
handler.create(commit, dry_run=dry_run)
5050

5151

52+
@task
53+
def info(c, tag=None, github=False, pypi=False):
54+
if tag is None:
55+
print('show latest release info')
56+
else:
57+
print(f'show release info: {tag}')
58+
59+
print_github = github or not (github or pypi)
60+
print_pypi = pypi or not (github or pypi)
61+
62+
release: ReleaseInfo = ReleaseInfo(tag)
63+
release.print(github=print_github, pypi=print_pypi)
64+
65+
5266
@task
5367
def distribute(c, tag=TARGET_TAG, dry_run=True):
5468
print(f'distribute release: {tag}')

0 commit comments

Comments
 (0)