当前位置: 首页>>代码示例>>Python>>正文


Python clr.AddReferenceToFileAndPath方法代码示例

本文整理汇总了Python中clr.AddReferenceToFileAndPath方法的典型用法代码示例。如果您正苦于以下问题:Python clr.AddReferenceToFileAndPath方法的具体用法?Python clr.AddReferenceToFileAndPath怎么用?Python clr.AddReferenceToFileAndPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clr的用法示例。


在下文中一共展示了clr.AddReferenceToFileAndPath方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compilePackage

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def compilePackage(self, packageName, codeDict):
        import clr
        packagePath = os.path.join(self.temporary_dir, packageName)
        self.ensure_directory_present(packagePath)
        fileList = []
        for fileName, code in codeDict.iteritems():
            filePath = os.path.join(packagePath, fileName)
            self.ensure_directory_present(os.path.dirname(filePath))
            self.write_to_file(filePath, code)
            fileList.append(filePath)
        dllFile = os.path.join(self.temporary_dir, packageName + ".dll")
        clr.CompileModules(dllFile, mainModule=fileList[0], *fileList)
        self.delete_files(*fileList)
        clr.AddReferenceToFileAndPath(dllFile)
        
############################ Tests ################################################### 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_compiler.py

示例2: load_ironpython_test

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def load_ironpython_test(*args):
    _add_reference_to_dlr_core()
    clr.AddReference("Microsoft.Scripting")
    clr.AddReference("Microsoft.Dynamic")
    clr.AddReference("IronPython")

    if args: 
        return clr.LoadAssemblyFromFileWithPath(_iron_python_test_dll)
    else: 
        clr.AddReferenceToFileAndPath(_iron_python_test_dll) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:ipunittest.py

示例3: load_iron_python_dll

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def load_iron_python_dll(self):
        #When assemblies are installed into the GAC, we should not expect
        #IronPython.dll to exist alongside IronPython.dll
        if os.path.exists(os.path.join(sys.prefix, "IronPython.dll")):
            clr.AddReferenceToFileAndPath(os.path.join(sys.prefix, "IronPython.dll"))
        else:
            clr.AddReference("IronPython") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:ipunittest.py

示例4: test_negative_assembly_names

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_negative_assembly_names(self):
        import clr
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceByName, 'bad assembly name', 'WellFormed.But.Nonexistent, Version=9.9.9.9, Culture=neutral, PublicKeyToken=deadbeefdeadbeef, processorArchitecture=6502')
        self.assertRaises(IOError, clr.AddReference, 'this_assembly_does_not_exist_neither_by_file_name_nor_by_strong_name')

        self.assertRaises(TypeError, clr.AddReference, 35)

        for method in [
            clr.AddReference,
            clr.AddReferenceToFile,
            clr.AddReferenceToFileAndPath,
            clr.AddReferenceByName,
            clr.AddReferenceByPartialName,
            clr.LoadAssemblyFromFileWithPath,
            clr.LoadAssemblyFromFile,
            clr.LoadAssemblyByName,
            clr.LoadAssemblyByPartialName,
            ]:
            self.assertRaises(TypeError, method, None)

        for method in [
            clr.AddReference,
            clr.AddReferenceToFile,
            clr.AddReferenceToFileAndPath,
            clr.AddReferenceByName,
            clr.AddReferenceByPartialName,
            ]:
            self.assertRaises(TypeError, method, None, None)

        import System
        self.assertRaises(ValueError, clr.LoadAssemblyFromFile, System.IO.Path.DirectorySeparatorChar)
        self.assertRaises(ValueError, clr.LoadAssemblyFromFile, '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:test_clrload.py

示例5: test_addreferencetofileandpath_conflict

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_addreferencetofileandpath_conflict(self):
        """verify AddReferenceToFileAndPath picks up the path specified, not some arbitrary assembly somewhere in your path already"""
        code1 = """
    using System;

    public class CollisionTest {
        public static string Result(){
            return "Test1";
        }
    }
    """

        code2 = """
    using System;

    public class CollisionTest {
        public static string Result(){
            return "Test2";
        }
    }
    """
        import clr
        tmp = self.temporary_dir

        test1_cs, test1_dll = os.path.join(tmp, 'test1.cs'), os.path.join(tmp, 'CollisionTest.dll')
        test2_cs, test2_dll = os.path.join(tmp, 'test2.cs'), os.path.join(sys.prefix, 'CollisionTest.dll')

        self.write_to_file(test1_cs, code1)
        self.write_to_file(test2_cs, code2)

        self.assertEqual(self.run_csc("/nologo /target:library /out:" + test2_dll + ' ' + test2_cs), 0)
        self.assertEqual(self.run_csc("/nologo /target:library /out:" + test1_dll + ' ' + test1_cs), 0)

        clr.AddReferenceToFileAndPath(test1_dll)
        import CollisionTest
        self.assertEqual(CollisionTest.Result(), "Test1")

    #TODO:@skip("multiple_execute") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:40,代码来源:test_clrload.py

示例6: get_enums

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def get_enums(): 
    list_enum_byte      = [0]
    list_enum_sbyte     = [1]
    list_enum_ushort    = [0]
    list_enum_short     = [1]
    list_enum_uint      = [0]
    list_enum_int       = [1]
    list_enum_ulong     = [0]
    list_enum_long      = [1]

    if is_cli:     
        import clr
        import os
        import sys
        clr.AddReferenceToFileAndPath(os.path.join(sys.exec_prefix, "IronPythonTest.dll"))
        from IronPythonTest import DaysByte, DaysInt, DaysLong, DaysSByte, DaysShort, DaysUInt, DaysULong, DaysUShort
        list_enum_byte      = [DaysByte.None]
        list_enum_sbyte     = [DaysSByte.Mon]
        list_enum_ushort    = [DaysUShort.None]
        list_enum_short     = [DaysShort.Mon]
        list_enum_uint      = [DaysUInt.None]
        list_enum_int       = [DaysInt.Mon]
        list_enum_ulong     = [DaysULong.None]
        list_enum_long      = [DaysLong.Mon]
    
    return merge_lists(
        list_enum_byte,
        list_enum_sbyte,
        list_enum_ushort,
        list_enum_short,
        list_enum_uint,
        list_enum_int,
        list_enum_ulong,
        list_enum_long,
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:testdata.py

示例7: test_compiled_code

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_compiled_code():
    if System.Environment.GetEnvironmentVariable('DLR_SaveAssemblies'):
        # The SaveAssemblies option is not compatible with saving code to disk
        print '... skipping test if DLR_SaveAssemblies is set...'
        return

    import clr
    
    pyil = os.path.join(testpath.temporary_dir, 'test.pyil')

    # make sure we can compile
    clr.CompileModules(pyil, os.path.join(testpath.public_testdir, 'test_class.py'))
    
    # make sure we can compile multiple files
    clr.CompileModules(pyil, os.path.join(testpath.public_testdir, 'test_class.py'), os.path.join(testpath.public_testdir, 'test_slice.py'))
    
    clr.AddReferenceToFileAndPath(pyil)
    import nt
    
    # and make sure we can run some reasonable sophisticated code...
    System.IO.File.Move(os.path.join(testpath.public_testdir, 'test_class.py'), 'old_test_class.py')
    try:
        import test_class
        Assert(test_class.test_oldstyle_getattr.__doc__ != '')
    finally:
        System.IO.File.Move('old_test_class.py', os.path.join(testpath.public_testdir, 'test_class.py')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_ipyc.py

示例8: compileCode

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def compileCode(self, name, *codeArr):
        import clr
        inputFiles = []
        counter = 0
        for code in codeArr:
            inputFile = os.path.join(self.temporary_dir, name + ("" if counter == 0 else str(counter)) + ".py")
            self.write_to_file(inputFile, code)
            inputFiles.append(inputFile)
            counter+=1
        dllFile = os.path.join(self.temporary_dir, name + ".dll")
        clr.CompileModules(dllFile, mainModule=inputFiles[0], *inputFiles)
        self.delete_files(*inputFiles)
        clr.AddReferenceToFileAndPath(dllFile) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_compiler.py

示例9: test_load_order_modfile

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_load_order_modfile(self):
        import clr
        fileName = os.path.join(self.temporary_dir,"loadOrderMod.py")
        dllName = os.path.join(self.temporary_dir,"loadOrderMod.dll")
        self.write_to_file(fileName, "def f(): return 'hello'")
        clr.CompileModules(dllName, fileName)
        self.write_to_file(fileName, "def f(): return 'bonjour'")
        clr.AddReferenceToFileAndPath(dllName)
        import loadOrderMod
        self.assertEqual(loadOrderMod.f(), 'hello') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_compiler.py

示例10: test_negative_assembly_names

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_negative_assembly_names(self):
        import clr
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceToFileAndPath, os.path.join(self.test_dir, 'this_file_does_not_exist.dll'))
        self.assertRaises(IOError, clr.AddReferenceByName, 'bad assembly name', 'WellFormed.But.Nonexistent, Version=9.9.9.9, Culture=neutral, PublicKeyToken=deadbeefdeadbeef, processorArchitecture=6502')
        self.assertRaises(FileNotFoundError if is_netcoreapp21 else SystemError, clr.AddReference, 'this_assembly_does_not_exist_neither_by_file_name_nor_by_strong_name')

        self.assertRaises(TypeError, clr.AddReference, 35)

        for method in [
            clr.AddReference,
            clr.AddReferenceToFile,
            clr.AddReferenceToFileAndPath,
            clr.AddReferenceByName,
            clr.AddReferenceByPartialName,
            clr.LoadAssemblyFromFileWithPath,
            clr.LoadAssemblyFromFile,
            clr.LoadAssemblyByName,
            clr.LoadAssemblyByPartialName,
            ]:
            self.assertRaises(TypeError, method, None)

        for method in [
            clr.AddReference,
            clr.AddReferenceToFile,
            clr.AddReferenceToFileAndPath,
            clr.AddReferenceByName,
            clr.AddReferenceByPartialName,
            ]:
            self.assertRaises(TypeError, method, None, None)

        import System
        self.assertRaises(ValueError, clr.LoadAssemblyFromFile, System.IO.Path.DirectorySeparatorChar)
        self.assertRaises(ValueError, clr.LoadAssemblyFromFile, '') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:37,代码来源:test_clrload.py

示例11: test_compiled_code

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_compiled_code():
    if System.Environment.GetEnvironmentVariable('DLR_SaveAssemblies'):
        # The SaveAssemblies option is not compatible with saving code to disk
        print('... skipping test if DLR_SaveAssemblies is set...')
        return

    import clr
    
    pyil = os.path.join(testpath.temporary_dir, 'test.pyil')

    # make sure we can compile
    clr.CompileModules(pyil, os.path.join(testpath.public_testdir, 'test_class.py'))
    
    # make sure we can compile multiple files
    clr.CompileModules(pyil, os.path.join(testpath.public_testdir, 'test_class.py'), os.path.join(testpath.public_testdir, 'test_slice.py'))
    
    clr.AddReferenceToFileAndPath(pyil)
    import nt
    
    # and make sure we can run some reasonable sophisticated code...
    System.IO.File.Move(os.path.join(testpath.public_testdir, 'test_class.py'), 'old_test_class.py')
    try:
        import test_class
        Assert(test_class.test_oldstyle_getattr.__doc__ != '')
    finally:
        System.IO.File.Move('old_test_class.py', os.path.join(testpath.public_testdir, 'test_class.py')) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:28,代码来源:test_ipyc.py

示例12: AddBatchRvtUtilAssemblyReference

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def AddBatchRvtUtilAssemblyReference():
    try:
        clr.AddReference(BATCH_RVT_UTIL_ASSEMBLY_NAME)
    except IOException, e: # Can occur if PyRevit is installed. Need to use AddReferenceToFileAndPath() in this case.
        batchRvtScriptHostAssembly = GetExistingLoadedAssembly(BATCH_RVT_SCRIPT_HOST_ASSEMBLY_NAME)
        clr.AddReference(batchRvtScriptHostAssembly)
        from BatchRvt.ScriptHost import ScriptHostUtil
        environmentVariables = ScriptHostUtil.GetEnvironmentVariables()
        batchRvtFolderPath = ScriptHostUtil.GetBatchRvtFolderPath(environmentVariables)
        clr.AddReferenceToFileAndPath(Path.Combine(batchRvtFolderPath, BATCH_RVT_UTIL_ASSEMBLY_NAME)) 
开发者ID:bvn-architecture,项目名称:RevitBatchProcessor,代码行数:12,代码来源:batch_rvt_util.py

示例13: test_cached_types

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_cached_types():
    import clr
    from System import IComparable, IFormattable, ICloneable
    import IronPythonTest    

    cwd = os.getcwd()
    os.chdir(testpath.temporary_dir)

    # basic sanity test that we can compile...
    clr.CompileSubclassTypes('test', (object, ))
    clr.CompileSubclassTypes('test', object)
    clr.CompileSubclassTypes('test', object, str, int, long, float, complex)
    clr.CompileSubclassTypes('test', (object, IComparable[()]))
    clr.CompileSubclassTypes('test', (object, IComparable[()]), (str, IComparable[()]))
    
    # build an unlikely existing type and make sure construction gives us
    # back the correct type.
    clr.CompileSubclassTypes('cached_type_dll', (object, IComparable[()], IFormattable, ICloneable))
    asm = System.Reflection.Assembly.LoadFrom(os.path.join(testpath.temporary_dir, 'cached_type_dll.dll'))
    clr.AddReference(asm)
    
    class x(object, IComparable[()], IFormattable, ICloneable):
        pass
        
    a = x()
    AreEqual(clr.GetClrType(x).Assembly, asm)

    # collect all types that are available in IronPythonTest and
    # pre-gen them, then run test_inheritance to make sure it all works.
    types = []
    queue = [IronPythonTest]
    while queue:
        cur = queue.pop()
        for name in dir(cur):
            attr = getattr(cur, name)
            if type(attr) is type:
                clrType = clr.GetClrType(attr)
                if clrType.IsEnum or clrType.IsSealed or clrType.IsValueType or clrType.ContainsGenericParameters:
                    continue
                types.append(attr)
            elif type(attr) == type(IronPythonTest):
                queue.append(attr)

    clr.CompileSubclassTypes('InheritanceTypes', *types)
    clr.AddReferenceToFileAndPath(os.path.join(testpath.temporary_dir, 'InheritanceTypes.dll'))
    import test_inheritance

    #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21892
    # verify that GetSubclassedTypes round trips with clr.CompileSubclassTypes
    clr.CompileSubclassTypes('finaltest', *clr.GetSubclassedTypes())
    clr.AddReference('finaltest')

    os.chdir(cwd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:55,代码来源:test_ipyc.py

示例14: test_cached_types

# 需要导入模块: import clr [as 别名]
# 或者: from clr import AddReferenceToFileAndPath [as 别名]
def test_cached_types():
    import clr
    from System import IComparable, IFormattable, ICloneable
    import IronPythonTest    

    cwd = os.getcwd()
    os.chdir(testpath.temporary_dir)

    # basic sanity test that we can compile...
    clr.CompileSubclassTypes('test', (object, ))
    clr.CompileSubclassTypes('test', object)
    clr.CompileSubclassTypes('test', object, str, int, float, complex)
    clr.CompileSubclassTypes('test', (object, IComparable[()]))
    clr.CompileSubclassTypes('test', (object, IComparable[()]), (str, IComparable[()]))
    
    # build an unlikely existing type and make sure construction gives us
    # back the correct type.
    clr.CompileSubclassTypes('cached_type_dll', (object, IComparable[()], IFormattable, ICloneable))
    asm = System.Reflection.Assembly.LoadFrom(os.path.join(testpath.temporary_dir, 'cached_type_dll.dll'))
    clr.AddReference(asm)
    
    class x(object, IComparable[()], IFormattable, ICloneable):
        pass
        
    a = x()
    AreEqual(clr.GetClrType(x).Assembly, asm)

    # collect all types that are available in IronPythonTest and
    # pre-gen them, then run test_inheritance to make sure it all works.
    types = []
    queue = [IronPythonTest]
    while queue:
        cur = queue.pop()
        for name in dir(cur):
            attr = getattr(cur, name)
            if type(attr) is type:
                clrType = clr.GetClrType(attr)
                if clrType.IsEnum or clrType.IsSealed or clrType.IsValueType or clrType.ContainsGenericParameters:
                    continue
                types.append(attr)
            elif type(attr) == type(IronPythonTest):
                queue.append(attr)

    clr.CompileSubclassTypes('InheritanceTypes', *types)
    clr.AddReferenceToFileAndPath(os.path.join(testpath.temporary_dir, 'InheritanceTypes.dll'))
    import test_inheritance

    #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21892
    # verify that GetSubclassedTypes round trips with clr.CompileSubclassTypes
    clr.CompileSubclassTypes('finaltest', *clr.GetSubclassedTypes())
    clr.AddReference('finaltest')

    os.chdir(cwd) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:55,代码来源:test_ipyc.py


注:本文中的clr.AddReferenceToFileAndPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。