From b4955188c14c18790182bb27610cd48afff056f1 Mon Sep 17 00:00:00 2001 From: kinegratii Date: Wed, 24 Jan 2024 23:20:12 +0800 Subject: [PATCH] :sparkles: Add Festival.code & Upgrade to python3.9+ --- .github/workflows/python-package.yml | 2 +- borax/calendars/festivals2.py | 24 ++++++++++++++++-------- docs/changelog.md | 14 ++++++++++++-- docs/guides/festivals2.md | 27 +++++++++++++++++++++++---- pyproject.toml | 4 +--- setup.py | 5 ++--- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d186a2f..fabc813 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 diff --git a/borax/calendars/festivals2.py b/borax/calendars/festivals2.py index 1c42073..f0d8f3e 100644 --- a/borax/calendars/festivals2.py +++ b/borax/calendars/festivals2.py @@ -6,6 +6,7 @@ import enum import warnings from datetime import date, timedelta, datetime +from functools import cached_property from pathlib import Path from typing import List, Tuple, Optional, Union, Iterator, Set, Generator, Sequence @@ -149,11 +150,11 @@ def from_simple_str(cls, date_str: str) -> 'WrappedDate': def encode(self) -> str: if self._fl == 'l': festival = LunarFestival(month=self.lunar.month, day=self.lunar.day, leap=self.lunar.leap) - encoded_str = festival.encode() + encoded_str = festival.code return '{}{:04d}{}'.format(encoded_str[0], self.lunar.year, encoded_str[1:]) else: festival = SolarFestival(month=self.solar.month, day=self.solar.day) - encoded_str = festival.encode() + encoded_str = festival.code return '{}{:04d}{}'.format(encoded_str[0], self.solar.year, encoded_str[1:]) @classmethod @@ -231,6 +232,10 @@ def set_name(self, name): self._name = name return self + @cached_property + def code(self): + return self.encode() + @property def schema(self): return self._schema @@ -980,19 +985,22 @@ def print_(self): def get_code_set(self) -> Set[str]: """Get codes for all festivals. """ - return set([f.encode() for f in self.data]) + return set([f.code for f in self.data]) - def extend_unique(self, other: Union[collections.UserList, List[str], 'FestivalLibrary']) -> 'FestivalLibrary': + def extend_unique( + self, + other: Union[collections.UserList, List[Union[str, Festival]], 'FestivalLibrary'] + ) -> 'FestivalLibrary': """Add a new festival if code does not exist. """ - f_codes = {f.encode() for f in self.data} + f_codes = {f.code for f in self.data} if isinstance(other, collections.UserList): new_data = other.data else: new_data = other for item in new_data: if isinstance(item, Festival): - if item.encode() not in f_codes: + if item.code not in f_codes: self.data.append(item) elif isinstance(item, str): try: @@ -1160,7 +1168,7 @@ def to_csv(self, path_or_buf): fileobj = path_or_buf writer = csv.writer(fileobj) for festival in self: - row = (festival.encode(), festival.name, festival.catalog) + row = (festival.code, festival.name, festival.catalog) writer.writerow(row) @classmethod @@ -1185,7 +1193,7 @@ def load_file(cls, file_path: Union[str, Path], unique: bool = False) -> 'Festiv fl.append(festival) except ValueError: continue - fl.sort(key=lambda x: x.encode()) + fl.sort(key=lambda x: x.code) return fl def filter(self, catalogs: Sequence = None) -> 'FestivalLibrary': diff --git a/docs/changelog.md b/docs/changelog.md index 8752124..729631f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,10 +1,19 @@ # 更新日志 -## v4.1.0 +## v4.1.0 (20240330) + +> Borax最低python版本要求为python3.9 + +[发布日志](/release-note/v410) + - 功能更新 - 新增 [Borax日历应用](/guides/borax_calendar_app) + - 包 `borax.apps` 变更为 `borax.capp` - 新增方法 `FestivalLibrary.extend_term_festivals` + - 新增 `borax.ui.widgets.MessageLabel` 类 + - `Festival` 类新增 `code` 属性 - 项目构建 + - 不再支持python3.7和python3.8 - 本地开发环境更新至 python3.11.7 - 使用 *pyproject.toml* 项目构建配置文件,构建命令 `python -m build -w` - 支持python3.12 @@ -12,9 +21,10 @@ - mkdocs-material 更新至 9.5.3 - 不再支持 docsify 构建(index.html 冲突) - ## v4.0.0 (20221115) +[发布日志](/release-note/v400) + - 新增基于 tkinter 的 [节日界面库](/guides/festivals2-ui) - 移除源代码文件编码声明行 - 移除 `borax.calendars.festival` 模块 diff --git a/docs/guides/festivals2.md b/docs/guides/festivals2.md index f6a0ff4..a8d7cd7 100644 --- a/docs/guides/festivals2.md +++ b/docs/guides/festivals2.md @@ -2,6 +2,8 @@ > 模块: `borax.calendars.festivals2` +> Updated in 4.1.0:新增 Festival.code属性。 + > Updated in 3.5.6: 星期型节日(WeekFestival)类支持倒数序号。如:“国际麻风节(1月最后一个星期天)” > Updated in 3.5.6: 星期型节日(WeekFestival)类支持每月频率。 @@ -247,6 +249,14 @@ TermFestival(index=0) ## Festival属性 +### code + +> Add in 4.1.0 + +类型:str,编码字符串。 `FestivalLibrary` 以此属性作为唯一性的标志。 + +需要注意的是该属性使用 `cached_property` 进行修饰。 + ### name 类型:str,节日名称,如“元旦”、“中秋节”等。 @@ -408,12 +418,14 @@ print(spring_festival.countdown()) # (273, 'FestivalLibrary' ### load_builtin ```python -FestivalLibrary.load_builtin(cls, identifier: str = 'zh-Hans') -> 'FestivalLibrary' +FestivalLibrary.load_builtin(cls, identifier: str = 'basic') -> 'FestivalLibrary' ``` 加载Borax提供的节日库数据。 diff --git a/pyproject.toml b/pyproject.toml index 7419bb0..0996dc9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,14 +9,12 @@ authors = [ ] description = "A tool collections.(Chinese-Lunar-Calendars/Python-Patterns)" readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.9" keywords = ["chinese lunar calendar", "python tool"] license = { text = "MIT License" } classifiers = [ "Development Status :: 5 - Production/Stable", "Programming Language :: Python :: 3", - "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", diff --git a/setup.py b/setup.py index a9d9464..b99d7a5 100644 --- a/setup.py +++ b/setup.py @@ -12,11 +12,10 @@ lib_classifiers = [ "Development Status :: 5 - Production/Stable", "Programming Language :: Python :: 3", - "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 :: 3.12", "Programming Language :: Python :: 3 :: Only", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -31,7 +30,7 @@ setup( name='borax', version=version, - python_requires='>=3.7', + python_requires='>=3.9', packages=find_packages(exclude=['tests']), include_package_data=True, license='MIT',