mods and MCDR!
This commit is contained in:
parent
2715755316
commit
b40d6fb30b
@ -11,7 +11,7 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from libs.semver.semver import VersionInfo
|
||||
from libs.semver import VersionInfo
|
||||
|
||||
game_version = '0.6.2'
|
||||
__version__ = game_version
|
||||
|
@ -13,7 +13,8 @@ from enum import EnumMeta
|
||||
from threading import Lock
|
||||
from typing import Union, TypeVar, List, Dict, Type, get_type_hints, Any
|
||||
|
||||
from semver import VersionInfo
|
||||
from semver import VersionInfo as semver_VersionInfo
|
||||
from libs.semver import VersionInfo as lib_semver_VersionInfo
|
||||
|
||||
"""
|
||||
This part of code come from MCDReforged(https://github.com/Fallen-Breath/MCDReforged)
|
||||
@ -46,13 +47,13 @@ def _get_args(cls: Type) -> tuple:
|
||||
return getattr(cls, '__args__', ())
|
||||
|
||||
|
||||
_BASIC_CLASSES = (type(None), bool, int, float, str, list, dict, VersionInfo)
|
||||
_BASIC_CLASSES = (type(None), bool, int, float, str, list, dict, lib_semver_VersionInfo, semver_VersionInfo)
|
||||
|
||||
|
||||
def serialize(obj) -> _BASIC_CLASSES:
|
||||
if type(obj) in (type(None), int, float, str, bool):
|
||||
return obj
|
||||
elif isinstance(obj, VersionInfo):
|
||||
elif isinstance(obj, lib_semver_VersionInfo) or isinstance(obj, semver_VersionInfo):
|
||||
return obj
|
||||
elif isinstance(obj, list) or isinstance(obj, tuple):
|
||||
return list(map(serialize, obj))
|
||||
@ -67,7 +68,7 @@ def serialize(obj) -> _BASIC_CLASSES:
|
||||
if attr_name.startswith('_'):
|
||||
attr_dict.pop(attr_name)
|
||||
except:
|
||||
raise TypeError('Unsupported input type {}'.format(type(obj))) from None
|
||||
raise TypeError(f'Unsupported input type {type(obj)}') from None
|
||||
else:
|
||||
return serialize(attr_dict)
|
||||
|
||||
|
@ -15,7 +15,7 @@ gitee: @shenjackyuanjie
|
||||
from typing import Tuple
|
||||
|
||||
# from libs
|
||||
from libs.semver.semver import VersionInfo
|
||||
from libs.semver import VersionInfo
|
||||
|
||||
# from DR
|
||||
from Difficult_Rocket import semver_game_version
|
||||
@ -54,8 +54,7 @@ class MODInfo(Serializable):
|
||||
write_loader_version: VersionInfo # mod编写的加载器版本
|
||||
compatible_version: Tuple[VersionInfo, VersionInfo] = (semver_game_version, semver_game_version) # mod兼容版本
|
||||
# 第一个是最低兼容版本,第二个是最高兼容版本
|
||||
# 例如: ("1.0.0", "1.1.0")
|
||||
# 例如: ("1.0.0", "1.1.0")
|
||||
# 例如: ("1.0.0", "1.1.0") 表示从1.0.0版本开始兼容,到1.1.0版本结束兼容
|
||||
|
||||
|
||||
MOD_info = MODInfo(
|
||||
@ -66,6 +65,8 @@ MOD_info = MODInfo(
|
||||
write_loader_version=semver_loader_version
|
||||
)
|
||||
|
||||
print(MOD_info.serialize())
|
||||
|
||||
"""
|
||||
一些重置用函数
|
||||
"""
|
||||
|
@ -71,7 +71,7 @@ EXCEPT_MSG = """
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
STR_OR_UNICODE = unicode if PY2 else str # For paste(): Python 3 uses str, Python 2 uses unicode.
|
||||
STR_OR_UNICODE = str
|
||||
|
||||
ENCODING = 'utf-8'
|
||||
|
||||
@ -104,7 +104,7 @@ class PyperclipTimeoutException(PyperclipException):
|
||||
|
||||
def _stringifyText(text):
|
||||
if PY2:
|
||||
acceptedTypes = (unicode, str, int, float, bool)
|
||||
acceptedTypes = (str, int, float, bool)
|
||||
else:
|
||||
acceptedTypes = (str, int, float, bool)
|
||||
if not isinstance(text, acceptedTypes):
|
||||
|
@ -9,11 +9,9 @@ import re
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
|
||||
__version__ = "2.13.0"
|
||||
__author__ = "Kostiantyn Rybnikov"
|
||||
__author_email__ = "k-bx@k-bx.com"
|
||||
@ -56,22 +54,21 @@ __all__ = (
|
||||
#: Contains the implemented semver.org version of the spec
|
||||
SEMVER_SPEC_VERSION = "2.0.0"
|
||||
|
||||
|
||||
if not hasattr(__builtins__, "cmp"):
|
||||
|
||||
def cmp(a, b):
|
||||
"""Return negative if a<b, zero if a==b, positive if a>b."""
|
||||
return (a > b) - (a < b)
|
||||
|
||||
|
||||
if PY3: # pragma: no cover
|
||||
string_types = str, bytes
|
||||
text_type = str
|
||||
binary_type = bytes
|
||||
|
||||
|
||||
def b(s):
|
||||
return s.encode("latin-1")
|
||||
|
||||
|
||||
def u(s):
|
||||
return s
|
||||
|
||||
@ -81,9 +78,11 @@ else: # pragma: no cover
|
||||
text_type = unicode
|
||||
binary_type = str
|
||||
|
||||
|
||||
def b(s):
|
||||
return s
|
||||
|
||||
|
||||
# Workaround for standalone backslash
|
||||
def u(s):
|
||||
return unicode(s.replace(r"\\", r"\\\\"), "unicode_escape")
|
||||
@ -147,10 +146,10 @@ def deprecated(func=None, replace=None, version=None, category=DeprecationWarnin
|
||||
|
||||
msg = " ".join(msg)
|
||||
warnings.warn_explicit(
|
||||
msg.format(m=func.__module__, f=f, r=r, v=version),
|
||||
category=category,
|
||||
filename=inspect.getfile(frame.f_code),
|
||||
lineno=frame.f_lineno,
|
||||
msg.format(m=func.__module__, f=f, r=r, v=version),
|
||||
category=category,
|
||||
filename=inspect.getfile(frame.f_code),
|
||||
lineno=frame.f_lineno,
|
||||
)
|
||||
# As recommended in the Python documentation
|
||||
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack
|
||||
@ -198,7 +197,7 @@ def comparator(operator):
|
||||
comparable_types = (VersionInfo, dict, tuple, list, text_type, binary_type)
|
||||
if not isinstance(other, comparable_types):
|
||||
raise TypeError(
|
||||
"other type %r must be in %r" % (type(other), comparable_types)
|
||||
"other type %r must be in %r" % (type(other), comparable_types)
|
||||
)
|
||||
return operator(self, other)
|
||||
|
||||
@ -222,24 +221,24 @@ class VersionInfo(object):
|
||||
_LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+")
|
||||
#: Regex for a semver version
|
||||
_REGEX = re.compile(
|
||||
r"""
|
||||
^
|
||||
(?P<major>0|[1-9]\d*)
|
||||
\.
|
||||
(?P<minor>0|[1-9]\d*)
|
||||
\.
|
||||
(?P<patch>0|[1-9]\d*)
|
||||
(?:-(?P<prerelease>
|
||||
(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)
|
||||
(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*
|
||||
))?
|
||||
(?:\+(?P<build>
|
||||
[0-9a-zA-Z-]+
|
||||
(?:\.[0-9a-zA-Z-]+)*
|
||||
))?
|
||||
$
|
||||
""",
|
||||
re.VERBOSE,
|
||||
r"""
|
||||
^
|
||||
(?P<major>0|[1-9]\d*)
|
||||
\.
|
||||
(?P<minor>0|[1-9]\d*)
|
||||
\.
|
||||
(?P<patch>0|[1-9]\d*)
|
||||
(?:-(?P<prerelease>
|
||||
(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)
|
||||
(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*
|
||||
))?
|
||||
(?:\+(?P<build>
|
||||
[0-9a-zA-Z-]+
|
||||
(?:\.[0-9a-zA-Z-]+)*
|
||||
))?
|
||||
$
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
def __init__(self, major, minor=0, patch=0, prerelease=None, build=None):
|
||||
@ -255,7 +254,7 @@ class VersionInfo(object):
|
||||
version_parts[name] = value
|
||||
if value < 0:
|
||||
raise ValueError(
|
||||
"{!r} is negative. A version can only be positive.".format(name)
|
||||
"{!r} is negative. A version can only be positive.".format(name)
|
||||
)
|
||||
|
||||
self._major = version_parts["major"]
|
||||
@ -342,13 +341,13 @@ class VersionInfo(object):
|
||||
('prerelease', None), ('build', None)])
|
||||
"""
|
||||
return collections.OrderedDict(
|
||||
(
|
||||
("major", self.major),
|
||||
("minor", self.minor),
|
||||
("patch", self.patch),
|
||||
("prerelease", self.prerelease),
|
||||
("build", self.build),
|
||||
)
|
||||
(
|
||||
("major", self.major),
|
||||
("minor", self.minor),
|
||||
("patch", self.patch),
|
||||
("prerelease", self.prerelease),
|
||||
("build", self.build),
|
||||
)
|
||||
)
|
||||
|
||||
# For compatibility reasons:
|
||||
@ -497,9 +496,9 @@ build='build.10')
|
||||
other = cls(*other)
|
||||
elif not isinstance(other, cls):
|
||||
raise TypeError(
|
||||
"Expected str or {} instance, but got {}".format(
|
||||
cls.__name__, type(other)
|
||||
)
|
||||
"Expected str or {} instance, but got {}".format(
|
||||
cls.__name__, type(other)
|
||||
)
|
||||
)
|
||||
|
||||
v1 = self.to_tuple()[:3]
|
||||
@ -549,15 +548,15 @@ build='build.10')
|
||||
}
|
||||
if part not in validparts:
|
||||
raise ValueError(
|
||||
"Invalid part. Expected one of {validparts}, but got {part!r}".format(
|
||||
validparts=validparts, part=part
|
||||
)
|
||||
"Invalid part. Expected one of {validparts}, but got {part!r}".format(
|
||||
validparts=validparts, part=part
|
||||
)
|
||||
)
|
||||
version = self
|
||||
if (version.prerelease or version.build) and (
|
||||
part == "patch"
|
||||
or (part == "minor" and version.patch == 0)
|
||||
or (part == "major" and version.minor == version.patch == 0)
|
||||
part == "patch"
|
||||
or (part == "minor" and version.patch == 0)
|
||||
or (part == "major" and version.minor == version.patch == 0)
|
||||
):
|
||||
return version.replace(prerelease=None, build=None)
|
||||
|
||||
@ -613,9 +612,9 @@ build='build.10')
|
||||
index = slice(index, index + 1)
|
||||
|
||||
if (
|
||||
isinstance(index, slice)
|
||||
and (index.start is not None and index.start < 0)
|
||||
or (index.stop is not None and index.stop < 0)
|
||||
isinstance(index, slice)
|
||||
and (index.start is not None and index.start < 0)
|
||||
or (index.stop is not None and index.stop < 0)
|
||||
):
|
||||
raise IndexError("Version index cannot be negative")
|
||||
|
||||
@ -683,15 +682,15 @@ build='build.10')
|
||||
match_version = match_expr[1:]
|
||||
else:
|
||||
raise ValueError(
|
||||
"match_expr parameter should be in format <op><ver>, "
|
||||
"where <op> is one of "
|
||||
"['<', '>', '==', '<=', '>=', '!=']. "
|
||||
"You provided: %r" % match_expr
|
||||
"match_expr parameter should be in format <op><ver>, "
|
||||
"where <op> is one of "
|
||||
"['<', '>', '==', '<=', '>=', '!=']. "
|
||||
"You provided: %r" % match_expr
|
||||
)
|
||||
|
||||
possibilities_dict = {
|
||||
">": (1,),
|
||||
"<": (-1,),
|
||||
">": (1,),
|
||||
"<": (-1,),
|
||||
"==": (0,),
|
||||
"!=": (-1, 1),
|
||||
">=": (0, 1),
|
||||
@ -1101,11 +1100,11 @@ def cmd_bump(args):
|
||||
:return: the new, bumped version
|
||||
"""
|
||||
maptable = {
|
||||
"major": "bump_major",
|
||||
"minor": "bump_minor",
|
||||
"patch": "bump_patch",
|
||||
"major": "bump_major",
|
||||
"minor": "bump_minor",
|
||||
"patch": "bump_patch",
|
||||
"prerelease": "bump_prerelease",
|
||||
"build": "bump_build",
|
||||
"build": "bump_build",
|
||||
}
|
||||
if args.bump is None:
|
||||
# When bump is called without arguments,
|
||||
@ -1167,7 +1166,7 @@ def createparser():
|
||||
parser = argparse.ArgumentParser(prog=__package__, description=__doc__)
|
||||
|
||||
parser.add_argument(
|
||||
"--version", action="version", version="%(prog)s " + __version__
|
||||
"--version", action="version", version="%(prog)s " + __version__
|
||||
)
|
||||
|
||||
s = parser.add_subparsers()
|
||||
@ -1184,29 +1183,29 @@ def createparser():
|
||||
|
||||
# Create subparsers for the bump subparser:
|
||||
for p in (
|
||||
sb.add_parser("major", help="Bump the major part of the version"),
|
||||
sb.add_parser("minor", help="Bump the minor part of the version"),
|
||||
sb.add_parser("patch", help="Bump the patch part of the version"),
|
||||
sb.add_parser("prerelease", help="Bump the prerelease part of the version"),
|
||||
sb.add_parser("build", help="Bump the build part of the version"),
|
||||
sb.add_parser("major", help="Bump the major part of the version"),
|
||||
sb.add_parser("minor", help="Bump the minor part of the version"),
|
||||
sb.add_parser("patch", help="Bump the patch part of the version"),
|
||||
sb.add_parser("prerelease", help="Bump the prerelease part of the version"),
|
||||
sb.add_parser("build", help="Bump the build part of the version"),
|
||||
):
|
||||
p.add_argument("version", help="Version to raise")
|
||||
|
||||
# Create the check subcommand
|
||||
parser_check = s.add_parser(
|
||||
"check", help="Checks if a string is a valid semver version"
|
||||
"check", help="Checks if a string is a valid semver version"
|
||||
)
|
||||
parser_check.set_defaults(func=cmd_check)
|
||||
parser_check.add_argument("version", help="Version to check")
|
||||
|
||||
# Create the nextver subcommand
|
||||
parser_nextver = s.add_parser(
|
||||
"nextver", help="Determines the next version, taking prereleases into account."
|
||||
"nextver", help="Determines the next version, taking prereleases into account."
|
||||
)
|
||||
parser_nextver.set_defaults(func=cmd_nextver)
|
||||
parser_nextver.add_argument("version", help="Version to raise")
|
||||
parser_nextver.add_argument(
|
||||
"part", help="One of 'major', 'minor', 'patch', or 'prerelease'"
|
||||
"part", help="One of 'major', 'minor', 'patch', or 'prerelease'"
|
||||
)
|
||||
return parser
|
||||
|
Loading…
Reference in New Issue
Block a user