Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
1. Fix a crucial error where class attribute values were tampered with in the logic block for importing real code, which caused the last release to fail.
2. Fix a potential error where attempting to access the "ge" magic attribute would raise an exception if the magic attribute did not exist, but also existed in the `builtins` module.
3. Refactor (improve) the method of obtaining version information in `setup` by directly extracting it from `package.__doc__`, rather than opening a file.
4. Adjust the classification information of the open-source library on PyPi.

1.修复一个严重的错误,在导入真实代码的逻辑块中篡改类属性值的错误,这导致上次未成功发布版本。
2.修复一个可能发生的错误,在尝试获取 `ge` 的魔法属性时,如果该魔化属性不存在,同时该魔化属性又存在于 `builtins` 模块,将引发异常。
3.重构(改进) `setup` 中获得版本信息的方案,直接从 `package.__doc__` 中提取,而不再打开文件。
4.调整在PyPi上的开源库分类信息。
  • Loading branch information
2018-11-27 authored and Yongkang YK4 Zhu committed May 13, 2023
1 parent a4e4d64 commit b921f8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
18 changes: 12 additions & 6 deletions gqylpy_exception/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>>> import gqylpy_exception as ge
>>> raise ge.AnError(...)
@version: 2.0.2
@version: 2.0.3
@author: 竹永康 <gqylpy@outlook.com>
@source: https://github.com/gqylpy/gqylpy-exception
Expand Down Expand Up @@ -195,16 +195,22 @@ class _xe6_xad_x8c_xe7_x90_xaa_xe6_x80_xa1_xe7_x8e_xb2_xe8_x90_x8d_xe4_xba_x91:
ge = gcode.GqylpyException()

for gname in gpack:
if gname[0] == '_':
setattr(ge, gname, gpack[gname])
else:
if gname[0] != '_':
try:
gfunc = getattr(gcode, gname)
assert gfunc.__module__ in (gpath, __package__)
except (AttributeError, AssertionError):
continue
gfunc.__module__ = __package__
setattr(ge, gname, gfunc)
elif not hasattr(ge, gname):
setattr(ge.__class__, gname, gpack[gname])

ge.__module__ = __package__
sys.modules[__name__] = ge.GqylpyException = ge
setattr(ge, __package__, ge.__class__)

ge.__doc__ = __doc__
ge.__name__ = __package__
ge.__class__.__qualname__ = __package__
ge.__class__.__module__ = __package__

sys.modules[__name__] = ge
12 changes: 6 additions & 6 deletions gqylpy_exception/g exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ def __getattr__(self, ename: str) -> Type['GqylpyError']:
try:
eclass = self.__history__[ename]
except KeyError:
if hasattr(builtins, ename):
raise self.ExceptionClassIsBuiltinsError(
f'exception class "{ename}" is builtins.'
) from None
# Some special modules may attempt to call non-built-in magic
# method, such as `copy`, `pickle`. Compatible for this purpose.
if ename[:2] == ename[-2:] == '__' and \
ename[2] != '_' and ename[-3] != '_':
# Some special modules may attempt to call non-built-in magic
# method, such as `copy`, `pickle`. Compatible for this purpose.
raise AttributeError(
f'"{__package__}" has no attribute "{ename}".'
) from None
if hasattr(builtins, ename):
raise self.ExceptionClassIsBuiltinsError(
f'exception class "{ename}" is builtins.'
) from None
if ename[-5:] != 'Error':
warnings.warn(
f'strange exception class "{ename}", exception class name '
Expand Down
28 changes: 16 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import setuptools
import gqylpy_exception as g

with open(g.__file__, encoding='utf8') as f:
for line in f:
if line.startswith('@version: ', 4):
version = line.split()[-1]
break
author, email = f.readline().split(maxsplit=1)[-1].rstrip().split()
source = f.readline().split()[-1]
gdoc: list = g.__doc__.split('\n')

for index, line in enumerate(gdoc):
if line.startswith('@version: ', 4):
version = line.split()[-1]
break
_, author, email = gdoc[index + 1].split()
source = gdoc[index + 2].split()[-1]

setuptools.setup(
name=g.__name__,
Expand All @@ -23,19 +24,22 @@
packages=[g.__name__],
python_requires='>=3.6, <4',
classifiers=[
'Environment :: Web Environment',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: Chinese (Simplified)',
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Topic :: Text Processing :: Indexing',
'Topic :: Utilities',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Bug Tracking',
'Topic :: Software Development :: Widget Sets',
'Topic :: Artistic Software',
'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 :: 3.11',
'Programming Language :: Python :: 3.12'
]
)

0 comments on commit b921f8d

Please sign in to comment.