Skip to content

Commit

Permalink
build: add poetry and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Undertone0809 committed Oct 16, 2023
1 parent 811e7ea commit bd63692
Show file tree
Hide file tree
Showing 20 changed files with 2,128 additions and 22 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: pip install poetry

- name: Set up cache
uses: actions/[email protected]
with:
path: .venv
key: venv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
- name: Analysis the code with lint
run: |
make lint
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Define a variable for Python and notebook files.
PYTHON_FILES=.

#* Lint
.PHONY: lint
lint:
poetry run black $(PYTHON_FILES) --check
poetry run isort --settings-path pyproject.toml ./
3 changes: 3 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ if __name__ == "__main__":
- [ ] 提供图片自定义格式化命名方式
- [ ] 构建PDF转换器
- [x] 提供markdown其他元素的替换
- [ ] 接入各种平台的markdown转换
- [ ] 语雀
- [ ] 飞书


## FAQ
Expand Down
2 changes: 1 addition & 1 deletion example/aliyun_oss_usage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from imarkdown import MdImageConverter, AliyunAdapter, MdFile
from imarkdown import AliyunAdapter, MdFile, MdImageConverter


def main():
Expand Down
2 changes: 1 addition & 1 deletion example/custom_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from imarkdown import MdImageConverter, BaseMdAdapter, MdFile
from imarkdown import BaseMdAdapter, MdFile, MdImageConverter


class CustomMdAdapter(BaseMdAdapter):
Expand Down
2 changes: 1 addition & 1 deletion example/custom_element_finder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import List

from imarkdown import BaseElementFinder, MdFile, MdImageConverter, LocalFileAdapter
from imarkdown import BaseElementFinder, LocalFileAdapter, MdFile, MdImageConverter


class CustomElementFinder(BaseElementFinder):
Expand Down
2 changes: 1 addition & 1 deletion example/local_storage_usage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from imarkdown import MdImageConverter, LocalFileAdapter, MdFile
from imarkdown import LocalFileAdapter, MdFile, MdImageConverter


def main():
Expand Down
8 changes: 6 additions & 2 deletions imarkdown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from imarkdown.adapter.aliyun_adapter import AliyunAdapter
from imarkdown.adapter.base import BaseMdAdapter
from imarkdown.adapter.local_adapter import LocalFileAdapter
from imarkdown.converter import MdImageConverter, BaseMdImageConverter, BaseElementFinder
from imarkdown.converter import (
BaseElementFinder,
BaseMdImageConverter,
MdImageConverter,
)
from imarkdown.schema import MdFile, MdFolder

__all__ = [
Expand All @@ -12,5 +16,5 @@
"BaseMdAdapter",
"LocalFileAdapter",
"AliyunAdapter",
"BaseElementFinder"
"BaseElementFinder",
]
3 changes: 2 additions & 1 deletion imarkdown/adapter/aliyun_adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Optional, Any, Dict
from typing import Any, Dict, Optional

from pydantic import root_validator

Expand Down Expand Up @@ -31,6 +31,7 @@ class AliyunAdapter(BaseMdAdapter):

@root_validator(pre=True)
def validate_environment(cls, values: Optional[Dict]) -> Dict:
# update adapter config to cache
env_config: Dict[str, Any] = cfg.load_variable(cls.__name__)
if env_config:
if not values:
Expand Down
2 changes: 1 addition & 1 deletion imarkdown/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class MdAdapterType(str, Enum):

_MdAdapterType: Dict[str, str] = {
MdAdapterType.Local: MdAdapterType.Local,
MdAdapterType.Aliyun: MdAdapterType.Aliyun
MdAdapterType.Aliyun: MdAdapterType.Aliyun,
}
8 changes: 4 additions & 4 deletions imarkdown/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import time
import traceback
from abc import abstractmethod
from typing import List, Optional, Any, Union, Dict
from typing import Any, Dict, List, Optional, Union

import requests
from pydantic import BaseModel, Field, root_validator

from imarkdown.adapter import BaseMdAdapter, MdAdapterMapper
from imarkdown.config import IMarkdownConfig
from imarkdown.constant import MdAdapterType
from imarkdown.schema import MdMediumManager, MdFile, MdFolder
from imarkdown.schema import MdFile, MdFolder, MdMediumManager
from imarkdown.utils import (
calculate_relative_path,
get_file_name_from_relative_path,
polish_path,
supplementary_file_path,
get_file_name_from_relative_path,
calculate_relative_path,
)

logger = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions imarkdown/schema.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import glob
import logging
import os
from typing import List, Optional, Any, Dict, Union
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel, root_validator, validator
from typing_extensions import Literal

from imarkdown.utils import (
supplementary_file_path,
convert_backslashes,
exist_markdown_file,
supplementary_file_path,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -225,6 +225,7 @@ def init_md_files(
Returns:
A list of all MdFile.
"""

def find_sub_files(md_folder: MdFolder):
for sub_node in md_folder.sub_nodes:
if isinstance(sub_node, MdFile):
Expand Down
10 changes: 10 additions & 0 deletions imarkdown/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def convert_backslashes(path):


def calculate_relative_path(image_path, md_directory):
"""
Calculate relative image path.
Args:
image_path: Absolute or relative image path.
md_directory: Absolute or relative markdown file path.
Returns:
Relative path of image compared to markdown file path.
"""
image_path = os.path.abspath(image_path)
md_directory = os.path.abspath(md_directory)

Expand Down
1 change: 1 addition & 0 deletions imarkdown/utils/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):

def singleton():
"""singleton decorator"""

def decorator(cls):
singleton_pool = SingletonPool()

Expand Down
Loading

0 comments on commit bd63692

Please sign in to comment.