fix: remove unused code

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2023-08-06 15:45:34 +02:00
parent f31198321b
commit 7675db8169
No known key found for this signature in database
GPG Key ID: E13DFD4B47127951
3 changed files with 12 additions and 149 deletions

View File

@ -14,7 +14,6 @@ from meta.common.neoforge import (
INSTALLER_INFO_DIR,
FORGEWRAPPER_MAVEN,
)
from meta.common.forge import FORGE_COMPONENT
from meta.common.mojang import MINECRAFT_COMPONENT
from meta.model import (
MetaVersion,
@ -27,7 +26,6 @@ from meta.model import (
)
from meta.model.neoforge import (
NeoForgeVersion,
NeoForgeInstallerProfile,
NeoForgeInstallerProfileV2,
InstallerInfo,
DerivedNeoForgeIndex,
@ -45,105 +43,6 @@ def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# Construct a set of libraries out of a Minecraft version file, for filtering.
mc_version_cache = {}
def load_mc_version_filter(version: str):
if version in mc_version_cache:
return mc_version_cache[version]
v = MetaVersion.parse_file(
os.path.join(LAUNCHER_DIR, MINECRAFT_COMPONENT, f"{version}.json")
)
libs = set(map(attrgetter("name"), v.libraries))
mc_version_cache[version] = libs
return libs
"""
Match a library coordinate to a set of library coordinates.
* Block those that pass completely.
* For others, block those with lower versions than in the set.
"""
def should_ignore_artifact(libs: Collection[GradleSpecifier], match: GradleSpecifier):
for ver in libs:
if (
ver.group == match.group
and ver.artifact == match.artifact
and ver.classifier == match.classifier
):
if ver.version == match.version:
# Everything is matched perfectly - this one will be ignored
return True
elif LooseVersion(ver.version) > LooseVersion(match.version):
return True
else:
# Otherwise it did not match - new version is higher and this is an upgrade
return False
# No match found in the set - we need to keep this
return False
def version_from_profile(
profile: NeoForgeInstallerProfile, version: NeoForgeVersion
) -> MetaVersion:
v = MetaVersion(name="NeoForge", version=version.rawVersion, uid=NEOFORGE_COMPONENT)
mc_version = profile.install.minecraft
v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mc_version)]
v.main_class = profile.version_info.main_class
v.release_time = profile.version_info.time
args = profile.version_info.minecraft_arguments
tweakers = []
expression = re.compile(r"--tweakClass ([a-zA-Z0-9.]+)")
match = expression.search(args)
while match is not None:
tweakers.append(match.group(1))
args = args[: match.start()] + args[match.end() :]
match = expression.search(args)
if len(tweakers) > 0:
args = args.strip()
v.additional_tweakers = tweakers
# v.minecraftArguments = args
v.libraries = []
mc_filter = load_mc_version_filter(mc_version)
for forge_lib in profile.version_info.libraries:
if (
forge_lib.name.is_lwjgl()
or forge_lib.name.is_log4j()
or should_ignore_artifact(mc_filter, forge_lib.name)
):
continue
overridden_name = forge_lib.name
if overridden_name.group == "net.minecraftforge":
if overridden_name.artifact == "minecraftforge":
overridden_name.artifact = "forge"
overridden_name.version = "%s-%s" % (
mc_version,
overridden_name.version,
)
overridden_name.classifier = "universal"
elif overridden_name.artifact == "forge":
overridden_name.classifier = "universal"
overridden_lib = Library(name=overridden_name)
if forge_lib.url == "http://maven.minecraftforge.net/":
overridden_lib.url = "https://maven.minecraftforge.net/"
else:
overridden_lib.url = forge_lib.url
# if forge_lib.checksums and len(forge_lib.checksums) == 2:
# overridden_lib.mmcHint = "forge-pack-xz"
v.libraries.append(overridden_lib)
v.order = 5
return v
def version_from_build_system_installer(
installer: MojangVersion,
profile: NeoForgeInstallerProfileV2,
@ -284,22 +183,14 @@ def main():
)
eprint(installer_version_filepath)
if os.path.isfile(installer_version_filepath):
installer = MojangVersion.parse_file(installer_version_filepath)
profile = NeoForgeInstallerProfileV2.parse_file(profile_filepath)
v = version_from_build_system_installer(installer, profile, version)
else:
if version.uses_installer():
# If we do not have the Forge json, we ignore this version
if not os.path.isfile(profile_filepath):
eprint("Skipping %s with missing profile json" % key)
continue
profile = NeoForgeInstallerProfile.parse_file(profile_filepath)
v = version_from_profile(profile, version)
assert os.path.isfile(
installer_version_filepath
), f"version {installer_version_filepath} does not have installer version manifest"
installer = MojangVersion.parse_file(installer_version_filepath)
profile = NeoForgeInstallerProfileV2.parse_file(profile_filepath)
v = version_from_build_system_installer(installer, profile, version)
v.write(os.path.join(LAUNCHER_DIR, NEOFORGE_COMPONENT, f"{v.version}.json"))
v.version = "NEO-" + v.version
v.write(os.path.join(LAUNCHER_DIR, FORGE_COMPONENT, f"{v.version}.json"))
recommended_versions.sort()

View File

@ -132,12 +132,6 @@ class NeoForgeOptional(MetaBase):
maven: Optional[str]
class NeoForgeInstallerProfile(MetaBase):
install: NeoForgeInstallerProfileInstallSection
version_info: NeoForgeVersionFile = Field(alias="versionInfo")
optionals: Optional[List[NeoForgeOptional]]
class DataSpec(MetaBase):
client: Optional[str]
server: Optional[str]
@ -211,14 +205,10 @@ class NeoForgeVersion:
self.changelog_url = url
def name(self):
return "forge %d" % self.build
return "neoforge %d" % self.build
def uses_installer(self):
if self.installer_url is None:
return False
if self.mc_version == "1.5.2":
return False
return True
return self.installer_url is not None
def filename(self):
if self.uses_installer():

View File

@ -17,7 +17,7 @@ import urllib.parse
from pydantic import ValidationError
from meta.common import upstream_path, ensure_upstream_dir, static_path, default_session
from meta.common.forge import (
from meta.common.neoforge import (
JARS_DIR,
INSTALLER_INFO_DIR,
INSTALLER_MANIFEST_DIR,
@ -30,7 +30,6 @@ from meta.model.neoforge import (
NeoForgeMCVersionInfo,
DerivedNeoForgeIndex,
NeoForgeVersion,
NeoForgeInstallerProfile,
NeoForgeInstallerProfileV2,
InstallerInfo,
)
@ -98,19 +97,8 @@ def get_single_forge_files_manifest(longversion):
classifier = file["name"][find_nth(name, "-", 3) + 1 : len(file_name)]
# assert len(extensionObj.items()) == 1
index = 0
count = 0
file_obj = NeoForgeFile(classifier=classifier, extension=file_ext[1:])
if count == 0:
ret_dict[classifier] = file_obj
index += 1
count += 1
else:
print(
"%s: Multiple objects detected for classifier %s:"
% (longversion, classifier)
)
assert False
ret_dict[classifier] = file_obj
if not from_file:
Path(path_thing).parent.mkdir(parents=True, exist_ok=True)
@ -141,9 +129,7 @@ def main():
assert type(long_version) == str
mc_version = long_version.split("-")[0]
match = version_expression.match(long_version)
if not match:
pprint(long_version)
assert match
assert match, f"{long_version} doesn't match version regex"
assert match.group("mc") == mc_version
try:
files = get_single_forge_files_manifest(long_version)
@ -153,6 +139,7 @@ def main():
version = match.group("ver")
branch = match.group("branch")
# TODO: what *is* recommended?
is_recommended = False
entry = NeoForgeEntry(
@ -262,11 +249,6 @@ def main():
# Process: does it parse?
is_parsable = False
exception = None
try:
NeoForgeInstallerProfile.parse_raw(install_profile_data)
is_parsable = True
except ValidationError as err:
exception = err
try:
NeoForgeInstallerProfileV2.parse_raw(install_profile_data)
is_parsable = True