Skip to content

Drop dependency on semver package #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies = [
"packaging>=19.1",
"psutil",
"requests",
"semver>=2.7.9,<3.0.0",
"termcolor",
]

Expand Down
53 changes: 21 additions & 32 deletions src/ue4docker/infrastructure/BuildConfiguration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import platform
import random

import humanfriendly
from packaging.version import Version, InvalidVersion

from .DockerUtils import DockerUtils
from .PackageUtils import PackageUtils
from .WindowsUtils import WindowsUtils
import humanfriendly, json, os, platform, random
from pkg_resources import parse_version

# Import the `semver` package even when the conflicting `node-semver` package is present
semver = PackageUtils.importFile(
"semver", os.path.join(PackageUtils.getPackageLocation("semver"), "semver.py")
)

# The default Unreal Engine git repository
DEFAULT_GIT_REPO = "https://github.com/EpicGames/UnrealEngine.git"
Expand Down Expand Up @@ -55,17 +54,17 @@ class VisualStudio(object):

SupportedSince = {
# We do not support versions older than 4.20
VS2017: semver.VersionInfo(4.20),
VS2017: Version("4.20"),
# Unreal Engine 4.23.1 is the first that successfully builds with Visual Studio v16.3
# See https://github.com/EpicGames/UnrealEngine/commit/2510d4fd07a35ba5bff6ac2c7becaa6e8b7f11fa
#
# Unreal Engine 4.25 is the first that works with .NET SDK 4.7+
# See https://github.com/EpicGames/UnrealEngine/commit/5256eedbdef30212ab69fdf4c09e898098959683
VS2019: semver.VersionInfo(4, 25),
VS2022: semver.VersionInfo(5, 0, 0),
VS2019: Version("4.25"),
VS2022: Version("5.0.0"),
}

UnsupportedSince = {VS2017: semver.VersionInfo(5, 0)}
UnsupportedSince = {VS2017: Version("5.0")}


class ExcludedComponent(object):
Expand Down Expand Up @@ -406,16 +405,13 @@ def __init__(self, parser, argv, logger):
else:
# Validate the specified version string
try:
ue4Version = semver.parse(self.args.release)
if (
ue4Version["major"] not in [4, 5]
or ue4Version["prerelease"] != None
):
ue4Version = Version(self.args.release)
if ue4Version.major not in [4, 5] or ue4Version.pre != 0:
raise Exception()
self.release = semver.format_version(
ue4Version["major"], ue4Version["minor"], ue4Version["patch"]
self.release = (
f"{ue4Version.major}.{ue4Version.minor}.{ue4Version.micro}"
)
except:
except InvalidVersion:
raise RuntimeError(
'invalid Unreal Engine release number "{}", full semver format required (e.g. "4.20.0")'.format(
self.args.release
Expand Down Expand Up @@ -545,11 +541,7 @@ def __init__(self, parser, argv, logger):
if ExcludedComponent.Debug not in self.excludedComponents:
logger.warning("Warning: You didn't pass --exclude debug", False)
warn20GiB = True
if (
self.release
and not self.custom
and semver.VersionInfo.parse(self.release) >= semver.VersionInfo(5, 0)
):
if self.release and not self.custom and Version(self.release).major >= 5:
logger.warning("Warning: You're building Unreal Engine 5", False)
warn20GiB = True

Expand Down Expand Up @@ -592,10 +584,7 @@ def _generateWindowsConfig(self):
if self.release is not None and not self.custom:
# Check whether specified Unreal Engine release is compatible with specified Visual Studio
supportedSince = VisualStudio.SupportedSince.get(self.visualStudio, None)
if (
supportedSince is not None
and semver.VersionInfo.parse(self.release) < supportedSince
):
if supportedSince is not None and Version(self.release) < supportedSince:
raise RuntimeError(
"specified version of Unreal Engine is too old for Visual Studio {}".format(
self.visualStudio
Expand All @@ -607,7 +596,7 @@ def _generateWindowsConfig(self):
)
if (
unsupportedSince is not None
and semver.VersionInfo.parse(self.release) >= unsupportedSince
and Version(self.release) >= unsupportedSince
):
raise RuntimeError(
"Visual Studio {} is too old for specified version of Unreal Engine".format(
Expand Down Expand Up @@ -648,9 +637,9 @@ def _generateWindowsConfig(self):
else:
# If we are able to use process isolation mode then use it, otherwise use Hyper-V isolation mode
differentKernels = self.basetag != self.hostBasetag
dockerSupportsProcess = parse_version(
dockerSupportsProcess = Version(
DockerUtils.version()["Version"]
) >= parse_version("18.09.0")
) >= Version("18.09.0")
if not differentKernels and dockerSupportsProcess:
self.isolation = "process"
else:
Expand Down
17 changes: 8 additions & 9 deletions src/ue4docker/infrastructure/DarwinUtils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from packaging import version
import os, platform
import platform

from packaging.version import Version


class DarwinUtils(object):
@staticmethod
def minimumRequiredVersion():
def minimumRequiredVersion() -> Version:
"""
Returns the minimum required version of macOS, which is 10.10.3 Yosemite

(10.10.3 is the minimum required version for Docker for Mac, as per:
<https://store.docker.com/editions/community/docker-ce-desktop-mac>)
"""
return "10.10.3"
return Version("10.10.3")

@staticmethod
def systemString():
Expand All @@ -23,17 +24,15 @@ def systemString():
)

@staticmethod
def getMacOsVersion():
def getMacOsVersion() -> Version:
"""
Returns the version number for the macOS host system
"""
return platform.mac_ver()[0]
return Version(platform.mac_ver()[0])

@staticmethod
def isSupportedMacOsVersion():
"""
Verifies that the macOS host system meets our minimum version requirements
"""
return version.parse(DarwinUtils.getMacOsVersion()) >= version.parse(
DarwinUtils.minimumRequiredVersion()
)
return DarwinUtils.getMacOsVersion() >= DarwinUtils.minimumRequiredVersion()
7 changes: 4 additions & 3 deletions src/ue4docker/infrastructure/GlobalConfiguration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pkg_resources import parse_version
import os, requests
import os

import requests
from packaging.version import Version

# The default namespace for our tagged container images
DEFAULT_TAG_NAMESPACE = "adamrehn"
Expand All @@ -17,7 +18,7 @@ def getLatestVersion():
Queries PyPI to determine the latest available release of ue4-docker
"""
releases = [
parse_version(release)
Version(release)
for release in requests.get("https://pypi.org/pypi/ue4-docker/json").json()[
"releases"
]
Expand Down
20 changes: 0 additions & 20 deletions src/ue4docker/infrastructure/PackageUtils.py

This file was deleted.

9 changes: 4 additions & 5 deletions src/ue4docker/infrastructure/WindowsUtils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .DockerUtils import DockerUtils
from pkg_resources import parse_version
from packaging.version import Version
import platform, sys
from typing import Optional

Expand Down Expand Up @@ -94,11 +94,10 @@ def isBlacklistedWindowsHost() -> bool:
Determines if host Windows version is one with bugs that make it unsuitable for use
(defaults to checking the host OS release if one is not specified)
"""
dockerVersion = parse_version(DockerUtils.version()["Version"])
dockerVersion = Version(DockerUtils.version()["Version"])
build = WindowsUtils.getWindowsBuild()
return (
build in WindowsUtils._blacklistedHosts
and dockerVersion < parse_version("19.03.6")
return build in WindowsUtils._blacklistedHosts and dockerVersion < Version(
"19.03.6"
)

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion src/ue4docker/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .ImageCleaner import ImageCleaner
from .Logger import Logger
from .NetworkUtils import NetworkUtils
from .PackageUtils import PackageUtils
from .PrettyPrinting import PrettyPrinting
from .ResourceMonitor import ResourceMonitor
from .SubprocessUtils import SubprocessUtils
Expand Down