Skip to content

Commit

Permalink
♻️ Refactor borax.calendars.dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
kinegratii committed Jan 13, 2024
1 parent ae2b502 commit 02105b4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include borax/calendars/FestivalData.csv
include borax/calendars/dataset/FestivalData.csv
include borax/calendars/dataset/festivals_ext1.csv
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $ pip install borax
Borax的版本符合 [语义化版本](https://semver.org/lang/zh-CN/) ,格式为 `<主版本号>.<副版本号>.<修正版本号>`, 推荐使用下面方式定义Borax的依赖版本号。

```text
borax~=3.5
borax~=4.1
```

## 使用示例 (Usage)
Expand Down Expand Up @@ -221,7 +221,7 @@ print(FinanceNumbers.to_capital_str(decimal.Decimal(4.50))) # '肆元伍角零

## 项目构建 (Project Build)

从4.0.1开始,borax 使用 *pyproject.toml* 作为项目构建的配置文件,使用以下命令构建 wheel 发行包。
从4.1.0 开始,borax 使用 *pyproject.toml* 作为项目构建的配置文件,使用以下命令构建 wheel 发行包。

```shell
python -m build -w
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions borax/calendars/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

__all__ = ['get_festival_dataset_path']

_FILE_DICT = {
'basic': 'FestivalData.csv',
'ext1': 'festivals_ext1.csv',
'zh-Hans': 'FestivalData.csv'
}


def get_festival_dataset_path(identifier: str) -> Path:
"""Return the full path for festival dataset csv file."""
return Path(__file__).parent / _FILE_DICT.get(identifier)
10 changes: 2 additions & 8 deletions borax/calendars/festivals2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
from typing import List, Tuple, Optional, Union, Iterator, Set, Generator, Sequence

from borax.calendars.dataset import get_festival_dataset_path
from borax.calendars.lunardate import LunarDate, LCalendars, TermUtils, TextUtils, TERMS_CN

__all__ = [
Expand Down Expand Up @@ -1211,11 +1212,4 @@ def load_builtin(cls, identifier: str = 'basic') -> 'FestivalLibrary':
"""
if identifier == 'empty':
return FestivalLibrary()
if identifier == 'zh-Hans': # Old identifier
identifier = 'basic'
file_dict = {
'basic': 'FestivalData.csv',
'ext1': 'dataset/festivals_ext1.csv'
}
file_path = Path(__file__).parent / file_dict.get(identifier)
return cls.load_file(file_path)
return cls.load_file(get_festival_dataset_path(identifier))
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@
description='A tool collections.(Chinese-Lunar-Calendars/Python-Patterns)',
long_description=long_description,
long_description_content_type='text/markdown',
entry_points={
"gui_scripts": [
"festival_creator = borax.apps.festival_creator:main"
]
},
)

0 comments on commit 02105b4

Please sign in to comment.