Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add poetry and github actions #13

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: 🐛 Bug report
about: If something isn't working 🔧
title: ''
labels: bug
assignees:
---

## 🐛 Bug Report

<!-- A clear and concise description of what the bug is. -->

## 🔬 How To Reproduce

Steps to reproduce the behavior:

1. ...

### Code sample

<!-- If applicable, attach a minimal code sample to reproduce the decried issue. -->

### Environment

* OS: [e.g. Linux / Windows / macOS]
* Python version, get it with:

```bash
python --version
```

### Screenshots

<!-- If applicable, add screenshots to help explain your problem. -->

## 📈 Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## 📎 Additional context

<!-- Add any other context about the problem here. -->
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Configuration: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository

blank_issues_enabled: false
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: 🚀 Feature request
about: Suggest an idea for this project 🏖
title: ''
labels: enhancement
assignees:
---

## 🚀 Feature Request

<!-- A clear and concise description of the feature proposal. -->

## 🔈 Motivation

<!-- Please describe the motivation for this proposal. -->

## 🛰 Alternatives

<!-- A clear and concise description of any alternative solutions or features you've considered. -->

## 📎 Additional context

<!-- Add any other context or screenshots about the feature request here. -->
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: ❓ Question
about: Ask a question about this project 🎓
title: ''
labels: question
assignees:
---

## Checklist

<!-- Mark with an `x` all the checkboxes that apply (like `[x]`) -->

- [ ] I've searched the project's [`issues`](https://github.com/Undertone0809/python-package-template/issues?q=is%3Aissue).

## ❓ Question

<!-- What is your question -->

How can I [...]?

Is it possible to [...]?

## 📎 Additional context

<!-- Add any other context or screenshots about the feature request here. -->
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