Skip to content

Commit 1467f64

Browse files
committed
feat: refactoring
1 parent 653a374 commit 1467f64

10 files changed

Lines changed: 1066 additions & 136 deletions

File tree

.github/workflows/release.yml

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
11
name: Release Package
22

3+
# need to setup:
4+
# secrets.PYPI_PASSWORD (See: https://pypi.org/help/#apitoken)
5+
36
on:
47
push:
58
tags:
6-
- '*'
9+
- v*
10+
env:
11+
PYTHON_VERSION: '3.11'
12+
PROJECT_NAME: my_best_python_project
713

814
jobs:
915
release:
10-
name: Create Release
1116
runs-on: ubuntu-latest
1217
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@master
15-
- name: Create Release
16-
id: create_release
17-
uses: actions/create-release@v1
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20-
with:
21-
tag_name: ${{ github.ref }}
22-
release_name: Release ${{ github.ref }}
23-
draft: false
24-
prerelease: false
18+
- uses: actions/checkout@v3
19+
20+
- id: create_release
21+
uses: actions/create-release@v1
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
with:
25+
tag_name: ${{ github.ref }}
26+
release_name: Release ${{ github.ref }}
27+
draft: false
28+
prerelease: false
2529
pypi:
2630
needs: release
2731
runs-on: ubuntu-latest
2832
steps:
29-
- uses: actions/checkout@v2
30-
with:
31-
persist-credentials: false
32-
- name: Set up Python
33-
uses: actions/setup-python@v1
34-
with:
35-
python-version: "3.x"
36-
- name: Install dependencies
37-
run: |
38-
python -m pip install --upgrade pip
39-
pip install setuptools wheel twine
40-
- name: Build and publish
41-
env:
42-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
43-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
44-
run: |
45-
python setup.py sdist bdist_wheel
46-
twine upload dist/*
33+
- uses: actions/checkout@v3
34+
with:
35+
persist-credentials: false
36+
- name: Build and publish to pypi
37+
uses: JRubics/[email protected]
38+
with:
39+
pypi_token: ${{ secrets.PYPI_TOKEN }}
40+
ghcr:
41+
needs: release
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- uses: docker/metadata-action@v4
46+
id: meta
47+
with:
48+
images: ghcr.io/${{ github.repository }}
49+
tags: |
50+
type=semver,pattern={{version}}
51+
type=semver,pattern={{major}}.{{minor}}
52+
- uses: docker/login-action@v2
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.repository_owner }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- uses: docker/build-push-action@v4
58+
with:
59+
context: .
60+
push: true
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
build-args: |
64+
VERSION=${{ github.event.release.tag_name }}

.pre-commit-config.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-added-large-files
6+
args: [--maxkb=2000]
7+
- id: check-ast
8+
- id: check-case-conflict
9+
- id: check-executables-have-shebangs
10+
- id: check-merge-conflict
11+
- id: check-symlinks
12+
- id: check-toml
13+
- id: check-yaml
14+
- id: debug-statements
15+
- id: destroyed-symlinks
16+
- id: end-of-file-fixer
17+
files: \.(py|sh|rst|yml|yaml)$
18+
- id: mixed-line-ending
19+
- id: trailing-whitespace
20+
files: \.(py|sh|rst|yml|yaml)$
21+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
22+
rev: v2.7.0
23+
hooks:
24+
- id: pretty-format-yaml
25+
args: [--autofix, --indent, '2']
26+
- repo: https://github.com/tox-dev/pyproject-fmt
27+
rev: 0.9.1
28+
hooks:
29+
- id: pyproject-fmt
30+
- repo: https://github.com/psf/black
31+
rev: 23.1.0
32+
hooks:
33+
- id: black
34+
- repo: https://github.com/charliermarsh/ruff-pre-commit
35+
rev: v0.0.248
36+
hooks:
37+
- id: ruff
38+
args: [--fix]
39+
- repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: v1.0.1
41+
hooks:
42+
- id: mypy
43+
files: ^shindan_cli/
44+
args: [--strict]
45+
additional_dependencies:
46+
- types-beautifulsoup4
47+
- types-requests
48+
- lxml-stubs
49+
- repo: https://github.com/igorshubovych/markdownlint-cli
50+
rev: v0.33.0
51+
hooks:
52+
- id: markdownlint
53+
exclude: ^.github/PULL_REQUEST_TEMPLATE.md
54+
args: [--disable=MD013]

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3
2+
3+
ARG VERSION
4+
ENV VERSION ${VERSION:-master}
5+
6+
RUN pip install --upgrade pip
7+
8+
RUN python -m pip install git+https://github.com/eggplants/shindan_cli@${VERSION}
9+
10+
ENTRYPOINT ["shindan"]

poetry.lock

Lines changed: 786 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1+
# poetry self add poetry-bumpversion
2+
13
[build-system]
2-
requires = ["wheel", "setuptools"]
3-
build-backend = "setuptools.build_meta"
4+
build-backend = "poetry.core.masonry.api"
5+
requires = [
6+
"poetry-core",
7+
]
8+
9+
[tool]
10+
[tool.black]
11+
line-length = 120
12+
target-version = ['py39']
13+
14+
[tool.isort]
15+
profile = "black"
16+
17+
[tool.mypy]
18+
pretty = true
19+
python_version = "3.9"
20+
show_error_codes = true
21+
strict = true
22+
23+
[tool.ruff]
24+
select = ["ALL"]
25+
ignore = ["D211", "D213"]
26+
line-length = 120
27+
28+
[tool.ruff.mccabe]
29+
max-complexity = 18
30+
31+
[tool.poetry]
32+
authors = ["eggplants <[email protected]>"]
33+
classifiers = [
34+
"Development Status :: 3 - Alpha",
35+
"License :: OSI Approved :: MIT License",
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.7",
38+
"Programming Language :: Python :: 3.8",
39+
"Programming Language :: Python :: 3.9",
40+
"Programming Language :: Python :: 3.10",
41+
"Programming Language :: Python :: 3 :: Only"
42+
]
43+
description = "ShindanMaker (https://shindanmaker.com) CLI"
44+
keywords = ["shindanmaker", "cli"]
45+
name = "shindan_cli"
46+
packages = [{include = "shindan_cli"}]
47+
license = "MIT"
48+
readme = "README.md"
49+
repository = "https://github.com/eggplants/shindan-cli"
50+
version = "0.9.0"
51+
52+
[tool.poetry.dependencies]
53+
python = ">=3.7,<4"
54+
beautifulsoup4 = "^4.11.2"
55+
lxml = "^4.9.2"
56+
requests = "^2.28.2"
57+
58+
59+
[tool.poetry.group.dev.dependencies]
60+
mypy = "^0.991"
61+
pre-commit = "^2.20.0"
62+
taskipy = "^1.10.3"
63+
types-beautifulsoup4 = "^4.11.6.7"
64+
types-requests = "^2.28.11.14"
65+
lxml-stubs = "^0.4.0"
66+
67+
[tool.poetry.scripts]
68+
mbpp = "shindan_cli.main:main"
69+
70+
[tool.poetry_bumpversion.file."shindan_cli/__init__.py"]
71+
72+
[tool.taskipy.tasks]
73+
lint = "pre-commit run -a"
74+
profile = "python -m cProfile"

setup.cfg

Lines changed: 0 additions & 54 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

shindan_cli/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from .shindan import shindan
1+
"""Initialize shindan-cli package."""
2+
from __future__ import annotations
23

3-
__version__ = "0.9"
4-
__all__ = ["shindan"]
4+
from .shindan import ShindanResult, shindan
5+
6+
__version__ = "0.9.0"
7+
__all__ = ("shindan", "ShindanResult")

shindan_cli/main.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
1+
"""Implements Shindan CLI as a main script."""
2+
3+
from __future__ import annotations
4+
15
import argparse
26

37
from . import __version__, shindan
48

59

6-
def check_natural(v: str) -> int:
10+
def _check_natural(v: str) -> int:
711
if int(v) < 0:
812
raise argparse.ArgumentTypeError("%s is an invalid natural int" % v)
9-
else:
10-
return int(v)
13+
return int(v)
1114

1215

13-
def parse_args() -> argparse.Namespace:
14-
"""Parse arguments."""
16+
def _parse_args() -> argparse.Namespace:
1517
parser = argparse.ArgumentParser(
1618
prog="shindan",
1719
formatter_class=argparse.RawDescriptionHelpFormatter,
1820
description="ShindanMaker (https://shindanmaker.com) CLI",
1921
)
20-
parser.add_argument(
21-
"page_id", metavar="ID", type=check_natural, help="shindan page id"
22-
)
22+
parser.add_argument("page_id", metavar="ID", type=_check_natural, help="shindan page id")
2323
parser.add_argument("shindan_name", metavar="NAME", type=str, help="shindan name")
2424
parser.add_argument("-w", "--wait", action="store_true", help="insert random wait")
25-
parser.add_argument(
26-
"-H", "--hashtag", action="store_true", help="add hashtag `#shindanmaker`"
27-
)
28-
parser.add_argument(
29-
"-l", "--link", action="store_true", help="add link to last of output"
30-
)
31-
parser.add_argument(
32-
"-V", "--version", action="version", version="%(prog)s {}".format(__version__)
33-
)
25+
parser.add_argument("-H", "--hashtag", action="store_true", help="add hashtag `#shindanmaker`")
26+
parser.add_argument("-l", "--link", action="store_true", help="add link to last of output")
27+
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}")
3428
return parser.parse_args()
3529

3630

3731
def main() -> None:
38-
args = parse_args()
32+
"""Run CLI."""
33+
args = _parse_args()
3934
result = shindan(args.page_id, args.shindan_name, wait=args.wait)
40-
print("\n".join(result["results"]))
35+
print("\n".join(result["results"])) # noqa: T201
4136
if args.hashtag:
42-
print(" ".join(result["hashtags"]))
37+
print(" ".join(result["hashtags"])) # noqa: T201
4338
if args.link:
44-
print(result["shindan_url"])
39+
print(result["shindan_url"]) # noqa: T201
4540

4641

4742
if __name__ == "__main__":

0 commit comments

Comments
 (0)