Commit d64ea749 authored by Tristan Maat's avatar Tristan Maat Committed by Tristan Van Berkom
Browse files

Make the platform object a singleton

parent de357931
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -146,7 +146,8 @@ class Pipeline():
            load_ticker(None)
            load_ticker(None)


        # Load selected platform
        # Load selected platform
        self.platform = Platform.get_platform(context, project)
        Platform._create_instance(context, project)
        self.platform = Platform.get_platform()
        self.artifacts = self.platform.artifactcache
        self.artifacts = self.platform.artifactcache


        # Create the factories after resolving the project
        # Create the factories after resolving the project
+9 −3
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ from .. import PlatformError, ProgramNotFoundError, ImplError




class Platform():
class Platform():
    _instance = None


    # Platform()
    # Platform()
    #
    #
@@ -42,8 +43,7 @@ class Platform():
        self.project = project
        self.project = project


    @classmethod
    @classmethod
    def get_platform(cls, *args, **kwargs):
    def _create_instance(cls, *args, **kwargs):

        if sys.platform.startswith('linux'):
        if sys.platform.startswith('linux'):
            backend = 'linux'
            backend = 'linux'
        else:
        else:
@@ -62,7 +62,13 @@ class Platform():
        else:
        else:
            raise PlatformError("No such platform: '{}'".format(backend))
            raise PlatformError("No such platform: '{}'".format(backend))


        return PlatformImpl(*args, **kwargs)
        cls._instance = PlatformImpl(*args, **kwargs)

    @classmethod
    def get_platform(cls, *args, **kwargs):
        if not cls._instance:
            raise PlatformError("Platform needs to be initialized first")
        return cls._instance


    ##################################################################
    ##################################################################
    #                       Platform properties                      #
    #                       Platform properties                      #