Example #1
0
    def testMultiple(self):

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        # From 1
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        # From 2
        assertIsEqual(config.getString('thing1'), 'Foo')

        # Second one should override
        assertIsEqual(config.getString('foo2'), 'ipsum')

        assertIsEqual(config.getString('nest1', 'firstName'), 'Dorothy')

        # Test concatenating lists together
        assertIsEqual(config.getList('list1'), ['lorem', 'ipsum', 'asdf', 'joe', 'frank'])

        # Test concatenating dictionaries together
        assertIsEqual(config.getDictionary('dict1'), {'joe': 5, 'mary': 15, 'kate': 5, 'jim': 10})

        assertIsEqual(config.tryGetDictionary(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetDictionary({ 5: 1 }, 'asdfasdfasdf'), { 5: 1 })

        assertIsEqual(config.tryGetList(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetList([1, 2], 'asdfasdfasdf'), [1, 2])

        assertIsEqual(config.tryGetBool(False, 'zxvzasdfasdfasdf'), False)
        assertIsEqual(config.tryGetBool(True, 'zxvzasdfasdfasdf'), True)

        assertIsEqual(config.tryGetString('asdf', 'zxvzasdfasdfasdf'), 'asdf')

        assertIsEqual(config.tryGetInt(5, 'zxvzasdfasdfasdf'), 5)
Example #2
0
    def loadProjectConfig(self, name):
        schemaPath = self._varMgr.expandPath('[UnityProjectsDir]/{0}/{1}'.format(name, ProjectConfigFileName))
        schemaPathUser = self._varMgr.expandPath('[UnityProjectsDir]/{0}/{1}'.format(name, ProjectUserConfigFileName))
        schemaPathGlobal = self._varMgr.expandPath('[UnityProjectsDir]/{0}'.format(ProjectConfigFileName))
        schemaPathUserGlobal = self._varMgr.expandPath('[UnityProjectsDir]/{0}'.format(ProjectUserConfigFileName))

        self._log.debug('Loading schema at path "{0}"'.format(schemaPath))
        yamlConfig = Config(loadYamlFilesThatExist(schemaPath, schemaPathUser, schemaPathGlobal, schemaPathUserGlobal))

        config = ProjectConfig()

        config.pluginsFolder = yamlConfig.tryGetList([], 'PluginsFolder')
        config.assetsFolder = yamlConfig.tryGetList([], 'AssetsFolder')
        config.solutionProjects = yamlConfig.tryGetList([], 'SolutionProjects')
        config.targetPlatforms = yamlConfig.tryGetList([Platforms.Windows], 'TargetPlatforms')
        config.solutionFolders = yamlConfig.tryGetOrderedDictionary(OrderedDict(), 'SolutionFolders')
        config.packageFolders = yamlConfig.getList('PackageFolders')
        config.projectSettingsPath = yamlConfig.getString('ProjectSettingsPath')

        # Remove duplicates
        config.assetsFolder = list(set(config.assetsFolder))
        config.pluginsFolder = list(set(config.pluginsFolder))

        for packageName in config.pluginsFolder:
            assertThat(not packageName in config.assetsFolder, "Found package '{0}' in both scripts and plugins.  Must be in only one or the other".format(packageName))

        return config
Example #3
0
    def loadProjectConfig(self, name):
        schemaPath = self._varMgr.expandPath('[UnityProjectsDir]/{0}/{1}'.format(name, ProjectConfigFileName))
        schemaPathUser = self._varMgr.expandPath('[UnityProjectsDir]/{0}/{1}'.format(name, ProjectUserConfigFileName))
        schemaPathGlobal = self._varMgr.expandPath('[UnityProjectsDir]/{0}'.format(ProjectConfigFileName))
        schemaPathUserGlobal = self._varMgr.expandPath('[UnityProjectsDir]/{0}'.format(ProjectUserConfigFileName))

        self._log.debug('Loading schema at path "{0}"'.format(schemaPath))
        yamlConfig = Config(loadYamlFilesThatExist(schemaPath, schemaPathUser, schemaPathGlobal, schemaPathUserGlobal))

        config = ProjectConfig()

        config.pluginsFolder = yamlConfig.tryGetList([], 'PluginsFolder')
        config.assetsFolder = yamlConfig.tryGetList([], 'AssetsFolder')
        config.solutionProjects = yamlConfig.tryGetList([], 'SolutionProjects')
        config.targetPlatforms = yamlConfig.tryGetList([Platforms.Windows], 'TargetPlatforms')
        config.solutionFolders = yamlConfig.tryGetOrderedDictionary(OrderedDict(), 'SolutionFolders')
        config.packageFolders = yamlConfig.getList('PackageFolders')
        config.projectSettingsPath = yamlConfig.getString('ProjectSettingsPath')

        # Remove duplicates
        config.assetsFolder = list(set(config.assetsFolder))
        config.pluginsFolder = list(set(config.pluginsFolder))

        for packageName in config.pluginsFolder:
            assertThat(not packageName in config.assetsFolder, "Found package '{0}' in both scripts and plugins.  Must be in only one or the other".format(packageName))

        return config
Example #4
0
    def testSpecialChars(self):
        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        assertIsEqual(config.tryGetString(None, 'foo4'), 'asdf')

        assertIsEqual(config.tryGetString(None, 'foo5'), 'zxcv')

        assertIsEqual(config.tryGetString(None, 'foo6'), 'asdf')
        assertIsEqual(config.tryGetString(None, 'foo7'), 'zxcv')
Example #5
0
def installBindings(mainConfigPath):

    assertIsNotNone(mainConfigPath)
    assertThat(os.path.isfile(mainConfigPath))

    projenyDir = _getProjenyDir()
    projenyConfigPath = os.path.join(projenyDir, ConfigFileName)

    # Put the standard config first so it can be over-ridden by user settings
    configPaths = [projenyConfigPath, mainConfigPath]
    configPaths += _getExtraUserConfigPaths()

    Container.bind('Config').toSingle(Config,
                                      loadYamlFilesThatExist(*configPaths))

    initialVars = {
        'ProjenyDir': projenyDir,
    }

    initialVars['ConfigDir'] = os.path.dirname(mainConfigPath)

    if not MiscUtil.isRunningAsExe():
        initialVars['PythonPluginDir'] = _getPluginDirPath()

    Container.bind('VarManager').toSingle(VarManager, initialVars)
    Container.bind('SystemHelper').toSingle(SystemHelper)
    Container.bind('Logger').toSingle(Logger)
    Container.bind('UnityHelper').toSingle(UnityHelper)
    Container.bind('ScriptRunner').toSingle(ScriptRunner)
    Container.bind('PackageManager').toSingle(PackageManager)
    Container.bind('ProcessRunner').toSingle(ProcessRunner)
    Container.bind('JunctionHelper').toSingle(JunctionHelper)
    Container.bind('VisualStudioSolutionGenerator').toSingle(
        VisualStudioSolutionGenerator)
    Container.bind('VisualStudioHelper').toSingle(VisualStudioHelper)
    Container.bind('ProjenyVisualStudioHelper').toSingle(
        ProjenyVisualStudioHelper)
    Container.bind('ProjectSchemaLoader').toSingle(ProjectSchemaLoader)
    Container.bind('CommonSettings').toSingle(CommonSettings)
    Container.bind('UnityPackageExtractor').toSingle(UnityPackageExtractor)
    Container.bind('ZipHelper').toSingle(ZipHelper)
    Container.bind('UnityPackageAnalyzer').toSingle(UnityPackageAnalyzer)
    Container.bind('ProjectConfigChanger').toSingle(ProjectConfigChanger)
    Container.bind('PrjRunner').toSingle(PrjRunner)
    Container.bind('UnityEditorMenuGenerator').toSingle(
        UnityEditorMenuGenerator)

    Container.bind('ReleaseSourceManager').toSingle(ReleaseSourceManager)
Example #6
0
    def testSimple(self):
        yamlPath = ScriptDir + '/ExampleConfig.yaml'

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(yamlPath))

        config = Container.resolve('Config')

        assertIsEqual(config.getString('date'), '2012-08-06')
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        assertIsEqual(config.getList('places'), ['New Jersey', 'New York'])
        assertRaisesAny(lambda: config.getString('places'))
        assertRaisesAny(lambda: config.getDictionary('places'))

        assertIsEqual(config.getDictionary('customer'),
          {'first_name': 'Dorothy', 'family_name': 'Gale'})

        # Tests YAML references
        assertIsEqual(config.getString('foo1'), config.getString('receipt'))
Example #7
0
def installBindings(mainConfigPath):

    assertIsNotNone(mainConfigPath)
    assertThat(os.path.isfile(mainConfigPath))

    projenyDir = _getProjenyDir()
    projenyConfigPath = os.path.join(projenyDir, ConfigFileName)

    # Put the standard config first so it can be over-ridden by user settings
    configPaths = [projenyConfigPath, mainConfigPath]
    configPaths += _getExtraUserConfigPaths()

    Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(*configPaths))

    initialVars = { 'ProjenyDir': projenyDir, }

    initialVars['ConfigDir'] = os.path.dirname(mainConfigPath)

    if not MiscUtil.isRunningAsExe():
        initialVars['PythonPluginDir'] = _getPluginDirPath()

    Container.bind('VarManager').toSingle(VarManager, initialVars)
    Container.bind('SystemHelper').toSingle(SystemHelper)
    Container.bind('Logger').toSingle(Logger)
    Container.bind('UnityHelper').toSingle(UnityHelper)
    Container.bind('ScriptRunner').toSingle(ScriptRunner)
    Container.bind('PackageManager').toSingle(PackageManager)
    Container.bind('ProcessRunner').toSingle(ProcessRunner)
    Container.bind('JunctionHelper').toSingle(JunctionHelper)
    Container.bind('VisualStudioSolutionGenerator').toSingle(VisualStudioSolutionGenerator)
    Container.bind('VisualStudioHelper').toSingle(VisualStudioHelper)
    Container.bind('ProjenyVisualStudioHelper').toSingle(ProjenyVisualStudioHelper)
    Container.bind('ProjectSchemaLoader').toSingle(ProjectSchemaLoader)
    Container.bind('CommonSettings').toSingle(CommonSettings)
    Container.bind('UnityPackageExtractor').toSingle(UnityPackageExtractor)
    Container.bind('ZipHelper').toSingle(ZipHelper)
    Container.bind('UnityPackageAnalyzer').toSingle(UnityPackageAnalyzer)
    Container.bind('ProjectConfigChanger').toSingle(ProjectConfigChanger)
    Container.bind('PrjRunner').toSingle(PrjRunner)

    Container.bind('ReleaseSourceManager').toSingle(ReleaseSourceManager)
Example #8
0
    def _getAllPackageInfos(self, projectConfig, platform):
        configRefDesc = "'{0}' or '{1}'".format(ProjectConfigFileName, ProjectUserConfigFileName)
        allPackageRefs = [PackageReference(x, configRefDesc) for x in projectConfig.pluginsFolder + projectConfig.assetsFolder]

        packageMap = {}

        # Resolve all dependencies for each package
        # by default, put any dependencies that are not declared explicitly into the plugins folder
        for packageRef in allPackageRefs:

            packageName = packageRef.name
            packageDir = None

            for packageFolder in projectConfig.packageFolders:
                candidatePackageDir = os.path.join(packageFolder, packageName)

                if self._sys.directoryExists(candidatePackageDir):
                    packageDir = self._varMgr.expandPath(candidatePackageDir)
                    break

            assertIsNotNone(packageDir, "Could not find package '{0}' in any of the package directories!  Referenced in {1}", packageName, packageRef.sourceDesc)

            configPath = os.path.join(packageDir, PackageConfigFileName)

            if os.path.exists(configPath):
                packageConfig = Config(loadYamlFilesThatExist(configPath))
            else:
                packageConfig = Config([])

            folderType = self._getFolderTypeFromString(packageConfig.tryGetString('', 'FolderType'))

            if not self._shouldIncludeForPlatform(packageName, packageConfig, folderType, platform):
                continue

            createCustomVsProject = self._shouldCreateVsProjectForName(packageName, projectConfig.solutionProjects)

            isPluginsDir = True

            if packageName in projectConfig.assetsFolder:
                assertThat(not packageName in projectConfig.pluginsFolder)
                isPluginsDir = False

            if packageConfig.tryGetBool(False, 'ForceAssetsDirectory'):
                isPluginsDir = False

            explicitDependencies = packageConfig.tryGetList([], 'Dependencies')

            forcePluginsDir = packageConfig.tryGetBool(False, 'ForcePluginsDirectory')

            assemblyProjInfo = self._tryGetAssemblyProjectInfo(packageConfig, packageName)

            sourceDesc = '"{0}"'.format(configPath)

            if assemblyProjInfo != None:
                for assemblyDependName in assemblyProjInfo.dependencies:
                    if assemblyDependName not in [x.name for x in allPackageRefs]:
                        allPackageRefs.append(PackageReference(assemblyDependName, sourceDesc))

                explicitDependencies += assemblyProjInfo.dependencies

            groupedDependencies = packageConfig.tryGetList([], 'GroupWith')
            extraDependencies = packageConfig.tryGetList([], 'Extras')

            assertThat(not packageName in packageMap, "Found duplicate package with name '{0}'", packageName)

            packageMap[packageName] = PackageInfo(
                isPluginsDir, packageName, packageConfig, createCustomVsProject,
                explicitDependencies, forcePluginsDir, folderType, assemblyProjInfo, packageDir, groupedDependencies)

            for dependName in (explicitDependencies + groupedDependencies + extraDependencies):
                if dependName not in [x.name for x in allPackageRefs]:
                    # Yes, python is ok with changing allPackageRefs even while iterating over it
                    allPackageRefs.append(PackageReference(dependName, sourceDesc))

        return packageMap
Example #9
0
    def loadProjectConfig(self, name):
        schemaPath = self._varMgr.expandPath(
            '[UnityProjectsDir]/{0}/{1}'.format(name, ProjectConfigFileName))
        schemaPathUser = self._varMgr.expandPath(
            '[UnityProjectsDir]/{0}/{1}'.format(name,
                                                ProjectUserConfigFileName))
        schemaPathGlobal = self._varMgr.expandPath(
            '[UnityProjectsDir]/{0}'.format(ProjectConfigFileName))
        schemaPathUserGlobal = self._varMgr.expandPath(
            '[UnityProjectsDir]/{0}'.format(ProjectUserConfigFileName))

        self._log.debug('Loading schema at path "{0}"'.format(schemaPath))
        yamlConfig = Config(
            loadYamlFilesThatExist(schemaPath, schemaPathUser,
                                   schemaPathGlobal, schemaPathUserGlobal))

        config = ProjectConfig()

        config.pluginsFolder = yamlConfig.tryGetList([], 'PluginsFolder')
        config.assetsFolder = yamlConfig.tryGetList([], 'AssetsFolder')
        config.solutionProjects = yamlConfig.tryGetList([], 'SolutionProjects')
        config.targetPlatforms = yamlConfig.tryGetList([Platforms.Windows],
                                                       'TargetPlatforms')
        config.solutionFolders = yamlConfig.tryGetOrderedDictionary(
            OrderedDict(), 'SolutionFolders')
        config.packageFolders = yamlConfig.getList('PackageFolders')
        config.projectSettingsPath = yamlConfig.getString(
            'ProjectSettingsPath')
        config.customDirectories = yamlConfig.tryGetDictionary(
            {}, 'CustomPackageDirectories')

        customDirectories = config.customDirectories
        for key, value in customDirectories.items():
            self._varMgr.set(key, value)

        # Remove duplicates
        # config.assetsFolderDict = dict(set(config.assetsFolder))
        tmpList = []
        for x in config.assetsFolder:
            if type(x) is dict:
                tmpList.append(x["name"])
            else:
                tmpList.append(x)

        duplicates = [
            item for item, count in Counter(tmpList).items() if count > 1
        ]
        self._log.debug("duplicates {0}".format(duplicates))
        for d in duplicates:
            self._log.debug("removing {0}".format(d))
            tmpList.remove(d)

        config.pluginsFolder = list(set(config.pluginsFolder))

        for packageName in config.pluginsFolder:
            assertThat(
                not packageName in config.assetsFolder,
                "Found package '{0}' in both scripts and plugins.  Must be in only one or the other"
                .format(packageName))

        return config
Example #10
0
    def _getAllPackageInfos(self, projectConfig, platform):
        configRefDesc = "'{0}' or '{1}'".format(ProjectConfigFileName, ProjectUserConfigFileName)
        allPackageRefs = [PackageReference(x, configRefDesc) for x in projectConfig.pluginsFolder + projectConfig.assetsFolder]

        packageMap = {}

        # Resolve all dependencies for each package
        # by default, put any dependencies that are not declared explicitly into the plugins folder
        for packageRef in allPackageRefs:

            packageName = packageRef.name
            packageDir = None

            for packageFolder in projectConfig.packageFolders:
                candidatePackageDir = os.path.join(packageFolder, packageName)

                if self._sys.directoryExists(candidatePackageDir):
                    packageDir = self._varMgr.expandPath(candidatePackageDir)
                    break

            assertIsNotNone(packageDir, "Could not find package '{0}' in any of the package directories!  Referenced in {1}", packageName, packageRef.sourceDesc)

            configPath = os.path.join(packageDir, PackageConfigFileName)

            if os.path.exists(configPath):
                packageConfig = Config(loadYamlFilesThatExist(configPath))
            else:
                packageConfig = Config([])

            folderType = self._getFolderTypeFromString(packageConfig.tryGetString('', 'FolderType'))

            if not self._shouldIncludeForPlatform(packageName, packageConfig, folderType, platform):
                continue

            createCustomVsProject = self._shouldCreateVsProjectForName(packageName, projectConfig.solutionProjects)

            isPluginsDir = True

            if packageName in projectConfig.assetsFolder:
                assertThat(not packageName in projectConfig.pluginsFolder)
                isPluginsDir = False

            if packageConfig.tryGetBool(False, 'ForceAssetsDirectory'):
                isPluginsDir = False

            explicitDependencies = packageConfig.tryGetList([], 'Dependencies')

            forcePluginsDir = packageConfig.tryGetBool(False, 'ForcePluginsDirectory')

            assemblyProjInfo = self._tryGetAssemblyProjectInfo(packageConfig, packageName)

            sourceDesc = '"{0}"'.format(configPath)

            if assemblyProjInfo != None:
                for assemblyDependName in assemblyProjInfo.dependencies:
                    if assemblyDependName not in [x.name for x in allPackageRefs]:
                        allPackageRefs.append(PackageReference(assemblyDependName, sourceDesc))

                explicitDependencies += assemblyProjInfo.dependencies

            groupedDependencies = packageConfig.tryGetList([], 'GroupWith')
            extraDependencies = packageConfig.tryGetList([], 'Extras')

            assertThat(not packageName in packageMap, "Found duplicate package with name '{0}'", packageName)

            packageMap[packageName] = PackageInfo(
                isPluginsDir, packageName, packageConfig, createCustomVsProject,
                explicitDependencies, forcePluginsDir, folderType, assemblyProjInfo, packageDir, groupedDependencies)

            for dependName in (explicitDependencies + groupedDependencies + extraDependencies):
                if dependName not in [x.name for x in allPackageRefs]:
                    # Yes, python is ok with changing allPackageRefs even while iterating over it
                    allPackageRefs.append(PackageReference(dependName, sourceDesc))

        return packageMap