mods and MCDR!

This commit is contained in:
shenjackyuanjie 2022-03-05 23:01:20 +08:00
parent 2715755316
commit b40d6fb30b
5 changed files with 78 additions and 77 deletions

View File

@ -11,7 +11,7 @@ github: @shenjackyuanjie
gitee: @shenjackyuanjie gitee: @shenjackyuanjie
""" """
from libs.semver.semver import VersionInfo from libs.semver import VersionInfo
game_version = '0.6.2' game_version = '0.6.2'
__version__ = game_version __version__ = game_version

View File

@ -13,7 +13,8 @@ from enum import EnumMeta
from threading import Lock from threading import Lock
from typing import Union, TypeVar, List, Dict, Type, get_type_hints, Any 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) 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__', ()) 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: def serialize(obj) -> _BASIC_CLASSES:
if type(obj) in (type(None), int, float, str, bool): if type(obj) in (type(None), int, float, str, bool):
return obj return obj
elif isinstance(obj, VersionInfo): elif isinstance(obj, lib_semver_VersionInfo) or isinstance(obj, semver_VersionInfo):
return obj return obj
elif isinstance(obj, list) or isinstance(obj, tuple): elif isinstance(obj, list) or isinstance(obj, tuple):
return list(map(serialize, obj)) return list(map(serialize, obj))
@ -67,7 +68,7 @@ def serialize(obj) -> _BASIC_CLASSES:
if attr_name.startswith('_'): if attr_name.startswith('_'):
attr_dict.pop(attr_name) attr_dict.pop(attr_name)
except: except:
raise TypeError('Unsupported input type {}'.format(type(obj))) from None raise TypeError(f'Unsupported input type {type(obj)}') from None
else: else:
return serialize(attr_dict) return serialize(attr_dict)

View File

@ -15,7 +15,7 @@ gitee: @shenjackyuanjie
from typing import Tuple from typing import Tuple
# from libs # from libs
from libs.semver.semver import VersionInfo from libs.semver import VersionInfo
# from DR # from DR
from Difficult_Rocket import semver_game_version from Difficult_Rocket import semver_game_version
@ -54,8 +54,7 @@ class MODInfo(Serializable):
write_loader_version: VersionInfo # mod编写的加载器版本 write_loader_version: VersionInfo # mod编写的加载器版本
compatible_version: Tuple[VersionInfo, VersionInfo] = (semver_game_version, semver_game_version) # 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( MOD_info = MODInfo(
@ -66,6 +65,8 @@ MOD_info = MODInfo(
write_loader_version=semver_loader_version write_loader_version=semver_loader_version
) )
print(MOD_info.serialize())
""" """
一些重置用函数 一些重置用函数
""" """

View File

@ -71,7 +71,7 @@ EXCEPT_MSG = """
PY2 = sys.version_info[0] == 2 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' ENCODING = 'utf-8'
@ -104,7 +104,7 @@ class PyperclipTimeoutException(PyperclipException):
def _stringifyText(text): def _stringifyText(text):
if PY2: if PY2:
acceptedTypes = (unicode, str, int, float, bool) acceptedTypes = (str, int, float, bool)
else: else:
acceptedTypes = (str, int, float, bool) acceptedTypes = (str, int, float, bool)
if not isinstance(text, acceptedTypes): if not isinstance(text, acceptedTypes):

View File

@ -9,11 +9,9 @@ import re
import sys import sys
import warnings import warnings
PY2 = sys.version_info[0] == 2 PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3 PY3 = sys.version_info[0] == 3
__version__ = "2.13.0" __version__ = "2.13.0"
__author__ = "Kostiantyn Rybnikov" __author__ = "Kostiantyn Rybnikov"
__author_email__ = "k-bx@k-bx.com" __author_email__ = "k-bx@k-bx.com"
@ -56,22 +54,21 @@ __all__ = (
#: Contains the implemented semver.org version of the spec #: Contains the implemented semver.org version of the spec
SEMVER_SPEC_VERSION = "2.0.0" SEMVER_SPEC_VERSION = "2.0.0"
if not hasattr(__builtins__, "cmp"): if not hasattr(__builtins__, "cmp"):
def cmp(a, b): def cmp(a, b):
"""Return negative if a<b, zero if a==b, positive if a>b.""" """Return negative if a<b, zero if a==b, positive if a>b."""
return (a > b) - (a < b) return (a > b) - (a < b)
if PY3: # pragma: no cover if PY3: # pragma: no cover
string_types = str, bytes string_types = str, bytes
text_type = str text_type = str
binary_type = bytes binary_type = bytes
def b(s): def b(s):
return s.encode("latin-1") return s.encode("latin-1")
def u(s): def u(s):
return s return s
@ -81,9 +78,11 @@ else: # pragma: no cover
text_type = unicode text_type = unicode
binary_type = str binary_type = str
def b(s): def b(s):
return s return s
# Workaround for standalone backslash # Workaround for standalone backslash
def u(s): def u(s):
return unicode(s.replace(r"\\", r"\\\\"), "unicode_escape") 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) msg = " ".join(msg)
warnings.warn_explicit( warnings.warn_explicit(
msg.format(m=func.__module__, f=f, r=r, v=version), msg.format(m=func.__module__, f=f, r=r, v=version),
category=category, category=category,
filename=inspect.getfile(frame.f_code), filename=inspect.getfile(frame.f_code),
lineno=frame.f_lineno, lineno=frame.f_lineno,
) )
# As recommended in the Python documentation # As recommended in the Python documentation
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack # 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) comparable_types = (VersionInfo, dict, tuple, list, text_type, binary_type)
if not isinstance(other, comparable_types): if not isinstance(other, comparable_types):
raise TypeError( 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) return operator(self, other)
@ -222,24 +221,24 @@ class VersionInfo(object):
_LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+") _LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+")
#: Regex for a semver version #: Regex for a semver version
_REGEX = re.compile( _REGEX = re.compile(
r""" r"""
^ ^
(?P<major>0|[1-9]\d*) (?P<major>0|[1-9]\d*)
\. \.
(?P<minor>0|[1-9]\d*) (?P<minor>0|[1-9]\d*)
\. \.
(?P<patch>0|[1-9]\d*) (?P<patch>0|[1-9]\d*)
(?:-(?P<prerelease> (?:-(?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-]*)
(?:\.(?: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> (?:\+(?P<build>
[0-9a-zA-Z-]+ [0-9a-zA-Z-]+
(?:\.[0-9a-zA-Z-]+)* (?:\.[0-9a-zA-Z-]+)*
))? ))?
$ $
""", """,
re.VERBOSE, re.VERBOSE,
) )
def __init__(self, major, minor=0, patch=0, prerelease=None, build=None): def __init__(self, major, minor=0, patch=0, prerelease=None, build=None):
@ -255,7 +254,7 @@ class VersionInfo(object):
version_parts[name] = value version_parts[name] = value
if value < 0: if value < 0:
raise ValueError( 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"] self._major = version_parts["major"]
@ -342,13 +341,13 @@ class VersionInfo(object):
('prerelease', None), ('build', None)]) ('prerelease', None), ('build', None)])
""" """
return collections.OrderedDict( return collections.OrderedDict(
( (
("major", self.major), ("major", self.major),
("minor", self.minor), ("minor", self.minor),
("patch", self.patch), ("patch", self.patch),
("prerelease", self.prerelease), ("prerelease", self.prerelease),
("build", self.build), ("build", self.build),
) )
) )
# For compatibility reasons: # For compatibility reasons:
@ -497,9 +496,9 @@ build='build.10')
other = cls(*other) other = cls(*other)
elif not isinstance(other, cls): elif not isinstance(other, cls):
raise TypeError( raise TypeError(
"Expected str or {} instance, but got {}".format( "Expected str or {} instance, but got {}".format(
cls.__name__, type(other) cls.__name__, type(other)
) )
) )
v1 = self.to_tuple()[:3] v1 = self.to_tuple()[:3]
@ -549,15 +548,15 @@ build='build.10')
} }
if part not in validparts: if part not in validparts:
raise ValueError( raise ValueError(
"Invalid part. Expected one of {validparts}, but got {part!r}".format( "Invalid part. Expected one of {validparts}, but got {part!r}".format(
validparts=validparts, part=part validparts=validparts, part=part
) )
) )
version = self version = self
if (version.prerelease or version.build) and ( if (version.prerelease or version.build) and (
part == "patch" part == "patch"
or (part == "minor" and version.patch == 0) or (part == "minor" and version.patch == 0)
or (part == "major" and version.minor == version.patch == 0) or (part == "major" and version.minor == version.patch == 0)
): ):
return version.replace(prerelease=None, build=None) return version.replace(prerelease=None, build=None)
@ -613,9 +612,9 @@ build='build.10')
index = slice(index, index + 1) index = slice(index, index + 1)
if ( if (
isinstance(index, slice) isinstance(index, slice)
and (index.start is not None and index.start < 0) and (index.start is not None and index.start < 0)
or (index.stop is not None and index.stop < 0) or (index.stop is not None and index.stop < 0)
): ):
raise IndexError("Version index cannot be negative") raise IndexError("Version index cannot be negative")
@ -683,15 +682,15 @@ build='build.10')
match_version = match_expr[1:] match_version = match_expr[1:]
else: else:
raise ValueError( raise ValueError(
"match_expr parameter should be in format <op><ver>, " "match_expr parameter should be in format <op><ver>, "
"where <op> is one of " "where <op> is one of "
"['<', '>', '==', '<=', '>=', '!=']. " "['<', '>', '==', '<=', '>=', '!=']. "
"You provided: %r" % match_expr "You provided: %r" % match_expr
) )
possibilities_dict = { possibilities_dict = {
">": (1,), ">": (1,),
"<": (-1,), "<": (-1,),
"==": (0,), "==": (0,),
"!=": (-1, 1), "!=": (-1, 1),
">=": (0, 1), ">=": (0, 1),
@ -1101,11 +1100,11 @@ def cmd_bump(args):
:return: the new, bumped version :return: the new, bumped version
""" """
maptable = { maptable = {
"major": "bump_major", "major": "bump_major",
"minor": "bump_minor", "minor": "bump_minor",
"patch": "bump_patch", "patch": "bump_patch",
"prerelease": "bump_prerelease", "prerelease": "bump_prerelease",
"build": "bump_build", "build": "bump_build",
} }
if args.bump is None: if args.bump is None:
# When bump is called without arguments, # When bump is called without arguments,
@ -1167,7 +1166,7 @@ def createparser():
parser = argparse.ArgumentParser(prog=__package__, description=__doc__) parser = argparse.ArgumentParser(prog=__package__, description=__doc__)
parser.add_argument( parser.add_argument(
"--version", action="version", version="%(prog)s " + __version__ "--version", action="version", version="%(prog)s " + __version__
) )
s = parser.add_subparsers() s = parser.add_subparsers()
@ -1184,29 +1183,29 @@ def createparser():
# Create subparsers for the bump subparser: # Create subparsers for the bump subparser:
for p in ( for p in (
sb.add_parser("major", help="Bump the major 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("minor", help="Bump the minor part of the version"),
sb.add_parser("patch", help="Bump the patch 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("prerelease", help="Bump the prerelease part of the version"),
sb.add_parser("build", help="Bump the build part of the version"), sb.add_parser("build", help="Bump the build part of the version"),
): ):
p.add_argument("version", help="Version to raise") p.add_argument("version", help="Version to raise")
# Create the check subcommand # Create the check subcommand
parser_check = s.add_parser( 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.set_defaults(func=cmd_check)
parser_check.add_argument("version", help="Version to check") parser_check.add_argument("version", help="Version to check")
# Create the nextver subcommand # Create the nextver subcommand
parser_nextver = s.add_parser( 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.set_defaults(func=cmd_nextver)
parser_nextver.add_argument("version", help="Version to raise") parser_nextver.add_argument("version", help="Version to raise")
parser_nextver.add_argument( parser_nextver.add_argument(
"part", help="One of 'major', 'minor', 'patch', or 'prerelease'" "part", help="One of 'major', 'minor', 'patch', or 'prerelease'"
) )
return parser return parser