Skip to content

Commit

Permalink
Merge pull request #8 from HansBug/dev/refactor
Browse files Browse the repository at this point in the history
dev(hansbug): refactor
  • Loading branch information
HansBug authored May 6, 2023
2 parents a446a2f + 44946a6 commit f47ddab
Show file tree
Hide file tree
Showing 55 changed files with 703 additions and 876 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
python-version: [ 3.7 ]
python-version:
- '3.8'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download cloc
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
python-version: [ 3.7 ]
python-version:
- '3.8'

services:
plantuml:
Expand All @@ -26,9 +27,9 @@ jobs:
- 18080:8080

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Code Lint

on: [ push, pull_request ]
on:
push:

jobs:
test:
Expand All @@ -14,16 +15,18 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 20
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install -y libxml2-dev libxslt-dev python-dev # need by pypy3
sudo apt-get update -y
sudo apt-get install -y tree make wget curl cloc graphviz
dot -V
python -m pip install --upgrade pip
pip install --upgrade flake8 setuptools wheel twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 20
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up python dependences
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ name: Repository Sync

on:
push:
pull_request:
schedule:
- cron: '0 1 * * *'
- cron: '0 1 * * *'

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Mirror the Github organization repos to Gitee
uses: Yikun/hub-mirror-action@master
with:
src: github/HansBug
dst: gitee/hansbug
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
static_list: "plantumlcli"
force_update: true
- name: Mirror the Github organization repos to Gitee
uses: Yikun/hub-mirror-action@master
with:
src: github/HansBug
dst: gitee/hansbug
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
static_list: "plantumlcli"
force_update: true
59 changes: 19 additions & 40 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Code Test

on:
push:
pull_request:
schedule:
- cron: '0 0 1 * *'

Expand All @@ -17,26 +16,24 @@ jobs:
os:
- 'ubuntu-latest'
python-version:
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- 'pypy-3.6'
- 'pypy-3.8'
- '3.10'
- '3.11'
- 'pypy-3.7'
- 'pypy-3.9'
java-version:
- '8'
plantuml-server-version:
- 'latest'
- 'jetty-v1.2023.6'
- 'jetty-v1.2021.14'
- 'jetty-v1.2020.19'
- 'jetty-v1.2019.11'
plantuml-version:
- '1.2023.6'
- '1.2021.12'
assistant-plantuml-version:
- '1.2021.12'
- '1.2020.19'
- '1.2019.13'
- '1.2018.14'
- '1.2017.20'

services:
Expand All @@ -47,30 +44,24 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 20
- name: Set up system dependences on linux
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install -y tree cloc wget curl make
sudo apt-get install -y graphviz
sudo dot -c
sudo apt-get install -y libxml2-dev libxslt-dev python-dev # need by pypy3
- name: Load testfile
env:
TESTFILE_VERSION: 0.0.1
run: |
git clone "https://github.com/HansBug/plantumlcli-testfile" "demo"
sudo apt-get update -y
sudo apt-get install -y tree make wget curl cloc graphviz
dot -V
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up java ${{ matrix.java-version }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
distribution: temurin
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -87,32 +78,20 @@ jobs:
tree .
cloc plantuml
cloc test
- name: Test the plantuml in use (${{ matrix.plantuml-version }} and ${{ matrix.assistant-plantuml-version }})
- name: Test the plantuml in use (jar ${{ matrix.plantuml-version }}, server ${{ matrix.plantuml-server-version }})
env:
TEST_PLANTUML_HOST: http://localhost:18080
PLANTUML_HOST: http://localhost:18080
run: |
java -jar demo/jar/plantuml.${{ matrix.plantuml-version }}.jar -version
java -jar demo/jar/plantuml.${{ matrix.assistant-plantuml-version }}.jar -version
curl -L "${TEST_PLANTUML_HOST}/txt/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IG80"
curl -L "${PLANTUML_HOST}/txt/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IG80"
- name: Run unittest
env:
PRIMARY_JAR_VERSION: ${{ matrix.plantuml-version }}
ASSISTANT_JAR_VERSION: ${{ matrix.assistant-plantuml-version }}
TEST_PLANTUML_HOST: http://localhost:18080
PLANTUML_JAR_VERSION: ${{ matrix.plantuml-version }}
PLANTUML_HOST: http://localhost:18080
TIMEOUT: '30'
run: |
source env.sh
make unittest WORKERS=${WORKERS}
- name: Run benchmark
env:
PRIMARY_JAR_VERSION: ${{ matrix.plantuml-version }}
ASSISTANT_JAR_VERSION: ${{ matrix.assistant-plantuml-version }}
TEST_PLANTUML_HOST: http://localhost:18080
run: |
source env.sh
make benchmark
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,5 @@ __pycache__
*.svg
*.latex
*.eps
/get-pip.py
/get-pip.py
!/test/testfile/**/*
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: docs pdocs test unittest benchmark
.PHONY: docs pdocs test unittest

RERUN ?=
RERUN_DELAY ?=
Expand Down Expand Up @@ -43,9 +43,6 @@ unittest:
$(if ${CI}${ACTUAL_RERUN},--reruns ${ACTUAL_RERUN} --reruns-delay ${ACTUAL_RERUN_DELAY},) \
$(if ${ACTUAL_TIMEOUT},--timeout=${ACTUAL_TIMEOUT},)

benchmark:
pytest ${RANGE_TEST_DIR} -sv -m benchmark --durations=0

docs:
$(MAKE) -C "${DOC_DIR}" build
pdocs:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_shims/plantumlcli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from plantumlcli.entrance.cli import cli as plantumlcli_cli
from plantumlcli.entry.cli import cli as plantumlcli_cli

if __name__ == '__main__':
plantumlcli_cli()
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# a list of plugins themes.
#
html_theme = 'sphinx_rtd_theme'
htmlhelp_basename = 'TreeValue'
htmlhelp_basename = 'plantumlcli'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the plugins static files,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions plantumlcli/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def __init__(self):
def autoload(cls, *args, **kwargs):
"""
Autoload plantuml object from given arguments
:return: auto-loaded plantuml object
:return: autoloaded plantuml object
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _check_version(self, version: str):
pass

@abstractmethod
def _get_version(self) -> str:
raise NotImplementedError
raise NotImplementedError # pragma: no cover

@property
def version(self) -> str:
Expand Down Expand Up @@ -92,7 +92,7 @@ def test(self) -> bool:

@abstractmethod
def _generate_uml_data(self, type_: PlantumlResourceType, code: str) -> bytes:
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def dump(self, path: str, type_: Union[int, str, PlantumlResourceType], code: str):
"""
Expand Down Expand Up @@ -135,7 +135,7 @@ def __repr__(self):

def try_plantuml(cls: Type[_Tp], *args, **kwargs) -> Tuple[bool, Union[Optional[_Tp], Exception]]:
"""
Try initialize plantuml object
Try to initialize plantuml object
:param cls: plantuml class
:param args: arguments
:param kwargs: key-word arguments
Expand Down
7 changes: 3 additions & 4 deletions plantumlcli/models/local.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import os
import re
import shutil
from tempfile import TemporaryDirectory, NamedTemporaryFile
from typing import Tuple, Optional, Mapping, Any

import where

from .base import Plantuml, PlantumlResourceType
from ..utils import load_binary_file, save_text_file, CommandLineExecuteError, execute

PLANTUML_JAR_ENV = 'PLANTUML_JAR'


def find_java_from_env() -> Optional[str]:
return where.first('java')
return shutil.which('java')


def find_java(java: Optional[str] = None) -> Optional[str]:
Expand Down Expand Up @@ -64,7 +63,7 @@ def __init__(self, java: str, plantuml: str):
_check_local(self.__java, self.__plantuml)

@classmethod
def autoload(cls, java: str = None, plantuml: str = None, **kwargs) -> 'LocalPlantuml':
def autoload(cls, java: Optional[str] = None, plantuml: Optional[str] = None, **kwargs) -> 'LocalPlantuml':
"""
Autoload LocalPlantuml object from given parameters and the environment
:param java: java executable file path
Expand Down
5 changes: 5 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ pytest-mock~=3.6.1
pytest-rerunfailures~=10.2
pytest-timeout~=2.0.2
more-itertools>=7,<8
testtools>=2
coverage>=5
mock>=4.0.3
huggingface_hub
pysyslimit>=0.5.0
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
where~=1.0
click>=7.0
colorama~=0.4
requests~=2.12
requests>=2.12
urlobject~=2.4
pyquery~=1.4
prettytable~=1.0
chardet~=3.0
chardet~=3.0
hbutils>=0.9.0
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _load_req(file: str):
url='https://github.com/HansBug/plantumlcli',

# environment
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=requirements,
tests_require=group_requirements['test'],
extras_require=group_requirements,
Expand All @@ -56,10 +56,11 @@ def _load_req(file: str):
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation :: PyPy'
],
include_package_data=True,
Expand All @@ -70,7 +71,7 @@ def _load_req(file: str):
},
entry_points={
'console_scripts': [
'plantumlcli=plantumlcli.entrance.cli:cli'
'plantumlcli=plantumlcli.entry.cli:cli'
]
},
)
Loading

0 comments on commit f47ddab

Please sign in to comment.