├── .gitattributes ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .nuget ├── NuGet.Config ├── NuGet.exe ├── NuGet.targets └── packages.config ├── DevScript.fsx ├── FSharp.Interop.PythonProvider.nuspec ├── LICENSE.txt ├── PythonProvider.Runtime ├── EngineAdapter.fs ├── PythonProvider.Runtime.fsproj ├── Scratchpad.fsx └── python27.dll ├── PythonTypeProvider.Tests.sln ├── PythonTypeProvider.sln ├── README.md ├── RELEASE_NOTES.md ├── build.cmd ├── build.fsx ├── build.sh ├── devenvDebuggingTestScript.sln ├── docs ├── content │ ├── index.fsx │ └── sample.fsx └── tools │ ├── generate.fsx │ ├── packages.config │ └── templates │ └── template.cshtml ├── lib ├── Python.Runtime.dll └── python27.dll ├── src ├── PythonDesignTimeProxy │ ├── App.config │ ├── Program.fs │ └── PythonProvider.TypesDiscoveryServer.fsproj └── PythonTypeProvider │ ├── DebugProvidedTypes.fs │ ├── ProvidedTypes.fs │ ├── ProvidedTypes.fsi │ ├── ProvidedTypesExtensions.fs │ ├── PythonProvider.fsproj │ ├── PythonTypeProvider.fs │ └── packages.config └── tests ├── PythonProvider.Runtime.Tests ├── PyObject.Tests.fs ├── PythonProvider.Runtime.Tests.fsproj ├── app.config ├── packages.config └── python27.dll └── PythonTypeProvider.Tests ├── Program.fs ├── PythonTypeProvider.Tests.fsproj ├── TestScript.fsx └── mytest.py /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | Please provide a succinct description of your issue. 4 | 5 | ### Repro steps 6 | 7 | Please provide the steps required to reproduce the problem 8 | 9 | 1. Step A 10 | 11 | 2. Step B 12 | 13 | ### Expected behavior 14 | 15 | Please provide a description of the behavior you expect. 16 | 17 | ### Actual behavior 18 | 19 | Please provide a description of the actual behavior you observe. 20 | 21 | ### Known workarounds 22 | 23 | Please provide a description of any known workarounds. 24 | 25 | ### Related information 26 | 27 | * Operating system 28 | * Branch 29 | * .NET Runtime, CoreCLR or Mono Version 30 | * Performance information, links to performance testing scripts 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # Enable nuget.exe in the .nuget folder (though normally executables are not tracked) 99 | !.nuget/NuGet.exe 100 | 101 | # Windows Azure Build Output 102 | csx 103 | *.build.csdef 104 | 105 | # Windows Store app package directory 106 | AppPackages/ 107 | 108 | # Others 109 | sql/ 110 | *.Cache 111 | ClientBin/ 112 | [Ss]tyle[Cc]op.* 113 | ~$* 114 | *~ 115 | *.dbmdl 116 | *.[Pp]ublish.xml 117 | *.pfx 118 | *.publishsettings 119 | 120 | # RIA/Silverlight projects 121 | Generated_Code/ 122 | 123 | # Backup & report files from converting an old project file to a newer 124 | # Visual Studio version. Backup files are not needed, because we have git ;-) 125 | _UpgradeReport_Files/ 126 | Backup*/ 127 | UpgradeLog*.XML 128 | UpgradeLog*.htm 129 | 130 | # SQL Server files 131 | App_Data/*.mdf 132 | App_Data/*.ldf 133 | 134 | 135 | #LightSwitch generated files 136 | GeneratedArtifacts/ 137 | _Pvt_Extensions/ 138 | ModelManifest.xml 139 | 140 | # ========================= 141 | # Windows detritus 142 | # ========================= 143 | 144 | # Windows image file caches 145 | Thumbs.db 146 | ehthumbs.db 147 | 148 | # Folder config file 149 | Desktop.ini 150 | 151 | # Recycle Bin used on file shares 152 | $RECYCLE.BIN/ 153 | 154 | # Mac desktop service store files 155 | .DS_Store 156 | 157 | # =================================================== 158 | # Exclude F# project specific directories and files 159 | # =================================================== 160 | 161 | # NuGet Packages Directory 162 | packages/ 163 | 164 | # Generated documentation folder 165 | docs/output/ 166 | 167 | # Temp folder used for publishing docs 168 | temp/ 169 | 170 | # Test results produced by build 171 | TestResults.xml 172 | release.cmd 173 | nuget/ 174 | 175 | # Nuget outputs 176 | nuget/*.nupkg 177 | 178 | # Python 179 | *.pyc -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pythonnet"] 2 | path = pythonnet 3 | url = https://github.com/pythonnet/pythonnet.git 4 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Interop.PythonProvider/0296a73dc18aaab21196ff577da69dd3e2ff6e86/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | 33 | 34 | 35 | 36 | $(SolutionDir).nuget 37 | packages.config 38 | 39 | 40 | 41 | 42 | $(NuGetToolsPath)\NuGet.exe 43 | @(PackageSource) 44 | 45 | "$(NuGetExePath)" 46 | mono --runtime=v4.0.30319 $(NuGetExePath) 47 | 48 | $(TargetDir.Trim('\\')) 49 | 50 | -RequireConsent 51 | -NonInteractive 52 | 53 | "$(SolutionDir) " 54 | "$(SolutionDir)" 55 | 56 | 57 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 58 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 59 | 60 | 61 | 62 | RestorePackages; 63 | $(BuildDependsOn); 64 | 65 | 66 | 67 | 68 | $(BuildDependsOn); 69 | BuildPackage; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | 98 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /DevScript.fsx: -------------------------------------------------------------------------------- 1 |  2 | //#r "Dependencies/pythonnet/Python.Runtime.dll" 3 | #r "bin/Python.Runtime.dll" 4 | 5 | open Python 6 | open Python.Runtime 7 | 8 | //PythonEngine.InitExt() 9 | PythonEngine.Initialize() 10 | 11 | let pySysModule = PythonEngine.ImportModule("sys") 12 | let sysPath = pySysModule.GetAttr("path") 13 | sysPath.InvokeMethod("append", new PyString(@"C:\Users\mitekm\Documents\GitHub\FSharp.Interop.PythonProvider\tests\PythonTypeProvider.Tests")) 14 | let testModule = PythonEngine.ImportModule("mytest") 15 | let inspectModule = PythonEngine.ImportModule("inspect") 16 | let testFunc = testModule.GetAttr("aMethod") 17 | let argsInfo = inspectModule.InvokeMethod("getargspec", testFunc) 18 | let args2 = argsInfo.GetAttr("args") 19 | testFunc.Invoke(new PyInt(5), new PyInt(7)) 20 | PythonEngine.RunSimpleString("5") 21 | 22 | PyObject.FromManagedObject(5).GetPythonType() 23 | 24 | PyTuple.IsTupleType(new PyInt(12)) 25 | 26 | let n = PythonEngine.BeginAllowThreads() 27 | //PythonEngine.EndAllowThreads(n) 28 | 29 | let (?) (pyObject: PyObject) (name: string) = pyObject.GetAttr name 30 | 31 | let callable = 32 | let builtin = PythonEngine.ImportModule("__builtin__") 33 | let pythonCallable = builtin ? callable 34 | fun(f: PyObject) -> pythonCallable.Invoke(f).IsTrue() 35 | 36 | let pyBuiltinsModule = PythonEngine.ImportModule("__builtin__") 37 | let import = pyBuiltinsModule.GetAttr("__import__") 38 | let none = PythonEngine.RunSimpleString("eval('None')") 39 | let x = PyObject.FromManagedObject(5.0f) 40 | x.GetPythonType() 41 | 42 | 43 | let pyMathModule = PythonEngine.ImportModule("math") 44 | let sin = pyMathModule ? sin 45 | let modules = pySysModule.GetAttr("modules") 46 | let keys = modules.InvokeMethod("keys") 47 | 48 | 49 | let l = PythonEngine.AcquireLock() 50 | let m = 51 | PythonEngine.ModuleFromString("a", """ 52 | def aMethod(arg1, arg2): 53 | pass 54 | """) 55 | PythonEngine.ReleaseLock l 56 | let n2 = PythonEngine.BeginAllowThreads() 57 | //let myMethod = PythonEngine.ImportModule("a") 58 | 59 | 60 | 61 | let l = PythonEngine.AcquireLock() 62 | let res = PythonEngine.RunSimpleString("execfile('file.py')") 63 | PythonEngine.ReleaseLock l 64 | 65 | 66 | (failwith "fail" : int) 67 | 68 | MailboxProcessor.Start(fun inbox -> 69 | async { while true do 70 | //PythonEngine.Initialize() 71 | printfn "locking..."; 72 | let l = PythonEngine.AcquireLock() 73 | printfn "sleeping..., l = %d" l 74 | do System.Threading.Thread.Sleep 1000 75 | printfn "unlocking..."; 76 | PythonEngine.ReleaseLock l 77 | do System.Threading.Thread.Sleep 1000 }) 78 | MailboxProcessor.Start(fun inbox -> 79 | async { while true do 80 | //PythonEngine.Initialize() 81 | printfn "locking..."; 82 | let l = PythonEngine.AcquireLock() 83 | printfn "sleeping..., l = %d" l 84 | do System.Threading.Thread.Sleep 1000 85 | printfn "unlocking..."; 86 | PythonEngine.ReleaseLock l 87 | do System.Threading.Thread.Sleep 1000 }) 88 | 89 | MailboxProcessor.Start(fun inbox -> 90 | async { while true do 91 | //PythonEngine.Initialize() 92 | printfn "2 locking..."; 93 | let l = PythonEngine.AcquireLock() 94 | printfn "2 sleeping..., l = %d" l 95 | do System.Threading.Thread.Sleep 1000 96 | printfn "2 unlocking..."; 97 | PythonEngine.ReleaseLock l 98 | do System.Threading.Thread.Sleep 1000 }) 99 | 100 | while true do 101 | printfn "MAIN: locking..."; 102 | let l = PythonEngine.AcquireLock() 103 | printfn "MAIN: sleeping..., l = %d" l 104 | do System.Threading.Thread.Sleep 1000 105 | printfn "MAIN: releasing..."; 106 | PythonEngine.ReleaseLock l 107 | do System.Threading.Thread.Sleep 1000 108 | 109 | 1 110 | (* 111 | def describe_builtin(obj): 112 | """ Describe a builtin function """ 113 | 114 | wi('+Built-in Function: %s' % obj.__name__) 115 | # Built-in functions cannot be inspected by 116 | # inspect.getargspec. We have to try and parse 117 | # the __doc__ attribute of the function. 118 | docstr = obj.__doc__ 119 | args = '' 120 | 121 | if docstr: 122 | items = docstr.split('\n') 123 | if items: 124 | func_descr = items[0] 125 | s = func_descr.replace(obj.__name__,'') 126 | idx1 = s.find('(') 127 | idx2 = s.find(')',idx1) 128 | if idx1 != -1 and idx2 != -1 and (idx2>idx1+1): 129 | args = s[idx1+1:idx2] 130 | wi('\t-Method Arguments:', args) 131 | 132 | if args=='': 133 | wi('\t-Method Arguments: None') 134 | 135 | print 136 | *) 137 | //let pythonRuntime = Runtime() 138 | 139 | let pythonSysModule = PythonEngine.ImportModule("sys") 140 | let pythonMathModule = PythonEngine.ImportModule("math") 141 | let pythonIterToolsModule = PythonEngine.ImportModule("itertools") 142 | let pythonInspectModule = PythonEngine.ImportModule("inspect") 143 | 144 | //PythonEngine.RunString("sin") 145 | //PythonEngine.RunString("sin(3.0)") 146 | //PythonEngine.RunString("import math; sin(3.0)") 147 | //PythonEngine.RunString("inspect.getargspec(math.sin)") 148 | //PythonEngine.RunString("inspect.getargspec(aMethod)") 149 | 150 | pythonSysModule.GetAttr("__doc__") 151 | 152 | let pythonMathModuleItems = pythonMathModule.Dir() 153 | [ for item in pythonMathModuleItems -> item.ToString() ] 154 | 155 | let pythonPiObject = pythonMathModule.GetAttr("pi") 156 | let pythonSinObject = pythonMathModule.GetAttr("sin") 157 | 158 | let pythonSinCodeObject = pythonSinObject.GetAttr("func_code") 159 | let pythonSinDocObject = pythonSinObject.GetAttr("__doc__") 160 | 161 | let myModule = PythonEngine.ModuleFromString("test2", """ 162 | def aMethod(arg1, arg2): 163 | pass 164 | 165 | p = 1""") 166 | 167 | let myMethod = myModule.GetAttr("aMethod") 168 | let myMethod = myModule.GetAttr("p") 169 | myModule.Dir() 170 | 171 | 172 | 173 | let myMethodCode = myMethod.GetAttr("func_code") 174 | myMethodCode.GetAttr("co_argcount") 175 | myMethodCode.GetAttr("co_varnames") 176 | myMethodCode.GetAttr("co_varnames").GetItem(0) 177 | myMethodCode.GetAttr("co_varnames").GetItem(1) 178 | myMethodCode.GetAttr("co_varnames").Length() 179 | 180 | pythonMathModule.GetAttr("__doc__").ToString() 181 | 182 | 183 | let getPythonModuleInfo(pythonModuleName:string) = 184 | let pythonModule = PythonEngine.ImportModule(pythonModuleName) 185 | try 186 | match pythonModule.GetAttr("__doc__") with 187 | | null -> "no documentation available" 188 | | attr -> "documentation: " + attr.ToString() 189 | with err -> sprintf "no documentation available (error: %s)" err.Message 190 | 191 | 192 | let moduleInfo = 193 | let modules = pythonSysModule.GetAttr("modules") 194 | let keys = modules.InvokeMethod("keys") 195 | [ for i in 0 .. keys.Length() - 1 do 196 | let moduleName = keys.GetItem(i).ToString() 197 | match moduleName with 198 | //| null -> () 199 | //| s when s.StartsWith "encodings." -> () 200 | | _ -> yield moduleName ] 201 | |> List.filter (fun x -> x = "inspect") 202 | (* 203 | ) 204 | // Explicit application needed in the demonstrator 205 | let (%%) (f:Python.Runtime.PyObject) (y: 'T) = 206 | let args = 207 | match box y with 208 | | null -> failwith "invalid null argument value to python function call" 209 | | :? Python.Runtime.PyObject as v -> v 210 | | :? double as v -> new Python.Runtime.PyFloat(v) :> Python.Runtime.PyObject 211 | | :? int as v -> new Python.Runtime.PyInt(v) :> Python.Runtime.PyObject 212 | | :? int64 as v -> new Python.Runtime.PyLong(v) :> Python.Runtime.PyObject 213 | | :? string as v -> new Python.Runtime.PyString(v) :> Python.Runtime.PyObject 214 | | _ -> failwith "unknown argument type %A" (box(y).GetType()) 215 | f.Invoke args 216 | 217 | *) 218 | 219 | 220 | -------------------------------------------------------------------------------- /FSharp.Interop.PythonProvider.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @project@ 8 | 9 | @build.number@ 10 | 11 | @authors@ 12 | 13 | @authors@ 14 | 15 | https://github.com/fsprojects/FSharp.Interop.PythonProvider/blob/master/LICENSE.txt 16 | 17 | https://github.com/fsprojects/FSharp.Interop.PythonProvider 18 | 19 | false 20 | 21 | @summary@ 22 | 23 | @description@ 24 | 25 | @releaseNotes@ 26 | 27 | Copyright 2013 28 | 29 | @tags@ 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2013, F# Software Foundation 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | ------------------------------------------------------------ 16 | 17 | Apache License, Version 2.0 18 | =========================== 19 | 20 | Apache License 21 | Version 2.0, January 2004 22 | http://www.apache.org/licenses/ 23 | 24 | ### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 25 | 26 | 27 | **1. Definitions.** 28 | 29 | - "License" shall mean the terms and conditions for use, reproduction, 30 | and distribution as defined by Sections 1 through 9 of this document. 31 | 32 | - "Licensor" shall mean the copyright owner or entity authorized by 33 | the copyright owner that is granting the License. 34 | 35 | - "Legal Entity" shall mean the union of the acting entity and all 36 | other entities that control, are controlled by, or are under common 37 | control with that entity. For the purposes of this definition, 38 | "control" means (i) the power, direct or indirect, to cause the 39 | direction or management of such entity, whether by contract or 40 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 41 | outstanding shares, or (iii) beneficial ownership of such entity. 42 | 43 | - "You" (or "Your") shall mean an individual or Legal Entity 44 | exercising permissions granted by this License. 45 | 46 | - "Source" form shall mean the preferred form for making modifications, 47 | including but not limited to software source code, documentation 48 | source, and configuration files. 49 | 50 | - "Object" form shall mean any form resulting from mechanical 51 | transformation or translation of a Source form, including but 52 | not limited to compiled object code, generated documentation, 53 | and conversions to other media types. 54 | 55 | - "Work" shall mean the work of authorship, whether in Source or 56 | Object form, made available under the License, as indicated by a 57 | copyright notice that is included in or attached to the work 58 | (an example is provided in the Appendix below). 59 | 60 | - "Derivative Works" shall mean any work, whether in Source or Object 61 | form, that is based on (or derived from) the Work and for which the 62 | editorial revisions, annotations, elaborations, or other modifications 63 | represent, as a whole, an original work of authorship. For the purposes 64 | of this License, Derivative Works shall not include works that remain 65 | separable from, or merely link (or bind by name) to the interfaces of, 66 | the Work and Derivative Works thereof. 67 | 68 | - "Contribution" shall mean any work of authorship, including 69 | the original version of the Work and any modifications or additions 70 | to that Work or Derivative Works thereof, that is intentionally 71 | submitted to Licensor for inclusion in the Work by the copyright owner 72 | or by an individual or Legal Entity authorized to submit on behalf of 73 | the copyright owner. For the purposes of this definition, "submitted" 74 | means any form of electronic, verbal, or written communication sent 75 | to the Licensor or its representatives, including but not limited to 76 | communication on electronic mailing lists, source code control systems, 77 | and issue tracking systems that are managed by, or on behalf of, the 78 | Licensor for the purpose of discussing and improving the Work, but 79 | excluding communication that is conspicuously marked or otherwise 80 | designated in writing by the copyright owner as "Not a Contribution." 81 | 82 | - "Contributor" shall mean Licensor and any individual or Legal Entity 83 | on behalf of whom a Contribution has been received by Licensor and 84 | subsequently incorporated within the Work. 85 | 86 | **2. Grant of Copyright License.** 87 | Subject to the terms and conditions of 88 | this License, each Contributor hereby grants to You a perpetual, 89 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 90 | copyright license to reproduce, prepare Derivative Works of, 91 | publicly display, publicly perform, sublicense, and distribute the 92 | Work and such Derivative Works in Source or Object form. 93 | 94 | **3. Grant of Patent License.** 95 | Subject to the terms and conditions of 96 | this License, each Contributor hereby grants to You a perpetual, 97 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 98 | (except as stated in this section) patent license to make, have made, 99 | use, offer to sell, sell, import, and otherwise transfer the Work, 100 | where such license applies only to those patent claims licensable 101 | by such Contributor that are necessarily infringed by their 102 | Contribution(s) alone or by combination of their Contribution(s) 103 | with the Work to which such Contribution(s) was submitted. If You 104 | institute patent litigation against any entity (including a 105 | cross-claim or counterclaim in a lawsuit) alleging that the Work 106 | or a Contribution incorporated within the Work constitutes direct 107 | or contributory patent infringement, then any patent licenses 108 | granted to You under this License for that Work shall terminate 109 | as of the date such litigation is filed. 110 | 111 | **4. Redistribution.** 112 | You may reproduce and distribute copies of the 113 | Work or Derivative Works thereof in any medium, with or without 114 | modifications, and in Source or Object form, provided that You 115 | meet the following conditions: 116 | 117 | - You must give any other recipients of the Work or 118 | Derivative Works a copy of this License; and 119 | 120 | - You must cause any modified files to carry prominent notices 121 | stating that You changed the files; and 122 | 123 | - You must retain, in the Source form of any Derivative Works 124 | that You distribute, all copyright, patent, trademark, and 125 | attribution notices from the Source form of the Work, 126 | excluding those notices that do not pertain to any part of 127 | the Derivative Works; and 128 | 129 | - If the Work includes a "NOTICE" text file as part of its 130 | distribution, then any Derivative Works that You distribute must 131 | include a readable copy of the attribution notices contained 132 | within such NOTICE file, excluding those notices that do not 133 | pertain to any part of the Derivative Works, in at least one 134 | of the following places: within a NOTICE text file distributed 135 | as part of the Derivative Works; within the Source form or 136 | documentation, if provided along with the Derivative Works; or, 137 | within a display generated by the Derivative Works, if and 138 | wherever such third-party notices normally appear. The contents 139 | of the NOTICE file are for informational purposes only and 140 | do not modify the License. You may add Your own attribution 141 | notices within Derivative Works that You distribute, alongside 142 | or as an addendum to the NOTICE text from the Work, provided 143 | that such additional attribution notices cannot be construed 144 | as modifying the License. 145 | 146 | You may add Your own copyright statement to Your modifications and 147 | may provide additional or different license terms and conditions 148 | for use, reproduction, or distribution of Your modifications, or 149 | for any such Derivative Works as a whole, provided Your use, 150 | reproduction, and distribution of the Work otherwise complies with 151 | the conditions stated in this License. 152 | 153 | **5. Submission of Contributions.** 154 | Unless You explicitly state otherwise, 155 | any Contribution intentionally submitted for inclusion in the Work 156 | by You to the Licensor shall be under the terms and conditions of 157 | this License, without any additional terms or conditions. 158 | Notwithstanding the above, nothing herein shall supersede or modify 159 | the terms of any separate license agreement you may have executed 160 | with Licensor regarding such Contributions. 161 | 162 | **6. Trademarks.** 163 | This License does not grant permission to use the trade 164 | names, trademarks, service marks, or product names of the Licensor, 165 | except as required for reasonable and customary use in describing the 166 | origin of the Work and reproducing the content of the NOTICE file. 167 | 168 | **7. Disclaimer of Warranty.** 169 | Unless required by applicable law or 170 | agreed to in writing, Licensor provides the Work (and each 171 | Contributor provides its Contributions) on an "AS IS" BASIS, 172 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 173 | implied, including, without limitation, any warranties or conditions 174 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 175 | PARTICULAR PURPOSE. You are solely responsible for determining the 176 | appropriateness of using or redistributing the Work and assume any 177 | risks associated with Your exercise of permissions under this License. 178 | 179 | **8. Limitation of Liability.** 180 | In no event and under no legal theory, 181 | whether in tort (including negligence), contract, or otherwise, 182 | unless required by applicable law (such as deliberate and grossly 183 | negligent acts) or agreed to in writing, shall any Contributor be 184 | liable to You for damages, including any direct, indirect, special, 185 | incidental, or consequential damages of any character arising as a 186 | result of this License or out of the use or inability to use the 187 | Work (including but not limited to damages for loss of goodwill, 188 | work stoppage, computer failure or malfunction, or any and all 189 | other commercial damages or losses), even if such Contributor 190 | has been advised of the possibility of such damages. 191 | 192 | **9. Accepting Warranty or Additional Liability.** 193 | While redistributing 194 | the Work or Derivative Works thereof, You may choose to offer, 195 | and charge a fee for, acceptance of support, warranty, indemnity, 196 | or other liability obligations and/or rights consistent with this 197 | License. However, in accepting such obligations, You may act only 198 | on Your own behalf and on Your sole responsibility, not on behalf 199 | of any other Contributor, and only if You agree to indemnify, 200 | defend, and hold each Contributor harmless for any liability 201 | incurred by, or claims asserted against, such Contributor by reason 202 | of your accepting any such warranty or additional liability. 203 | 204 | ==================================================================================== 205 | Python.NET Components (Python.Runtime.dll) 206 | 207 | Zope Public License (ZPL) Version 2.0 208 | ----------------------------------------------- 209 | 210 | This software is Copyright (c) Zope Corporation (tm) and 211 | Contributors. All rights reserved. 212 | 213 | This license has been certified as open source. It has also 214 | been designated as GPL compatible by the Free Software 215 | Foundation (FSF). 216 | 217 | Redistribution and use in source and binary forms, with or 218 | without modification, are permitted provided that the 219 | following conditions are met: 220 | 221 | 1. Redistributions in source code must retain the above 222 | copyright notice, this list of conditions, and the following 223 | disclaimer. 224 | 225 | 2. Redistributions in binary form must reproduce the above 226 | copyright notice, this list of conditions, and the following 227 | disclaimer in the documentation and/or other materials 228 | provided with the distribution. 229 | 230 | 3. The name Zope Corporation (tm) must not be used to 231 | endorse or promote products derived from this software 232 | without prior written permission from Zope Corporation. 233 | 234 | 4. The right to distribute this software or to use it for 235 | any purpose does not give you the right to use Servicemarks 236 | (sm) or Trademarks (tm) of Zope Corporation. Use of them is 237 | covered in a separate agreement (see 238 | http://www.zope.com/Marks). 239 | 240 | 5. If any files are modified, you must cause the modified 241 | files to carry prominent notices stating that you changed 242 | the files and the date of any change. 243 | 244 | Disclaimer 245 | 246 | THIS SOFTWARE IS PROVIDED BY ZOPE CORPORATION ``AS IS'' 247 | AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 248 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 249 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 250 | NO EVENT SHALL ZOPE CORPORATION OR ITS CONTRIBUTORS BE 251 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 252 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 253 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 254 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 255 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 256 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 257 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 258 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 259 | DAMAGE. 260 | 261 | 262 | This software consists of contributions made by Zope 263 | Corporation and many individuals on behalf of Zope 264 | Corporation. Specific attributions are listed in the 265 | accompanying credits file. 266 | 267 | 268 | 269 | ============================================================= 270 | 271 | Python components (python27.dll) - see license at http://docs.python.org/2/license.html 272 | 273 | 274 | -------------------------------------------------------------------------------- /PythonProvider.Runtime/EngineAdapter.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module FSharp.Interop.Python 3 | 4 | open System 5 | open System.Collections.Generic 6 | open System.Runtime.CompilerServices 7 | open Python.Runtime 8 | 9 | let internal init = 10 | lazy 11 | PythonEngine.Initialize() 12 | AppDomain.CurrentDomain.DomainUnload.Add (fun _ -> PythonEngine.Shutdown()) 13 | 14 | //let internal getGIL() = 15 | // init.Force() 16 | // let token = PythonEngine.AcquireLock() 17 | // { new System.IDisposable with member __.Dispose() = PythonEngine.ReleaseLock(token) } 18 | 19 | let invoke action = 20 | init.Force() 21 | let token = PythonEngine.AcquireLock() 22 | try action() 23 | finally PythonEngine.ReleaseLock(token) 24 | 25 | //let (?) (self: PyObject) (name: string): 'T option = invoke <| fun() -> 26 | // if self.HasAttr name 27 | // then 28 | // let attr = self.GetAttr(name) 29 | // assert(attr.Repr() <> "None") 30 | // attr.AsManagedObject(typeof<'T>) |> unbox |> Some 31 | // else 32 | // None 33 | 34 | module Inspect = 35 | let internal handle = lazy (invoke <| fun() -> PythonEngine.ImportModule("inspect")) 36 | let internal isroutine = lazy (invoke <| fun() -> handle.Value.GetAttr("isroutine")) 37 | let internal ismodule = lazy (invoke <| fun() -> handle.Value.GetAttr("ismodule")) 38 | let internal getmembers = lazy (invoke <| fun() -> handle.Value.GetAttr("getmembers")) 39 | let internal getdoc = lazy (invoke <| fun() -> handle.Value.GetAttr("getdoc")) 40 | let internal isbuiltin = lazy (invoke <| fun() -> handle.Value.GetAttr("isbuiltin")) 41 | let internal isabstract = lazy (invoke <| fun() -> handle.Value.GetAttr("isabstract")) 42 | let internal isclass = lazy (invoke <| fun() -> handle.Value.GetAttr("isclass")) 43 | 44 | [] 45 | type Extensions = 46 | [] 47 | static member inline Invoke(this: Lazy, [] args: PyObject[]) = 48 | invoke <| fun() -> this.Value.Invoke(args) 49 | 50 | type PyObject with 51 | //gil required 52 | member this.Cast<'T>(): 'T = invoke <| fun() -> 53 | this.AsManagedObject(typeof<'T>) |> unbox 54 | member this.TryGetAttr(name: string) = invoke <| fun() -> 55 | if this.HasAttr(name) 56 | then Some( this.GetAttr(name)) 57 | else None 58 | member this.Name = invoke <| fun() -> 59 | assert (this.HasAttr("__name__")) 60 | this.GetAttr("__name__").Cast() 61 | member this.Doc: string = invoke <| fun() -> 62 | Inspect.getdoc.Invoke(this).Cast() 63 | 64 | member this.IsRoutine = invoke <| fun() -> 65 | Inspect.isroutine.Invoke(this).IsTrue() 66 | member this.IsModule = invoke <| fun() -> 67 | Inspect.ismodule.Invoke(this).IsTrue() 68 | member this.IsBuiltIn = invoke <| fun() -> 69 | Inspect.isbuiltin.Invoke(this).IsTrue() 70 | member this.IsAbstractClass = invoke <| fun() -> 71 | Inspect.isabstract.Invoke(this).IsTrue() 72 | member this.IsClass = invoke <| fun() -> 73 | Inspect.isclass.Invoke(this).IsTrue() 74 | 75 | member this.IsNotNone = invoke <| fun() -> 76 | this.IsTrue() 77 | 78 | member this.IsPublic = this.Name.[0] <> '_' 79 | 80 | type Module(handle: PyObject, ?name: string) = 81 | 82 | do assert (handle.IsModule) 83 | 84 | let members = 85 | lazy 86 | invoke <| fun() -> 87 | let publicMembers = 88 | match handle.TryGetAttr("__all__") with 89 | | Some pyObj -> 90 | seq { 91 | for name in pyObj |> PyList.AsList do 92 | yield string name, handle.GetAttr(name) 93 | } 94 | | None -> 95 | seq { 96 | for m in Inspect.getmembers.Invoke(handle) |> PyList.AsList do 97 | let name = m.[0].ToString() 98 | let isPublic = name.[0] <> '_' 99 | if isPublic && not (m.IsModule || m.IsClass) 100 | then yield name, m.[1] 101 | } 102 | 103 | dict publicMembers 104 | 105 | new(name: string) = let handle = invoke <| fun() -> PythonEngine.ImportModule(name) in Module(handle) 106 | 107 | member __.Name = handle.Name 108 | member __.Doc = handle.Doc 109 | 110 | member this.Item with get key = members.Value.[key] 111 | member this.Members = members.Value |> Seq.map (|KeyValue|) 112 | 113 | type SysModule() as this = 114 | inherit Module("sys") 115 | 116 | let path = lazy (invoke <| fun() -> PyList.AsList this.["path"]) 117 | 118 | member __.Modules() = 119 | invoke <| fun () -> 120 | seq { 121 | let modules = (new PyDict(this.["modules"])).Items() |> PyList.AsList 122 | for x in modules do 123 | let ``module`` = x.[1] 124 | if ``module``.IsNotNone && (``module``.Name = "__builtin__" || ``module``.IsPublic) 125 | then yield Module(``module``) 126 | } 127 | |> Seq.distinctBy (fun x -> x.Name) 128 | |> Seq.toArray 129 | 130 | member __.Path = [ for x in path.Value -> string x ] 131 | member __.AppendToPath(item: string) = path.Value.Append(new PyString( item)) 132 | 133 | open System.Runtime.CompilerServices 134 | [] 135 | do() 136 | -------------------------------------------------------------------------------- /PythonProvider.Runtime/PythonProvider.Runtime.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | ad4d91af-3c95-485b-a141-b67a9c97cc4d 9 | Library 10 | PythonProvider.Runtime 11 | PythonProvider.Runtime 12 | v4.0 13 | 4.3.1.0 14 | PythonProvider.Runtime 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | 3 25 | bin\Debug\PythonProvider.Runtime.XML 26 | 27 | 28 | pdbonly 29 | true 30 | true 31 | bin\Release\ 32 | TRACE 33 | 3 34 | bin\Release\PythonProvider.Runtime.XML 35 | 36 | 37 | 11 38 | 39 | 40 | 41 | 42 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 43 | 44 | 45 | 46 | 47 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | True 60 | 61 | 62 | ..\lib\Python.Runtime.dll 63 | 64 | 65 | 66 | 67 | 68 | 75 | -------------------------------------------------------------------------------- /PythonProvider.Runtime/Scratchpad.fsx: -------------------------------------------------------------------------------- 1 | #r "../lib/Python.Runtime.dll" 2 | open Python.Runtime 3 | PythonEngine.Initialize() 4 | 5 | open System.Collections 6 | open System.Collections.Generic 7 | 8 | let invoke action = 9 | let token = PythonEngine.AcquireLock() 10 | try action() 11 | finally PythonEngine.ReleaseLock(token) 12 | 13 | 14 | let inspect = invoke <| fun() -> PythonEngine.ImportModule("inspect") 15 | let inspect2 = invoke <| fun() -> PythonEngine.ImportModule("inspect") 16 | let math = invoke <| fun() -> PythonEngine.ImportModule("math") 17 | let sysModule = invoke <| fun() -> PythonEngine.ImportModule("sys") 18 | sysModule.GetAttr("__name__").AsManagedObject(typeof) |> unbox 19 | let ms = sysModule.GetAttr("modules") 20 | PyDict.IsDictType ms 21 | let xs' = (new PyDict(ms)) 22 | xs'.["encodings.encodings"].IsTrue() 23 | 24 | [for x in PyList.AsList(PyDict(sysModule.GetAttr("modules")).Keys()) do let x' = string x in if x'.[0] <> '_' then yield x' ] |> Seq.toArray //|> Seq.groupBy id |> Seq.filter (fun (x, xs) -> Seq.length xs > 1) 25 | 26 | let modules = 27 | [ 28 | let keys = ms.GetAttr("keys").Invoke() 29 | for key in PyList.AsList keys do 30 | let key = key.ToString() 31 | if key.[0] <> '_' 32 | then yield key 33 | ] 34 | |> List.sort 35 | 36 | let handle = invoke <| fun() -> PythonEngine.ImportModule("inspect") 37 | let isroutine = invoke <| fun() -> handle.GetAttr("isroutine") 38 | let getmembers = invoke <| fun() -> handle.GetAttr("getmembers") 39 | let ismodule = invoke <| fun() -> handle.GetAttr("ismodule") 40 | let getdoc = invoke <| fun() -> handle.GetAttr("getdoc") 41 | 42 | ismodule.Invoke(sysModule).IsTrue() 43 | let xs = getmembers.Invoke(sysModule, isroutine) |> PyList.AsList 44 | let x = new PyTuple(xs.[0]) 45 | let name = sysModule.GetAttr("__name__") 46 | PyString.IsStringType(name) 47 | name.AsManagedObject(typeof) 48 | 49 | PyObject.FromManagedObject(3).GetPythonType() 50 | PyInt(3).GetPythonType() 51 | -------------------------------------------------------------------------------- /PythonProvider.Runtime/python27.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Interop.PythonProvider/0296a73dc18aaab21196ff577da69dd3e2ff6e86/PythonProvider.Runtime/python27.dll -------------------------------------------------------------------------------- /PythonTypeProvider.Tests.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PythonTypeProvider.Tests", "tests\PythonTypeProvider.Tests\PythonTypeProvider.Tests.fsproj", "{D1DE417D-B34A-4F03-8755-949A54435D2A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D1DE417D-B34A-4F03-8755-949A54435D2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D1DE417D-B34A-4F03-8755-949A54435D2A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D1DE417D-B34A-4F03-8755-949A54435D2A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D1DE417D-B34A-4F03-8755-949A54435D2A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /PythonTypeProvider.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PythonProvider", "src\PythonTypeProvider\PythonProvider.fsproj", "{380603C0-72B7-4E76-8307-907344CDD78E}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{F9DEC36E-C519-4D9F-B571-104050171225}" 9 | ProjectSection(SolutionItems) = preProject 10 | docs\tools\generate.fsx = docs\tools\generate.fsx 11 | docs\content\index.fsx = docs\content\index.fsx 12 | docs\content\sample.fsx = docs\content\sample.fsx 13 | EndProjectSection 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{1D17676E-13CD-4C73-B79F-7E1C0C4DEC83}" 16 | ProjectSection(SolutionItems) = preProject 17 | build.fsx = build.fsx 18 | RELEASE_NOTES.md = RELEASE_NOTES.md 19 | EndProjectSection 20 | EndProject 21 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PythonProvider.TypesDiscoveryServer", "src\PythonDesignTimeProxy\PythonProvider.TypesDiscoveryServer.fsproj", "{F5932D2F-EB19-45B6-961D-01ACF9E086BD}" 22 | EndProject 23 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PythonProvider.Runtime", "PythonProvider.Runtime\PythonProvider.Runtime.fsproj", "{AD4D91AF-3C95-485B-A141-B67A9C97CC4D}" 24 | EndProject 25 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PythonProvider.Runtime.Tests", "tests\PythonProvider.Runtime.Tests\PythonProvider.Runtime.Tests.fsproj", "{345AD7B0-1DE0-448A-86B0-086AC521C7A7}" 26 | EndProject 27 | Global 28 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 29 | Debug|Any CPU = Debug|Any CPU 30 | Debug|Mixed Platforms = Debug|Mixed Platforms 31 | Debug|x64 = Debug|x64 32 | Debug|x86 = Debug|x86 33 | DebugMono|Any CPU = DebugMono|Any CPU 34 | DebugMono|Mixed Platforms = DebugMono|Mixed Platforms 35 | DebugMono|x64 = DebugMono|x64 36 | DebugMono|x86 = DebugMono|x86 37 | DebugWin|Any CPU = DebugWin|Any CPU 38 | DebugWin|Mixed Platforms = DebugWin|Mixed Platforms 39 | DebugWin|x64 = DebugWin|x64 40 | DebugWin|x86 = DebugWin|x86 41 | Release|Any CPU = Release|Any CPU 42 | Release|Mixed Platforms = Release|Mixed Platforms 43 | Release|x64 = Release|x64 44 | Release|x86 = Release|x86 45 | ReleaseMono|Any CPU = ReleaseMono|Any CPU 46 | ReleaseMono|Mixed Platforms = ReleaseMono|Mixed Platforms 47 | ReleaseMono|x64 = ReleaseMono|x64 48 | ReleaseMono|x86 = ReleaseMono|x86 49 | ReleaseWin|Any CPU = ReleaseWin|Any CPU 50 | ReleaseWin|Mixed Platforms = ReleaseWin|Mixed Platforms 51 | ReleaseWin|x64 = ReleaseWin|x64 52 | ReleaseWin|x86 = ReleaseWin|x86 53 | EndGlobalSection 54 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 55 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 58 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 59 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|x64.ActiveCfg = Debug|Any CPU 60 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|x64.Build.0 = Debug|Any CPU 61 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|x86.ActiveCfg = Debug|Any CPU 62 | {380603C0-72B7-4E76-8307-907344CDD78E}.Debug|x86.Build.0 = Debug|Any CPU 63 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|Any CPU.ActiveCfg = Debug|Any CPU 64 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|Any CPU.Build.0 = Debug|Any CPU 65 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|Mixed Platforms.ActiveCfg = Debug|Any CPU 66 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|Mixed Platforms.Build.0 = Debug|Any CPU 67 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|x64.ActiveCfg = Debug|Any CPU 68 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugMono|x86.ActiveCfg = Debug|Any CPU 69 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 70 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|Any CPU.Build.0 = Debug|Any CPU 71 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU 72 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU 73 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|x64.ActiveCfg = Debug|Any CPU 74 | {380603C0-72B7-4E76-8307-907344CDD78E}.DebugWin|x86.ActiveCfg = Debug|Any CPU 75 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|Any CPU.ActiveCfg = Release|Any CPU 76 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|Any CPU.Build.0 = Release|Any CPU 77 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 78 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|Mixed Platforms.Build.0 = Release|Any CPU 79 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|x64.ActiveCfg = Release|Any CPU 80 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|x64.Build.0 = Release|Any CPU 81 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|x86.ActiveCfg = Release|Any CPU 82 | {380603C0-72B7-4E76-8307-907344CDD78E}.Release|x86.Build.0 = Release|Any CPU 83 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|Any CPU.ActiveCfg = Release|Any CPU 84 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|Any CPU.Build.0 = Release|Any CPU 85 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|Mixed Platforms.ActiveCfg = Release|Any CPU 86 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|Mixed Platforms.Build.0 = Release|Any CPU 87 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|x64.ActiveCfg = Release|Any CPU 88 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseMono|x86.ActiveCfg = Release|Any CPU 89 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 90 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU 91 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU 92 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU 93 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 94 | {380603C0-72B7-4E76-8307-907344CDD78E}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 95 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 96 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 97 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 98 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 99 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|x64.ActiveCfg = Debug|Any CPU 100 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|x64.Build.0 = Debug|Any CPU 101 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|x86.ActiveCfg = Debug|Any CPU 102 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Debug|x86.Build.0 = Debug|Any CPU 103 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|Any CPU.ActiveCfg = Debug|Any CPU 104 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|Any CPU.Build.0 = Debug|Any CPU 105 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|Mixed Platforms.ActiveCfg = Debug|Any CPU 106 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|Mixed Platforms.Build.0 = Debug|Any CPU 107 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|x64.ActiveCfg = Debug|Any CPU 108 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugMono|x86.ActiveCfg = Debug|Any CPU 109 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 110 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|Any CPU.Build.0 = Debug|Any CPU 111 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU 112 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU 113 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|x64.ActiveCfg = Debug|Any CPU 114 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.DebugWin|x86.ActiveCfg = Debug|Any CPU 115 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 116 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|Any CPU.Build.0 = Release|Any CPU 117 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 118 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|Mixed Platforms.Build.0 = Release|Any CPU 119 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|x64.ActiveCfg = Release|Any CPU 120 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.Release|x86.ActiveCfg = Release|Any CPU 121 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|Any CPU.ActiveCfg = Release|Any CPU 122 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|Any CPU.Build.0 = Release|Any CPU 123 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|Mixed Platforms.ActiveCfg = Release|Any CPU 124 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|Mixed Platforms.Build.0 = Release|Any CPU 125 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|x64.ActiveCfg = Release|Any CPU 126 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseMono|x86.ActiveCfg = Release|Any CPU 127 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 128 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU 129 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU 130 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU 131 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 132 | {F5932D2F-EB19-45B6-961D-01ACF9E086BD}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 133 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 134 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|Any CPU.Build.0 = Debug|Any CPU 135 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 136 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 137 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|x64.ActiveCfg = Debug|Any CPU 138 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Debug|x86.ActiveCfg = Debug|Any CPU 139 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|Any CPU.ActiveCfg = Debug|Any CPU 140 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|Any CPU.Build.0 = Debug|Any CPU 141 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|Mixed Platforms.ActiveCfg = Debug|Any CPU 142 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|Mixed Platforms.Build.0 = Debug|Any CPU 143 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|x64.ActiveCfg = Debug|Any CPU 144 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugMono|x86.ActiveCfg = Debug|Any CPU 145 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 146 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|Any CPU.Build.0 = Debug|Any CPU 147 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU 148 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU 149 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|x64.ActiveCfg = Debug|Any CPU 150 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.DebugWin|x86.ActiveCfg = Debug|Any CPU 151 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|Any CPU.ActiveCfg = Release|Any CPU 152 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|Any CPU.Build.0 = Release|Any CPU 153 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 154 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|Mixed Platforms.Build.0 = Release|Any CPU 155 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|x64.ActiveCfg = Release|Any CPU 156 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.Release|x86.ActiveCfg = Release|Any CPU 157 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|Any CPU.ActiveCfg = Release|Any CPU 158 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|Any CPU.Build.0 = Release|Any CPU 159 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|Mixed Platforms.ActiveCfg = Release|Any CPU 160 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|Mixed Platforms.Build.0 = Release|Any CPU 161 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|x64.ActiveCfg = Release|Any CPU 162 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseMono|x86.ActiveCfg = Release|Any CPU 163 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 164 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU 165 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU 166 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU 167 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 168 | {AD4D91AF-3C95-485B-A141-B67A9C97CC4D}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 169 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 170 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU 171 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 172 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 173 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|x64.ActiveCfg = Debug|Any CPU 174 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Debug|x86.ActiveCfg = Debug|Any CPU 175 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|Any CPU.ActiveCfg = Debug|Any CPU 176 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|Any CPU.Build.0 = Debug|Any CPU 177 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|Mixed Platforms.ActiveCfg = Debug|Any CPU 178 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|Mixed Platforms.Build.0 = Debug|Any CPU 179 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|x64.ActiveCfg = Debug|Any CPU 180 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugMono|x86.ActiveCfg = Debug|Any CPU 181 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 182 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|Any CPU.Build.0 = Debug|Any CPU 183 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU 184 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU 185 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|x64.ActiveCfg = Debug|Any CPU 186 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.DebugWin|x86.ActiveCfg = Debug|Any CPU 187 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU 188 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|Any CPU.Build.0 = Release|Any CPU 189 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 190 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU 191 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|x64.ActiveCfg = Release|Any CPU 192 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.Release|x86.ActiveCfg = Release|Any CPU 193 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|Any CPU.ActiveCfg = Release|Any CPU 194 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|Any CPU.Build.0 = Release|Any CPU 195 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|Mixed Platforms.ActiveCfg = Release|Any CPU 196 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|Mixed Platforms.Build.0 = Release|Any CPU 197 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|x64.ActiveCfg = Release|Any CPU 198 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseMono|x86.ActiveCfg = Release|Any CPU 199 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 200 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU 201 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU 202 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU 203 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 204 | {345AD7B0-1DE0-448A-86B0-086AC521C7A7}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 205 | EndGlobalSection 206 | GlobalSection(SolutionProperties) = preSolution 207 | HideSolutionNode = FALSE 208 | EndGlobalSection 209 | EndGlobal 210 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Issue Stats](http://issuestats.com/github/fsprojects/FSharp.Interop.PythonProvider/badge/issue)](http://issuestats.com/github/fsprojects/FSharp.Interop.PythonProvider) 2 | [![Issue Stats](http://issuestats.com/github/fsprojects/FSharp.Interop.PythonProvider/badge/pr)](http://issuestats.com/github/fsprojects/FSharp.Interop.PythonProvider) 3 | 4 | PythonTypeProvider 5 | ================== 6 | 7 | Early experimental F# type provider for python. 8 | 9 | ## Disclaimer 10 | 11 | This is an alpha build and as such may have problems yet undetected. 12 | 13 | This is not suitable for production use. 14 | 15 | ## Maintainer(s) 16 | 17 | - [@dmitry-a-morozov](https://github.com/dmitry-a-morozov) 18 | - [@orlandpm](https://github.com/orlandpm) 19 | 20 | The default maintainer account for projects under "fsprojects" is [@fsprojectsgit](https://github.com/fsprojectsgit) - F# Community Project Incubation Space (repo management) 21 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 0.0.1-alpha - 17.12.2013 2 | * Initial release of FSharp.Interop.PythonProvider 3 | #### 0.0.2-alpha - 17.12.2013 4 | * Update docs -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | if not exist packages\FAKE\tools\Fake.exe ( 4 | .nuget\nuget.exe install FAKE -OutputDirectory packages -ExcludeVersion -Prerelease 5 | ) 6 | packages\FAKE\tools\FAKE.exe build.fsx %* 7 | -------------------------------------------------------------------------------- /build.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // FAKE build script 3 | // -------------------------------------------------------------------------------------- 4 | 5 | #r @"packages/FAKE/tools/FakeLib.dll" 6 | open Fake 7 | open Fake.Git 8 | open Fake.AssemblyInfoFile 9 | open Fake.ReleaseNotesHelper 10 | open System 11 | 12 | let projects = [|"PythonTypeProvider" 13 | "PythonTypeProviderProxy"|] 14 | 15 | let summary = "Early experimental F# type provider for python." 16 | let description = "Early experimental F# type provider for python." 17 | let authors = ["Don Syme"; "Gustavo Guerra"; "Jon Harrop" ] 18 | let tags = "F# fsharp typeproviders python" 19 | 20 | let solutionFile = "PythonTypeProvider" 21 | 22 | let testAssemblies = "tests/**/bin/Release/*.Tests*.dll" 23 | let gitHome = "https://github.com/fsprojects/FSharp.Interop.PythonProvider" 24 | let gitName = "FSharp.Interop.PythonProvider" 25 | let cloneUrl = "https://github.com/fsprojects/FSharp.Interop.PythonProvider" 26 | let nugetDir = "./nuget/" 27 | 28 | // Read additional information from the release notes document 29 | Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ 30 | let release = parseReleaseNotes (IO.File.ReadAllLines "RELEASE_NOTES.md") 31 | 32 | // Generate assembly info files with the right version & up-to-date information 33 | Target "AssemblyInfo" (fun _ -> 34 | for project in projects do 35 | let fileName = "src/" + project + "/AssemblyInfo.fs" 36 | CreateFSharpAssemblyInfo fileName 37 | [ Attribute.Title project 38 | Attribute.Product project 39 | Attribute.Description summary 40 | Attribute.Version release.AssemblyVersion 41 | Attribute.FileVersion release.AssemblyVersion ] 42 | ) 43 | 44 | // -------------------------------------------------------------------------------------- 45 | // Clean build results & restore NuGet packages 46 | 47 | Target "RestorePackages" RestorePackages 48 | 49 | Target "Clean" (fun _ -> 50 | CleanDirs ["bin"; "temp"; nugetDir] 51 | ) 52 | 53 | Target "CleanDocs" (fun _ -> 54 | CleanDirs ["docs/output"] 55 | ) 56 | 57 | // -------------------------------------------------------------------------------------- 58 | // Build library & test project 59 | 60 | Target "Build" (fun _ -> 61 | !! (solutionFile + ".sln") 62 | |> MSBuildRelease "" "Rebuild" 63 | |> ignore 64 | 65 | !! (solutionFile + ".Tests.sln") 66 | |> MSBuildRelease "" "Rebuild" 67 | |> ignore 68 | ) 69 | 70 | // -------------------------------------------------------------------------------------- 71 | // Run the unit tests using test runner & kill test runner when complete 72 | 73 | Target "RunTests" (fun _ -> 74 | ActivateFinalTarget "CloseTestRunner" 75 | 76 | !! testAssemblies 77 | |> NUnit (fun p -> 78 | { p with 79 | DisableShadowCopy = true 80 | TimeOut = TimeSpan.FromMinutes 20. 81 | OutputFile = "TestResults.xml" }) 82 | ) 83 | 84 | FinalTarget "CloseTestRunner" (fun _ -> 85 | ProcessHelper.killProcess "nunit-agent.exe" 86 | ) 87 | 88 | // -------------------------------------------------------------------------------------- 89 | // Build a NuGet package 90 | 91 | Target "NuGet" (fun _ -> 92 | // Format the description to fit on a single line (remove \r\n and double-spaces) 93 | let description = description.Replace("\r", "") 94 | .Replace("\n", "") 95 | .Replace(" ", " ") 96 | let project = gitName 97 | 98 | let nugetDocsDir = nugetDir @@ "docs" 99 | let nugetlibDir = nugetDir @@ "lib/net40" 100 | 101 | CleanDir nugetDocsDir 102 | CleanDir nugetlibDir 103 | 104 | CopyDir nugetlibDir "bin" (fun file -> file.Contains "FSharp.Core." |> not) 105 | CopyDir nugetDocsDir "./docs/output" allFiles 106 | 107 | NuGet (fun p -> 108 | { p with 109 | Authors = authors 110 | Project = project 111 | Summary = summary 112 | Description = description 113 | Version = release.NugetVersion 114 | ReleaseNotes = release.Notes |> toLines 115 | Tags = tags 116 | OutputPath = nugetDir 117 | AccessKey = getBuildParamOrDefault "nugetkey" "" 118 | Publish = hasBuildParam "nugetkey" 119 | Dependencies = [] }) 120 | (project + ".nuspec") 121 | ) 122 | 123 | // -------------------------------------------------------------------------------------- 124 | // Generate the documentation 125 | 126 | Target "GenerateDocs" (fun _ -> 127 | executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore 128 | ) 129 | 130 | // -------------------------------------------------------------------------------------- 131 | // Release Scripts 132 | 133 | Target "ReleaseDocs" (fun _ -> 134 | let ghPages = "gh-pages" 135 | let ghPagesLocal = "temp/gh-pages" 136 | Repository.clone "temp" (cloneUrl) ghPages 137 | Branches.checkoutBranch ghPagesLocal ghPages 138 | fullclean "temp/gh-pages" 139 | CopyRecursive "docs/output" ghPagesLocal true |> printfn "%A" 140 | CommandHelper.runSimpleGitCommand ghPagesLocal "add ." |> printfn "%s" 141 | let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion 142 | CommandHelper.runSimpleGitCommand ghPagesLocal cmd |> printfn "%s" 143 | Branches.push ghPagesLocal 144 | ) 145 | 146 | Target "Release" DoNothing 147 | 148 | // -------------------------------------------------------------------------------------- 149 | // Run all targets by default. Invoke 'build ' to override 150 | 151 | Target "All" DoNothing 152 | 153 | "Clean" 154 | ==> "RestorePackages" 155 | ==> "AssemblyInfo" 156 | ==> "Build" 157 | ==> "RunTests" 158 | ==> "All" 159 | 160 | "All" 161 | ==> "CleanDocs" 162 | ==> "GenerateDocs" 163 | ==> "ReleaseDocs" 164 | ==> "NuGet" 165 | ==> "Release" 166 | 167 | RunTargetOrDefault "All" 168 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ ! -f packages/FAKE/tools/Fake.exe ]; then 3 | mono .NuGet/NuGet.exe install FAKE -OutputDirectory packages -ExcludeVersion -Prerelease 4 | fi 5 | mono packages/FAKE/tools/FAKE.exe build.fsx $@ 6 | -------------------------------------------------------------------------------- /devenvDebuggingTestScript.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "devenv", "..\..\..\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe", "{09335C7B-F4F3-4AD6-9FEE-0C653AAD6FF8}" 7 | ProjectSection(DebuggerProjectSystem) = preProject 8 | PortSupplier = 00000000-0000-0000-0000-000000000000 9 | Executable = C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 10 | RemoteMachine = 11 | StartingDirectory = C:\GitHub\fsprojects\PythonTypeProvider 12 | Arguments = C:\GitHub\fsprojects\PythonTypeProvider\TestScript.fsx 13 | Environment = Default 14 | LaunchingEngine = fb0d4648-f776-4980-95f8-bb7f36ebc1ee 15 | UseLegacyDebugEngines = No 16 | LaunchSQLEngine = No 17 | AttachLaunchAction = No 18 | EndProjectSection 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|x86 = Debug|x86 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {09335C7B-F4F3-4AD6-9FEE-0C653AAD6FF8}.Debug|x86.ActiveCfg = Debug 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /docs/content/index.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | FSharp.Interop.PythonProvider 6 | ============================= 7 | 8 | Early experimental F# type provider for Python. 9 | 10 | Uses [Python for .NET](https://github.com/pythonnet/pythonnet) for metadata and interop. 11 | 12 | Currently uses python27.dll for execution on Windows (this is determined by Python.NET). 13 | 14 | Currently 32-bit only. 15 | 16 |
17 |
18 |
19 |
20 | The library can be installed from NuGet: 21 |
PM> Install-Package FSharp.Interop.PythonProvider -prerelease
22 |
23 |
24 |
25 |
26 | 27 | 28 | *) 29 | 30 | 31 | (** 32 | 33 | Contributing and copyright 34 | -------------------------- 35 | 36 | The project is hosted on [GitHub][gh] where you can [report issues][issues], fork 37 | the project and submit pull requests. If you're adding new public API, please also 38 | consider adding [samples][content] that can be turned into a documentation. You might 39 | also want to read [library design notes][readme] to understand how it works. 40 | 41 | The library is available under the Apache 2.0 license, which allows modification and 42 | redistribution for both commercial and non-commercial purposes. For more information see the 43 | [License file][license] in the GitHub repository. 44 | 45 | [content]: https://github.com/fsprojects/FSharp.Interop.PythonProvider/tree/master/docs/content 46 | [gh]: https://github.com/fsprojects/FSharp.Interop.PythonProvider 47 | [issues]: https://github.com/fsprojects/FSharp.Interop.PythonProvider/issues 48 | [readme]: https://github.com/fsprojects/FSharp.Interop.PythonProvider/blob/master/README.md 49 | [license]: https://github.com/fsprojects/FSharp.Interop.PythonProvider/blob/master/LICENSE.txt 50 | *) 51 | -------------------------------------------------------------------------------- /docs/content/sample.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | Sample 6 | ====== 7 | *) 8 | 9 | #r "Python.Runtime.dll" 10 | #r "FSharp.Interop.PythonProvider.dll" 11 | 12 | open FSharp.Interop 13 | 14 | //Python.math.sin Python.math.pi 15 | //Python.math.cos Python.math.pi 16 | 17 | type Python = PythonProvider<"math, sys, os"> 18 | Python. math.pi 19 | Python.os.curdir 20 | 21 | -------------------------------------------------------------------------------- /docs/tools/generate.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // Builds the documentation from `.fsx` and `.md` files in the 'docs/content' directory 3 | // (the generated documentation is stored in the 'docs/output' directory) 4 | // -------------------------------------------------------------------------------------- 5 | 6 | // Binaries that have XML documentation (in a corresponding generated XML file) 7 | let referenceBinaries = [ "FSharp.Interop.PythonProvider.dll" ] 8 | // Web site location for the generated documentation 9 | let website = "/FSharp.Interop.PythonProvider" 10 | 11 | // Specify more information about your project 12 | let info = 13 | [ "project-name", "fsprojects/FSharp.Interop.PythonProvider" 14 | "project-author", "F# Software Foundation" 15 | "project-summary", "Experimental F# type provider for Python." 16 | "project-github", "https://github.com/fsprojects/FSharp.Interop.PythonProvider" 17 | "project-nuget", "https://www.nuget.org/packages/FSharp.Interop.PythonProvider" ] 18 | 19 | // -------------------------------------------------------------------------------------- 20 | // For typical project, no changes are needed below 21 | // -------------------------------------------------------------------------------------- 22 | 23 | #I "../../packages/FSharp.Formatting.2.2.11-beta/lib/net40" 24 | #I "../../packages/RazorEngine.3.3.0/lib/net40/" 25 | #r "../../packages/Microsoft.AspNet.Razor.2.0.30506.0/lib/net40/System.Web.Razor.dll" 26 | #r "../../packages/FAKE/tools/FakeLib.dll" 27 | #r "RazorEngine.dll" 28 | #r "FSharp.Literate.dll" 29 | #r "FSharp.CodeFormat.dll" 30 | #r "FSharp.MetadataFormat.dll" 31 | open Fake 32 | open System.IO 33 | open Fake.FileHelper 34 | open FSharp.Literate 35 | open FSharp.MetadataFormat 36 | 37 | // When called from 'build.fsx', use the public project URL as 38 | // otherwise, use the current 'output' directory. 39 | #if RELEASE 40 | let root = website 41 | #else 42 | let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output") 43 | #endif 44 | 45 | // Paths with template/source/output locations 46 | let bin = __SOURCE_DIRECTORY__ @@ "../../bin" 47 | let content = __SOURCE_DIRECTORY__ @@ "../content" 48 | let output = __SOURCE_DIRECTORY__ @@ "../output" 49 | let files = __SOURCE_DIRECTORY__ @@ "../files" 50 | let templates = __SOURCE_DIRECTORY__ @@ "templates" 51 | let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/FSharp.Formatting.2.2.11-beta/" 52 | let docTemplate = formatting @@ "templates/docpage.cshtml" 53 | 54 | // Where to look for *.csproj templates (in this order) 55 | let layoutRoots = 56 | [ templates; formatting @@ "templates" 57 | formatting @@ "templates/reference" ] 58 | 59 | // Copy static files and CSS + JS from F# Formatting 60 | let copyFiles () = 61 | CopyRecursive files output true |> Log "Copying file: " 62 | ensureDirectory (output @@ "content") 63 | CopyRecursive (formatting @@ "styles") (output @@ "content") true 64 | |> Log "Copying styles and scripts: " 65 | 66 | // Build API reference from XML comments 67 | let buildReference () = 68 | CleanDir (output @@ "reference") 69 | for lib in referenceBinaries do 70 | MetadataFormat.Generate 71 | ( bin @@ lib, output @@ "reference", layoutRoots, 72 | parameters = ("root", root)::info ) 73 | 74 | // Build documentation from `fsx` and `md` files in `docs/content` 75 | let buildDocumentation () = 76 | let subdirs = Directory.EnumerateDirectories(content, "*", SearchOption.AllDirectories) 77 | for dir in Seq.append [content] subdirs do 78 | let sub = if dir.Length > content.Length then dir.Substring(content.Length + 1) else "." 79 | Literate.ProcessDirectory 80 | ( dir, docTemplate, output @@ sub, replacements = ("root", root)::info, 81 | layoutRoots = layoutRoots ) 82 | 83 | // Generate 84 | copyFiles() 85 | buildDocumentation() 86 | buildReference() 87 | -------------------------------------------------------------------------------- /docs/tools/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/tools/templates/template.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | @Title 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 |
24 |
25 | 29 |

@Properties["project-name"]

30 |
31 |
32 |
33 |
34 | @RenderBody() 35 |
36 |
37 | 49 |
50 |
51 |
52 | Fork me on GitHub 53 | 54 | 55 | -------------------------------------------------------------------------------- /lib/Python.Runtime.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Interop.PythonProvider/0296a73dc18aaab21196ff577da69dd3e2ff6e86/lib/Python.Runtime.dll -------------------------------------------------------------------------------- /lib/python27.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Interop.PythonProvider/0296a73dc18aaab21196ff577da69dd3e2ff6e86/lib/python27.dll -------------------------------------------------------------------------------- /src/PythonDesignTimeProxy/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/PythonDesignTimeProxy/Program.fs: -------------------------------------------------------------------------------- 1 | namespace PythonTypeProvider.Server 2 | 3 | open Python 4 | open Python.Runtime 5 | open System 6 | open System.Diagnostics 7 | open FSharp.Interop 8 | 9 | type ModuleName = string 10 | type Doc = string option 11 | 12 | // Put the stuff that accesses Python in an app domain. The python code 13 | // seems to go scrpaing through all loaded DLLs looking for something, and this process triggers 14 | // exceptions when some dynamic assemblies are seen, e.g. when loaded in Visual Studio. Placing the 15 | // provider in an app domain fixes this. 16 | // 17 | // Eventually the provider should probably be placed in a 32-bit external process, the connection to this process 18 | // could also be done using .NET remoting, so it wouldn't be a big change from here. 19 | type PythonStaticInfoServer() = 20 | inherit MarshalByRefObject() 21 | 22 | let init = 23 | lazy 24 | PythonEngine.Initialize() 25 | // I don't fully understand why this call is needed, but without it no lock-releasing seems to happen 26 | //let nb = PythonEngine.BeginAllowThreads() 27 | //PythonEngine.EndAllowThreads(nb) 28 | System.AppDomain.CurrentDomain.DomainUnload.Add (fun _ -> Python.Runtime.PythonEngine.Shutdown()) 29 | 30 | let acquire() = 31 | init.Force() 32 | let n = PythonEngine.AcquireLock() 33 | { new System.IDisposable with member __.Dispose() = PythonEngine.ReleaseLock(n) } 34 | 35 | let runtime = Python.Runtime.Runtime() 36 | 37 | let (?) (pyObject: PyObject) (name: string) = pyObject.GetAttr name 38 | 39 | let (|Attr|_|) (name: string) (o: PyObject) = 40 | if o.HasAttr( name) 41 | then Some( o?name) 42 | else None 43 | 44 | let isbuiltin = 45 | let isbuiltinFunc = 46 | lazy 47 | use _lock = acquire() 48 | let builtin = PythonEngine.ImportModule("inspect") 49 | builtin ? isbuiltin 50 | fun(f: PyObject) -> isbuiltinFunc.Value.Invoke(f).IsTrue() 51 | 52 | let isfunction = 53 | let isFunctionFunc = 54 | lazy 55 | use _lock = acquire() 56 | let builtin = PythonEngine.ImportModule("inspect") 57 | builtin ? isfunction 58 | fun(f: PyObject) -> isFunctionFunc.Value.Invoke(f).IsTrue() 59 | 60 | let argsFromBuiltinDocs(name: string, doc: string) = 61 | let firstLine = doc.Split('\n').[0] 62 | let leftParent, rightParent = firstLine.IndexOf '(', firstLine.LastIndexOf ')' 63 | let length = rightParent - leftParent - 1 64 | //Debug.Assert( length > 0, sprintf "For function %s failed to parse doc string:\n %s" name doc) 65 | //assert ( length >= 0) 66 | doc.Substring(leftParent + 1, length).Split(',') |> Array.map (fun x -> x.Trim()) 67 | 68 | let argForFunction(func: PyObject) = 69 | use inpect = PythonEngine.ImportModule("inspect") 70 | let args = inpect.InvokeMethod("getargspec", func).GetAttr("args") 71 | [| for i = 0 to args.Length() - 1 do yield args.[i].ToString() |] 72 | 73 | // // Prevent the app domain from exiting, we keep it around forever. 74 | // // See http://stackoverflow.com/questions/2410221/appdomain-and-marshalbyrefobject-life-time-how-to-avoid-remotingexception 75 | // override __.InitializeLifetimeService() = null 76 | let sysModule = lazy Python.SysModule() 77 | 78 | member x.GetLoadedModulesInfo(workingFolder: string, import: string[]): (ModuleName * Doc)[] = 79 | try 80 | sysModule.Value.AppendToPath( workingFolder) 81 | import |> Array.iter (fun x -> 82 | PythonEngine.ImportModule x |> ignore 83 | ) 84 | [| for x in sysModule.Value.Modules() -> x.Name, Some x.Doc |] 85 | with ex -> 86 | let serializable = Exception(ex.Message) 87 | serializable.Data.Add("inner", string ex) 88 | raise serializable 89 | 90 | member __.GetModuleInfo(pyModuleName): (string * string * string[])[] = 91 | let m = sysModule.Value.Modules() |> Array.find(fun x -> x.Name = pyModuleName) 92 | m.Members 93 | |> Seq.map (fun (name, x) -> 94 | if x.HasAttr("__name__") 95 | then 96 | let args = 97 | if x.IsCallable() 98 | then 99 | try 100 | if x.IsBuiltIn 101 | then argsFromBuiltinDocs(x.Name, x.Doc) 102 | else argForFunction x 103 | with ex -> 104 | Debug.WriteLine(sprintf "Cannot parse args from doc for built-in function %s. Doc:\n%s" x.Name x.Doc) 105 | [| "params" |] 106 | else 107 | Array.empty 108 | 109 | name, x.Doc, args 110 | else 111 | name, null, Array.empty 112 | ) 113 | |> Seq.toArray 114 | 115 | member x.GetModuleInfo1(pyModuleName): (string * string * string[])[] = 116 | use _lock = acquire() 117 | use pyModule = PythonEngine.ImportModule(pyModuleName) 118 | use pyModuleItems = pyModule.Dir() 119 | [| for pyItem in pyModuleItems do 120 | use pyItemObj = pyModule.GetAttr( pyItem) 121 | let doc = 122 | match pyItemObj.HasAttr( "__doc__"), lazy pyItemObj.GetAttr( "__doc__") with 123 | | false, _ -> None 124 | | true, Lazy x when x.Repr() = "None" -> None 125 | | true, Lazy attr -> 126 | attr.ToString() |> Some 127 | 128 | let memberName = pyItem.ToString() 129 | 130 | let args = 131 | if pyItemObj.IsCallable() 132 | then 133 | match isbuiltin pyItemObj, doc with 134 | | true, Some docString -> argsFromBuiltinDocs(memberName, docString) 135 | | true, None -> [| "params" |] 136 | | false, _ -> 137 | if isfunction pyItemObj 138 | then argForFunction pyItemObj 139 | else Array.empty 140 | else 141 | Array.empty 142 | 143 | let doc = 144 | if memberName.Contains("built-in function") then 145 | use attr = pyItem.GetAttr("__doc__") 146 | attr.ToString() 147 | else 148 | if pyItemObj.HasAttr("__doc__") then 149 | use attr = pyItemObj.GetAttr("__doc__") 150 | attr.ToString() 151 | else 152 | null 153 | yield memberName, doc, args |] 154 | 155 | module Main = 156 | open System.Runtime.Remoting 157 | open System.Runtime.Remoting.Lifetime 158 | open System.Runtime.Remoting.Channels 159 | 160 | [] 161 | [] 162 | let main argv = 163 | 164 | let channelName = argv.[0] 165 | let chan = new Ipc.IpcChannel(channelName) 166 | //LifetimeServices.LeaseTime <- TimeSpan(7,0,0,0) // days,hours,mins,secs 167 | //LifetimeServices.LeaseManagerPollTime <- TimeSpan(7,0,0,0) 168 | //LifetimeServices.RenewOnCallTime <- TimeSpan(7,0,0,0) 169 | //LifetimeServices.SponsorshipTimeout <- TimeSpan(7,0,0,0) 170 | ChannelServices.RegisterChannel(chan,false) 171 | 172 | let server = new PythonStaticInfoServer() 173 | let objRef = RemotingServices.Marshal(server,"PythonStaticInfoServer") 174 | RemotingConfiguration.RegisterActivatedServiceType(typeof) 175 | 176 | printfn "%s started." channelName 177 | 178 | let parentPid = channelName.Split('_').[1] 179 | let parentProcess = Process.GetProcessById(int parentPid) 180 | parentProcess.WaitForExit() 181 | 0 // return an integer exit code 182 | -------------------------------------------------------------------------------- /src/PythonDesignTimeProxy/PythonProvider.TypesDiscoveryServer.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | f5932d2f-eb19-45b6-961d-01acf9e086bd 9 | Exe 10 | PythonTypeProviderProxy 11 | PythonProvider.TypesDiscoveryServer 12 | v4.0 13 | PythonProvider.TypesDiscoveryServer 14 | 4.3.1.0 15 | 16 | 17 | true 18 | full 19 | false 20 | false 21 | ..\..\bin 22 | DEBUG;TRACE 23 | 3 24 | x86 25 | 26 | 27 | true 28 | 29 | 30 | PythonStaticInfoServer_27788_2015065968_366086954 31 | 32 | 33 | pdbonly 34 | true 35 | true 36 | ..\..\bin 37 | TRACE 38 | 3 39 | x86 40 | ..\..\bin\PythonTypeProviderProxy.XML 41 | true 42 | --target:winexe 43 | 44 | 45 | 46 | True 47 | 48 | 49 | 50 | ..\..\pythonnet\src\runtime\bin\x86\DebugWin\Python.Runtime.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | PythonProvider.Runtime 64 | {ad4d91af-3c95-485b-a141-b67a9c97cc4d} 65 | True 66 | 67 | 68 | 69 | 11 70 | 71 | 72 | 73 | 74 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 75 | 76 | 77 | 78 | 79 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 80 | 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/DebugProvidedTypes.fs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // Helpers for writing type providers 3 | // ---------------------------------------------------------------------------------------------- 4 | 5 | namespace ProviderImplementation 6 | 7 | open System 8 | open System.Collections.Generic 9 | open System.Reflection 10 | open System.Text 11 | open Microsoft.FSharp.Core.CompilerServices 12 | open Microsoft.FSharp.Core.Printf 13 | open Microsoft.FSharp.Quotations 14 | open Microsoft.FSharp.Quotations.Patterns 15 | open Microsoft.FSharp.Reflection 16 | open ProviderImplementation.ProvidedTypes 17 | 18 | module internal Debug = 19 | 20 | /// Converts a sequence of strings to a single string separated with the delimiters 21 | let inline private separatedBy delimiter (items: string seq) = String.Join(delimiter, Array.ofSeq items) 22 | 23 | /// Simulates a real instance of TypeProviderConfig and then creates an instance of the last 24 | /// type provider added to a namespace by the type provider constructor 25 | let generate (resolutionFolder: string) (runtimeAssembly: string) typeProviderForNamespacesConstructor args = 26 | 27 | let cfg = new TypeProviderConfig(fun _ -> false) 28 | let (?<-) cfg prop value = 29 | cfg.GetType().GetProperty(prop).GetSetMethod(nonPublic = true).Invoke(cfg, [| box value |]) |> ignore 30 | cfg?ResolutionFolder <- resolutionFolder 31 | cfg?RuntimeAssembly <- runtimeAssembly 32 | cfg?ReferencedAssemblies <- Array.zeroCreate 0 33 | 34 | let typeProviderForNamespaces = typeProviderForNamespacesConstructor cfg :> TypeProviderForNamespaces 35 | 36 | let providedTypeDefinition = typeProviderForNamespaces.Namespaces |> Seq.last |> snd |> Seq.last 37 | 38 | match args with 39 | | [||] -> providedTypeDefinition 40 | | args -> 41 | // I found a prefixed "Debug" to be more useful than combining the name using the static parameters 42 | // The type name ends up quite mangled in the dll output if you choose to use that to aid debugging. 43 | // let typeName = providedTypeDefinition.Name + (args |> Seq.map (fun s -> ",\"" + (if s = null then "" else s.ToString()) + "\"") |> Seq.reduce (+)) 44 | let typeName = "Debug" + providedTypeDefinition.Name 45 | providedTypeDefinition.MakeParametricType(typeName, args) 46 | 47 | /// Returns a string representation of the signature (and optionally also the body) of all the 48 | /// types generated by the type provider up to a certain depth and width 49 | /// If ignoreOutput is true, this will still visit the full graph, but it will output an empty string to be faster 50 | let prettyPrint signatureOnly ignoreOutput maxDepth maxWidth (t: ProvidedTypeDefinition) = 51 | 52 | let ns = 53 | [ t.Namespace 54 | "Microsoft.FSharp.Core" 55 | "Microsoft.FSharp.Core.Operators" 56 | "Microsoft.FSharp.Collections" 57 | "Microsoft.FSharp.Control" 58 | "Microsoft.FSharp.Text" ] 59 | |> Set.ofSeq 60 | 61 | let pending = new Queue<_>() 62 | let visited = new HashSet<_>() 63 | 64 | let add t = 65 | if visited.Add t then 66 | pending.Enqueue t 67 | 68 | let fullName (t: Type) = 69 | let fullName = t.Namespace + "." + t.Name 70 | if fullName.StartsWith "FSI_" then 71 | fullName.Substring(fullName.IndexOf('.') + 1) 72 | else 73 | fullName 74 | 75 | let rec toString useFullName (t: Type) = 76 | 77 | if t = null then 78 | "" // happens in the Freebase provider 79 | else 80 | 81 | let hasUnitOfMeasure = t.Name.Contains("[") 82 | 83 | let innerToString (t: Type) = 84 | match t with 85 | | t when t = typeof -> "bool" 86 | | t when t = typeof -> "obj" 87 | | t when t = typeof -> "int" 88 | | t when t = typeof -> "int64" 89 | | t when t = typeof -> "float" 90 | | t when t = typeof -> "float32" 91 | | t when t = typeof -> "decimal" 92 | | t when t = typeof -> "string" 93 | | t when t = typeof -> "()" 94 | | t when t = typeof -> "()" 95 | | t when t.IsArray -> (t.GetElementType() |> toString useFullName) + "[]" 96 | | :? ProvidedTypeDefinition as t -> 97 | add t 98 | t.Name.Split(',').[0] 99 | | t when t.IsGenericType -> 100 | let args = 101 | if useFullName then 102 | t.GetGenericArguments() 103 | |> Seq.map (if hasUnitOfMeasure then (fun t -> t.Name) else toString useFullName) 104 | else 105 | t.GetGenericArguments() 106 | |> Seq.map (fun _ -> "_") 107 | if FSharpType.IsTuple t then 108 | separatedBy " * " args 109 | elif t.Name.StartsWith "FSharpFunc`" then 110 | "(" + separatedBy " -> " args + ")" 111 | else 112 | let args = separatedBy "," args 113 | let name, reverse = 114 | match t with 115 | | t when hasUnitOfMeasure -> toString useFullName t.UnderlyingSystemType, false 116 | | t when t.GetGenericTypeDefinition().Name = typeof.GetGenericTypeDefinition().Name -> "seq", true 117 | | t when t.GetGenericTypeDefinition().Name = typeof.GetGenericTypeDefinition().Name -> "list", true 118 | | t when t.GetGenericTypeDefinition().Name = typeof.GetGenericTypeDefinition().Name -> "option", true 119 | | t when t.GetGenericTypeDefinition().Name = typeof.GetGenericTypeDefinition().Name -> "ref", true 120 | | t when t.Name = "FSharpAsync`1" -> "async", true 121 | | t when ns.Contains t.Namespace -> t.Name, false 122 | | t -> (if useFullName then fullName t else t.Name), false 123 | let name = name.Split('`').[0] 124 | if reverse then 125 | args + " " + name 126 | else 127 | name + "<" + args + ">" 128 | | t when ns.Contains t.Namespace -> t.Name 129 | | t when t.IsGenericParameter -> t.Name 130 | | t -> if useFullName then fullName t else t.Name 131 | 132 | let rec warnIfWrongAssembly (t:Type) = 133 | match t with 134 | | :? ProvidedTypeDefinition -> "" 135 | | t when t.IsGenericType -> defaultArg (t.GetGenericArguments() |> Seq.map warnIfWrongAssembly |> Seq.tryFind (fun s -> s <> "")) "" 136 | | t when t.IsArray -> warnIfWrongAssembly <| t.GetElementType() 137 | | t -> if not t.IsGenericParameter && t.Assembly = Assembly.GetExecutingAssembly() then " [DESIGNTIME]" else "" 138 | 139 | if ignoreOutput then 140 | "" 141 | elif hasUnitOfMeasure || t.IsGenericParameter || t.DeclaringType = null then 142 | innerToString t + (warnIfWrongAssembly t) 143 | else 144 | (toString useFullName t.DeclaringType) + "+" + (innerToString t) + (warnIfWrongAssembly t) 145 | 146 | let toSignature (parameters: ParameterInfo[]) = 147 | if parameters.Length = 0 then 148 | "()" 149 | else 150 | parameters 151 | |> Seq.map (fun p -> p.Name + ":" + (toString true p.ParameterType)) 152 | |> separatedBy " -> " 153 | 154 | let printExpr expr = 155 | 156 | let sb = StringBuilder () 157 | let print (str:string) = sb.Append(str) |> ignore 158 | 159 | let getCurrentIndent() = 160 | let lastEnterPos = sb.ToString().LastIndexOf('\n') 161 | if lastEnterPos = -1 then sb.Length + 4 else sb.Length - lastEnterPos - 1 162 | 163 | let breakLine indent = 164 | print "\n" 165 | print (new String(' ', indent)) 166 | 167 | let isBigExpression = function 168 | | Let _ | NewArray _ | NewTuple _ -> true 169 | | _ -> false 170 | 171 | let inline getAttrs attrName m = 172 | ( ^a : (member GetCustomAttributesData : unit -> IList) m) 173 | |> Seq.filter (fun attr -> attr.Constructor.DeclaringType.Name = attrName) 174 | 175 | let inline hasAttr attrName m = 176 | not (Seq.isEmpty (getAttrs attrName m)) 177 | 178 | let rec printSeparatedByCommas exprs = 179 | match exprs with 180 | | [] -> () 181 | | e::es -> 182 | printExpr false true e 183 | for e in es do 184 | print ", " 185 | printExpr false true e 186 | 187 | and printCall fromPipe printName (mi:MethodInfo) args = 188 | if fromPipe && List.length args = 1 then 189 | printName() 190 | elif not (hasAttr "CompilationArgumentCountsAttribute" mi) then 191 | printName() 192 | match args with 193 | | [] -> print "()" 194 | | arg::args -> 195 | print "(" 196 | let indent = getCurrentIndent() 197 | printExpr false true arg 198 | for arg in args do 199 | print ", " 200 | if isBigExpression arg then 201 | breakLine indent 202 | printExpr false true arg 203 | print ")" 204 | else 205 | print "(" 206 | printName() 207 | for arg in args do 208 | print " " 209 | printExpr false true arg 210 | print ")" 211 | 212 | and printExpr fromPipe needsParens = function 213 | | Call (instance, mi, args) -> 214 | if mi.Name = "GetArray" && mi.DeclaringType.FullName = "Microsoft.FSharp.Core.LanguagePrimitives+IntrinsicFunctions" then 215 | printExpr false true args.Head 216 | print ".[" 217 | printExpr false true args.Tail.Head 218 | print "]" 219 | elif mi.DeclaringType.IsGenericType && mi.DeclaringType.GetGenericTypeDefinition().Name = typeof.GetGenericTypeDefinition().Name then 220 | if args.IsEmpty then 221 | match instance with 222 | | None -> print "None" 223 | | Some instance -> 224 | printExpr false true instance 225 | print "." 226 | print <| mi.Name.Substring("get_".Length) 227 | else 228 | print "Some " 229 | printExpr false true args.Head 230 | elif mi.Name.Contains "." && not args.IsEmpty then 231 | // instance method in type extension 232 | let printName() = 233 | printExpr false true args.Head 234 | print "." 235 | print (mi.Name.Substring(mi.Name.IndexOf '.' + 1)) 236 | printCall fromPipe printName mi args.Tail 237 | elif mi.Attributes &&& MethodAttributes.SpecialName = MethodAttributes.SpecialName && mi.Name.StartsWith "get_" && args.IsEmpty then 238 | // property get 239 | match instance with 240 | | Some expr -> printExpr false true expr 241 | | None -> print (toString false mi.DeclaringType) 242 | print "." 243 | print <| mi.Name.Substring("get_".Length) 244 | elif mi.Name = "op_PipeRight" && args.Length = 2 then 245 | printExpr false false args.Head 246 | print " |> " 247 | match args.Tail.Head with 248 | | Lambda (_, (Call(_,_,_) as call)) -> printExpr true false call 249 | | _ as expr -> printExpr false false expr 250 | else 251 | let printName() = 252 | match instance with 253 | | Some expr -> printExpr false true expr 254 | | None -> print (toString false mi.DeclaringType) 255 | print "." 256 | print mi.Name 257 | let isOptional (arg:Expr, param:ParameterInfo) = 258 | hasAttr "OptionalArgumentAttribute" param 259 | && arg.ToString() = "Call (None, get_None, [])" 260 | let args = 261 | mi.GetParameters() 262 | |> List.ofArray 263 | |> List.zip args 264 | |> List.filter (not << isOptional) 265 | |> List.map fst 266 | printCall fromPipe printName mi args 267 | | Let (var1, TupleGet (Var x, 1), Let (var2, TupleGet (Var y, 0), body)) when x = y -> 268 | let indent = getCurrentIndent() 269 | bprintf sb "let %s, %s = %s" var2.Name var1.Name x.Name 270 | breakLine indent 271 | printExpr false false body 272 | | Let (var, value, body) -> 273 | let indent = getCurrentIndent() 274 | let usePattern = sprintf "IfThenElse(TypeTest(IDisposable,Coerce(%s,Object)),Call(Some(Call(None,UnboxGeneric,[Coerce(%s,Object)])),Dispose,[]),Value())" var.Name var.Name 275 | let body = 276 | match body with 277 | | TryFinally (tryExpr, finallyExpr) when finallyExpr.ToString().Replace("\n", null).Replace(" ", null) = usePattern -> 278 | bprintf sb "use %s = " var.Name 279 | tryExpr 280 | | _ -> 281 | if var.IsMutable then 282 | bprintf sb "let mutable %s = " var.Name 283 | else 284 | bprintf sb "let %s = " var.Name 285 | body 286 | match value with 287 | | Let _ -> 288 | breakLine (indent + 4) 289 | printExpr false false value 290 | | _ -> printExpr false false value 291 | breakLine indent 292 | printExpr false false body 293 | | Value (null, _) -> 294 | print "null" 295 | | Value (value, typ) when typ = typeof && (value :?> string).Contains("\\") -> 296 | bprintf sb "@%A" value 297 | | Value (value, _) -> 298 | bprintf sb "%A" value 299 | | Var (var) -> 300 | print var.Name 301 | | NewObject (ci, args) -> 302 | let getSourceConstructFlags (attr:CustomAttributeData) = 303 | let arg = attr.ConstructorArguments 304 | |> Seq.filter (fun arg -> arg.ArgumentType.Name = "SourceConstructFlags") 305 | |> Seq.head 306 | arg.Value :?> int 307 | let compilationMappings = getAttrs "CompilationMappingAttribute" ci.DeclaringType 308 | if not (Seq.isEmpty compilationMappings) && (getSourceConstructFlags (Seq.head compilationMappings)) = int SourceConstructFlags.RecordType then 309 | print "{ " 310 | let indent = getCurrentIndent() 311 | let recordFields = FSharpType.GetRecordFields(ci.DeclaringType) 312 | args |> List.iteri (fun i arg -> 313 | if i > 0 then 314 | breakLine indent 315 | print recordFields.[i].Name 316 | print " = " 317 | printExpr false false arg) 318 | print " }" 319 | else 320 | print "(new " 321 | print (toString false ci.DeclaringType) 322 | print "(" 323 | printSeparatedByCommas args 324 | print "))" 325 | | NewDelegate (typ, vars, expr) -> 326 | print "new " 327 | print (toString false typ) 328 | match expr with 329 | | Var v when not vars.IsEmpty && vars.Tail.IsEmpty && vars.Head = v -> print "(id)" 330 | | _ -> 331 | let indent = getCurrentIndent() 332 | if vars.IsEmpty then 333 | print "(fun () -> " 334 | else 335 | print "(fun" 336 | for var in vars do 337 | bprintf sb " (%s:%s)" var.Name (toString false var.Type) 338 | print " -> " 339 | if isBigExpression expr then 340 | breakLine (indent + 4) 341 | printExpr false false expr 342 | else 343 | printExpr false false expr 344 | print ")" 345 | | NewTuple (exprs) -> 346 | if needsParens then print "(" 347 | let indent = getCurrentIndent() 348 | printExpr false true exprs.Head 349 | for e in exprs.Tail do 350 | print "," 351 | breakLine indent 352 | printExpr false true e 353 | if needsParens then print ")" 354 | | NewArray (_, exprs) -> 355 | if exprs.Length = 0 then print "[| |]" 356 | else 357 | print "[| " 358 | let indent = getCurrentIndent() 359 | printExpr false true exprs.Head 360 | for e in exprs.Tail do 361 | breakLine indent 362 | printExpr false true e 363 | print " |]" 364 | | Coerce (expr, typ) -> 365 | print "(" 366 | printExpr false false expr 367 | print " :> " 368 | print (toString false typ) 369 | print ")" 370 | | TupleGet (expr, index) -> 371 | print "(let " 372 | let rec getTupleLength (typ:Type) = 373 | let length = typ.GetGenericArguments().Length 374 | if length = 0 then // happens in the Apiary provider 375 | let typeNameSuffix = typ.Name.Substring(typ.Name.IndexOf('`') + 1) 376 | typeNameSuffix.Substring(0, typeNameSuffix.IndexOf('[')) |> Int32.Parse 377 | else 378 | let lastItem = typ.GetGenericArguments() |> Seq.last 379 | if lastItem.Name.StartsWith "Tuple`" 380 | then length + getTupleLength lastItem - 1 381 | else length 382 | let tupleLength = getTupleLength expr.Type 383 | let varName = "t" + (string (index + 1)) 384 | for i in 0..tupleLength-1 do 385 | if i = index then 386 | print varName 387 | else 388 | print "_" 389 | if i <> tupleLength-1 then 390 | print "," 391 | print " = " 392 | printExpr false false expr 393 | print (" in " + varName + ")") 394 | | expr -> print (expr.ToString()) 395 | 396 | printExpr false false expr 397 | sb.ToString() 398 | 399 | let sb = StringBuilder () 400 | 401 | let print (str: string) = 402 | if not ignoreOutput then 403 | sb.Append(str) |> ignore 404 | 405 | let println() = 406 | if not ignoreOutput then 407 | sb.AppendLine() |> ignore 408 | 409 | let printMember (memberInfo: MemberInfo) = 410 | 411 | let print str = 412 | print " " 413 | print str 414 | println() 415 | 416 | let getMethodBody (m: ProvidedMethod) = 417 | seq { if not m.IsStatic then yield (ProvidedTypeDefinition.EraseType m.DeclaringType) 418 | for param in m.GetParameters() do yield (ProvidedTypeDefinition.EraseType param.ParameterType) } 419 | |> Seq.map (fun typ -> Expr.Value(null, typ)) 420 | |> Array.ofSeq 421 | |> m.GetInvokeCodeInternal false 422 | 423 | let getConstructorBody (c: ProvidedConstructor) = 424 | if c.IsImplicitCtor then Expr.Value(()) else 425 | seq { for param in c.GetParameters() do yield (ProvidedTypeDefinition.EraseType param.ParameterType) } 426 | |> Seq.map (fun typ -> Expr.Value(null, typ)) 427 | |> Array.ofSeq 428 | |> c.GetInvokeCodeInternal false 429 | 430 | let printExpr x = 431 | if not ignoreOutput then 432 | let rec removeParams x = 433 | match x with 434 | | Let (_, Value(null, _), body) -> removeParams body 435 | | _ -> x 436 | let formattedExpr = printExpr (removeParams x) 437 | print formattedExpr 438 | println() 439 | 440 | let printObj x = 441 | if ignoreOutput then 442 | "" 443 | else 444 | sprintf "\n%O\n" x 445 | 446 | match memberInfo with 447 | 448 | | :? ProvidedConstructor as cons -> 449 | if not ignoreOutput then 450 | print <| "new : " + 451 | (toSignature <| cons.GetParameters()) + " -> " + 452 | (toString true memberInfo.DeclaringType) 453 | if not signatureOnly then 454 | cons |> getConstructorBody |> printExpr 455 | 456 | | :? ProvidedLiteralField as field -> 457 | let value = 458 | if signatureOnly then "" 459 | else field.GetRawConstantValue() |> printObj 460 | if not ignoreOutput then 461 | print <| "val " + field.Name + ": " + 462 | (toString true field.FieldType) + 463 | value 464 | 465 | | :? ProvidedProperty as prop -> 466 | if not ignoreOutput then 467 | print <| (if prop.IsStatic then "static " else "") + "member " + 468 | prop.Name + ": " + (toString true prop.PropertyType) + 469 | " with " + (if prop.CanRead && prop.CanWrite then "get, set" else if prop.CanRead then "get" else "set") 470 | if not signatureOnly then 471 | if prop.CanRead then 472 | getMethodBody (prop.GetGetMethod() :?> ProvidedMethod) |> printExpr 473 | if prop.CanWrite then 474 | getMethodBody (prop.GetSetMethod() :?> ProvidedMethod) |> printExpr 475 | 476 | | :? ProvidedMethod as m -> 477 | if m.Attributes &&& MethodAttributes.SpecialName <> MethodAttributes.SpecialName then 478 | if not ignoreOutput then 479 | print <| (if m.IsStatic then "static " else "") + "member " + 480 | m.Name + ": " + (toSignature <| m.GetParameters()) + 481 | " -> " + (toString true m.ReturnType) 482 | if not signatureOnly then 483 | m |> getMethodBody |> printExpr 484 | 485 | | _ -> () 486 | 487 | add t 488 | 489 | let currentDepth = ref 0 490 | 491 | while pending.Count <> 0 && !currentDepth <= maxDepth do 492 | let pendingForThisDepth = new List<_>(pending) 493 | pending.Clear() 494 | let pendingForThisDepth = 495 | pendingForThisDepth 496 | |> Seq.sortBy (fun m -> m.Name) 497 | |> Seq.truncate maxWidth 498 | for t in pendingForThisDepth do 499 | match t with 500 | | t when FSharpType.IsRecord t-> "record " 501 | | t when FSharpType.IsModule t -> "module " 502 | | t when t.IsValueType -> "struct " 503 | | t when t.IsClass && t.IsSealed && t.IsAbstract -> "static class " 504 | | t when t.IsClass && t.IsAbstract -> "abstract class " 505 | | t when t.IsClass -> "class " 506 | | _ -> "" 507 | |> print 508 | print (toString true t) 509 | if t.BaseType <> typeof then 510 | print " : " 511 | print (toString true t.BaseType) 512 | println() 513 | t.GetMembers() 514 | |> Seq.sortBy (fun m -> m.Name) 515 | |> Seq.iter printMember 516 | println() 517 | currentDepth := !currentDepth + 1 518 | 519 | sb.ToString() 520 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/ProvidedTypes.fsi: -------------------------------------------------------------------------------- 1 | // Based on code developed for the F# 3.0 Beta release of March 2012, 2 | // Copyright (c) Microsoft Corporation 2005-2012. 3 | // This sample code is provided "as is" without warranty of any kind. 4 | // We disclaim all warranties, either express or implied, including the 5 | // warranties of merchantability and fitness for a particular purpose. 6 | 7 | // This file contains a set of helper types and methods for providing types in an implementation 8 | // of ITypeProvider. 9 | 10 | // This code has been modified and is appropriate for use in conjunction with the F# 3.0, F# 3.1, and F# 3.1.1 releases 11 | 12 | 13 | namespace ProviderImplementation.ProvidedTypes 14 | 15 | open System 16 | open System.Reflection 17 | open System.Linq.Expressions 18 | open Microsoft.FSharp.Core.CompilerServices 19 | 20 | /// Represents an erased provided parameter 21 | type ProvidedParameter = 22 | inherit System.Reflection.ParameterInfo 23 | new : parameterName: string * parameterType: Type * ?isOut:bool * ?optionalValue:obj -> ProvidedParameter 24 | member IsParamArray : bool with get,set 25 | 26 | /// Represents an erased provided constructor. 27 | type ProvidedConstructor = 28 | inherit System.Reflection.ConstructorInfo 29 | 30 | /// Create a new provided constructor. It is not initially associated with any specific provided type definition. 31 | new : parameters: ProvidedParameter list -> ProvidedConstructor 32 | 33 | /// Add a 'System.Obsolete' attribute to this provided constructor 34 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 35 | 36 | /// Add XML documentation information to this provided constructor 37 | member AddXmlDoc : xmlDoc: string -> unit 38 | 39 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 40 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 41 | 42 | /// Add XML documentation information to this provided constructor, where the documentation is re-computed every time it is required. 43 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 44 | 45 | /// Set the quotation used to compute the implementation of invocations of this constructor. 46 | member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set 47 | 48 | /// FSharp.Data addition: this method is used by Debug.fs 49 | member internal GetInvokeCodeInternal : bool -> (Quotations.Expr [] -> Quotations.Expr) 50 | 51 | /// Set the target and arguments of the base constructor call. Only used for generated types. 52 | member BaseConstructorCall : (Quotations.Expr list -> ConstructorInfo * Quotations.Expr list) with set 53 | 54 | /// Set a flag indicating that the constructor acts like an F# implicit constructor, so the 55 | /// parameters of the constructor become fields and can be accessed using Expr.GlobalVar with the 56 | /// same name. 57 | member IsImplicitCtor : bool with get,set 58 | 59 | /// Add definition location information to the provided constructor. 60 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 61 | 62 | member IsTypeInitializer : bool with get,set 63 | 64 | type ProvidedMethod = 65 | inherit System.Reflection.MethodInfo 66 | 67 | /// Create a new provided method. It is not initially associated with any specific provided type definition. 68 | new : methodName:string * parameters: ProvidedParameter list * returnType: Type -> ProvidedMethod 69 | 70 | /// Add XML documentation information to this provided method 71 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 72 | 73 | /// Add XML documentation information to this provided constructor 74 | member AddXmlDoc : xmlDoc: string -> unit 75 | 76 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 77 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 78 | 79 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 80 | /// The documentation is re-computed every time it is required. 81 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 82 | 83 | member AddMethodAttrs : attributes:MethodAttributes -> unit 84 | 85 | /// Set the method attributes of the method. By default these are simple 'MethodAttributes.Public' 86 | member SetMethodAttrs : attributes:MethodAttributes -> unit 87 | 88 | /// Get or set a flag indicating if the property is static. 89 | member IsStaticMethod : bool with get, set 90 | 91 | /// Set the quotation used to compute the implementation of invocations of this method. 92 | member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set 93 | 94 | /// FSharp.Data addition: this method is used by Debug.fs 95 | member internal GetInvokeCodeInternal : bool -> (Quotations.Expr [] -> Quotations.Expr) 96 | 97 | /// Add definition location information to the provided type definition. 98 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 99 | 100 | /// Add a custom attribute to the provided method definition. 101 | member AddCustomAttribute : CustomAttributeData -> unit 102 | 103 | 104 | 105 | /// Represents an erased provided property. 106 | type ProvidedProperty = 107 | inherit System.Reflection.PropertyInfo 108 | 109 | /// Create a new provided type. It is not initially associated with any specific provided type definition. 110 | new : propertyName: string * propertyType: Type * ?parameters:ProvidedParameter list -> ProvidedProperty 111 | 112 | /// Add a 'System.Obsolete' attribute to this provided property 113 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 114 | 115 | /// Add XML documentation information to this provided constructor 116 | member AddXmlDoc : xmlDoc: string -> unit 117 | 118 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 119 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 120 | 121 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 122 | /// The documentation is re-computed every time it is required. 123 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 124 | 125 | /// Get or set a flag indicating if the property is static. 126 | /// FSharp.Data addition: the getter is used by Debug.fs 127 | member IsStatic : bool with get,set 128 | 129 | /// Set the quotation used to compute the implementation of gets of this property. 130 | member GetterCode : (Quotations.Expr list -> Quotations.Expr) with set 131 | 132 | /// Set the function used to compute the implementation of sets of this property. 133 | member SetterCode : (Quotations.Expr list -> Quotations.Expr) with set 134 | 135 | /// Add definition location information to the provided type definition. 136 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 137 | 138 | /// Add a custom attribute to the provided property definition. 139 | member AddCustomAttribute : CustomAttributeData -> unit 140 | 141 | /// Represents an erased provided property. 142 | type ProvidedEvent = 143 | inherit System.Reflection.EventInfo 144 | 145 | /// Create a new provided type. It is not initially associated with any specific provided type definition. 146 | new : propertyName: string * eventHandlerType: Type -> ProvidedEvent 147 | 148 | /// Add XML documentation information to this provided constructor 149 | member AddXmlDoc : xmlDoc: string -> unit 150 | 151 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 152 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 153 | 154 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 155 | /// The documentation is re-computed every time it is required. 156 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 157 | 158 | /// Get or set a flag indicating if the property is static. 159 | member IsStatic : bool with set 160 | 161 | /// Set the quotation used to compute the implementation of gets of this property. 162 | member AdderCode : (Quotations.Expr list -> Quotations.Expr) with set 163 | 164 | /// Set the function used to compute the implementation of sets of this property. 165 | member RemoverCode : (Quotations.Expr list -> Quotations.Expr) with set 166 | 167 | /// Add definition location information to the provided type definition. 168 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 169 | 170 | /// Represents an erased provided field. 171 | type ProvidedLiteralField = 172 | inherit System.Reflection.FieldInfo 173 | 174 | /// Create a new provided field. It is not initially associated with any specific provided type definition. 175 | new : fieldName: string * fieldType: Type * literalValue: obj -> ProvidedLiteralField 176 | 177 | /// Add a 'System.Obsolete' attribute to this provided field 178 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 179 | 180 | /// Add XML documentation information to this provided field 181 | member AddXmlDoc : xmlDoc: string -> unit 182 | 183 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 184 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 185 | 186 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 187 | /// The documentation is re-computed every time it is required. 188 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 189 | 190 | /// Add definition location information to the provided field. 191 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 192 | 193 | /// Represents an erased provided field. 194 | type ProvidedField = 195 | inherit System.Reflection.FieldInfo 196 | 197 | /// Create a new provided field. It is not initially associated with any specific provided type definition. 198 | new : fieldName: string * fieldType: Type -> ProvidedField 199 | 200 | /// Add a 'System.Obsolete' attribute to this provided field 201 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 202 | 203 | /// Add XML documentation information to this provided field 204 | member AddXmlDoc : xmlDoc: string -> unit 205 | 206 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 207 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 208 | 209 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 210 | /// The documentation is re-computed every time it is required. 211 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 212 | 213 | /// Add definition location information to the provided field definition. 214 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 215 | 216 | member SetFieldAttributes : attributes : FieldAttributes -> unit 217 | 218 | /// FSharp.Data addition: SymbolKind is used by AssemblyReplacer.fs 219 | /// Represents the type constructor in a provided symbol type. 220 | [] 221 | type SymbolKind = 222 | | SDArray 223 | | Array of int 224 | | Pointer 225 | | ByRef 226 | | Generic of System.Type 227 | | FSharpTypeAbbreviation of (System.Reflection.Assembly * string * string[]) 228 | 229 | /// FSharp.Data addition: ProvidedSymbolType is used by AssemblyReplacer.fs 230 | /// Represents an array or other symbolic type involving a provided type as the argument. 231 | /// See the type provider spec for the methods that must be implemented. 232 | /// Note that the type provider specification does not require us to implement pointer-equality for provided types. 233 | [] 234 | type ProvidedSymbolType = 235 | inherit System.Type 236 | 237 | /// Returns the kind of this symbolic type 238 | member Kind : SymbolKind 239 | /// Return the provided types used as arguments of this symbolic type 240 | member Args : list 241 | 242 | 243 | /// Provides symbolic provided types 244 | [] 245 | type ProvidedTypeBuilder = 246 | /// Like typ.MakeGenericType, but will also work with unit-annotated types 247 | static member MakeGenericType: genericTypeDefinition: System.Type * genericArguments: System.Type list -> System.Type 248 | /// Like methodInfo.MakeGenericMethod, but will also work with unit-annotated types and provided types 249 | static member MakeGenericMethod: genericMethodDefinition: System.Reflection.MethodInfo * genericArguments: System.Type list -> MethodInfo 250 | 251 | /// Helps create erased provided unit-of-measure annotations. 252 | [] 253 | type ProvidedMeasureBuilder = 254 | 255 | /// The ProvidedMeasureBuilder for building measures. 256 | static member Default : ProvidedMeasureBuilder 257 | 258 | /// e.g. 1 259 | member One : System.Type 260 | /// e.g. m * kg 261 | member Product : measure1: System.Type * measure1: System.Type -> System.Type 262 | /// e.g. 1 / kg 263 | member Inverse : denominator: System.Type -> System.Type 264 | 265 | /// e.g. kg / m 266 | member Ratio : numerator: System.Type * denominator: System.Type -> System.Type 267 | 268 | /// e.g. m * m 269 | member Square : ``measure``: System.Type -> System.Type 270 | 271 | /// the SI unit from the F# core library, where the string is in capitals and US spelling, e.g. Meter 272 | member SI : string -> System.Type 273 | 274 | /// e.g. float, Vector 275 | member AnnotateType : basic: System.Type * argument: System.Type list -> System.Type 276 | 277 | 278 | /// Represents a provided static parameter. 279 | type ProvidedStaticParameter = 280 | inherit System.Reflection.ParameterInfo 281 | new : parameterName: string * parameterType:Type * ?parameterDefaultValue:obj -> ProvidedStaticParameter 282 | 283 | /// Add XML documentation information to this provided constructor 284 | member AddXmlDoc : xmlDoc: string -> unit 285 | 286 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 287 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 288 | 289 | /// Represents a provided type definition. 290 | type ProvidedTypeDefinition = 291 | inherit System.Type 292 | 293 | /// Create a new provided type definition in a namespace. 294 | new : assembly: Assembly * namespaceName: string * className: string * baseType: Type option -> ProvidedTypeDefinition 295 | 296 | /// Create a new provided type definition, to be located as a nested type in some type definition. 297 | new : className : string * baseType: Type option -> ProvidedTypeDefinition 298 | 299 | /// Add the given type as an implemented interface. 300 | member AddInterfaceImplementation : interfaceType: Type -> unit 301 | 302 | /// Add the given function as a set of on-demand computed interfaces. 303 | member AddInterfaceImplementationsDelayed : interfacesFunction:(unit -> Type list)-> unit 304 | 305 | /// Specifies that the given method body implements the given method declaration. 306 | member DefineMethodOverride : methodInfoBody: ProvidedMethod * methodInfoDeclaration: MethodInfo -> unit 307 | 308 | /// Add a 'System.Obsolete' attribute to this provided type definition 309 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 310 | 311 | /// Add XML documentation information to this provided constructor 312 | member AddXmlDoc : xmlDoc: string -> unit 313 | 314 | /// Set the base type 315 | member SetBaseType : Type -> unit 316 | 317 | /// Set the base type to a lazily evaluated value 318 | member SetBaseTypeDelayed : Lazy -> unit 319 | 320 | /// Set underlying type for generated enums 321 | member SetEnumUnderlyingType : Type -> unit 322 | 323 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary. 324 | /// The documentation is only computed once. 325 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 326 | 327 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 328 | /// The documentation is re-computed every time it is required. 329 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 330 | 331 | /// Set the attributes on the provided type. This fully replaces the default TypeAttributes. 332 | member SetAttributes : System.Reflection.TypeAttributes -> unit 333 | 334 | /// Reset the enclosing type (for generated nested types) 335 | member ResetEnclosingType: enclosingType:System.Type -> unit 336 | 337 | /// Add a method, property, nested type or other member to a ProvidedTypeDefinition 338 | member AddMember : memberInfo:MemberInfo -> unit 339 | /// Add a set of members to a ProvidedTypeDefinition 340 | member AddMembers : memberInfos:list<#MemberInfo> -> unit 341 | 342 | /// Add a member to a ProvidedTypeDefinition, delaying computation of the members until required by the compilation context. 343 | member AddMemberDelayed : memberFunction:(unit -> #MemberInfo) -> unit 344 | 345 | /// Add a set of members to a ProvidedTypeDefinition, delaying computation of the members until required by the compilation context. 346 | member AddMembersDelayed : (unit -> list<#MemberInfo>) -> unit 347 | 348 | /// Add the types of the generated assembly as generative types, where types in namespaces get hierarchically positioned as nested types. 349 | member AddAssemblyTypesAsNestedTypesDelayed : assemblyFunction:(unit -> System.Reflection.Assembly) -> unit 350 | 351 | // Parametric types 352 | member DefineStaticParameters : parameters: ProvidedStaticParameter list * instantiationFunction: (string -> obj[] -> ProvidedTypeDefinition) -> unit 353 | 354 | /// Add definition location information to the provided type definition. 355 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 356 | 357 | /// Suppress System.Object entries in intellisense menus in instances of this provided type 358 | member HideObjectMethods : bool with set 359 | 360 | /// Get or set a flag indicating if the ProvidedTypeDefinition is erased 361 | member IsErased : bool with get,set 362 | 363 | /// Get or set a flag indicating if the ProvidedTypeDefinition has type-relocation suppressed 364 | [] 365 | member SuppressRelocation : bool with get,set 366 | 367 | /// FSharp.Data addition: this method is used by Debug.fs 368 | member MakeParametricType : name:string * args:obj[] -> ProvidedTypeDefinition 369 | 370 | /// Add a custom attribute to the provided type definition. 371 | member AddCustomAttribute : CustomAttributeData -> unit 372 | 373 | /// FSharp.Data addition: this method is used by Debug.fs and QuotationBuilder.fs 374 | /// Emulate the F# type provider type erasure mechanism to get the 375 | /// actual (erased) type. We erase ProvidedTypes to their base type 376 | /// and we erase array of provided type to array of base type. In the 377 | /// case of generics all the generic type arguments are also recursively 378 | /// replaced with the erased-to types 379 | static member EraseType : t:Type -> Type 380 | 381 | /// A provided generated assembly 382 | type ProvidedAssembly = 383 | new : assemblyFileName:string -> ProvidedAssembly 384 | /// 385 | /// Emit the given provided type definitions as part of the assembly 386 | /// and adjust the 'Assembly' property of all provided type definitions to return that 387 | /// assembly. 388 | /// 389 | /// The assembly is only emitted when the Assembly property on the root type is accessed for the first time. 390 | /// The host F# compiler does this when processing a generative type declaration for the type. 391 | /// 392 | /// An optional path of type names to wrap the generated types. The generated types are then generated as nested types. 393 | member AddTypes : types : ProvidedTypeDefinition list -> unit 394 | member AddNestedTypes : types : ProvidedTypeDefinition list * enclosingGeneratedTypeNames: string list -> unit 395 | 396 | #if FX_NO_LOCAL_FILESYSTEM 397 | #else 398 | /// Register that a given file is a provided generated assembly 399 | static member RegisterGenerated : fileName:string -> Assembly 400 | #endif 401 | 402 | 403 | /// A base type providing default implementations of type provider functionality when all provided 404 | /// types are of type ProvidedTypeDefinition. 405 | type TypeProviderForNamespaces = 406 | 407 | /// Initializes a type provider to provide the types in the given namespace. 408 | new : namespaceName:string * types: ProvidedTypeDefinition list -> TypeProviderForNamespaces 409 | 410 | /// Initializes a type provider 411 | new : unit -> TypeProviderForNamespaces 412 | 413 | /// Add a namespace of provided types. 414 | member AddNamespace : namespaceName:string * types: ProvidedTypeDefinition list -> unit 415 | 416 | /// FSharp.Data addition: this method is used by Debug.fs 417 | /// Get all namespace with their provided types. 418 | member Namespaces : (string * ProvidedTypeDefinition list) seq with get 419 | 420 | /// Invalidate the information provided by the provider 421 | member Invalidate : unit -> unit 422 | 423 | #if FX_NO_LOCAL_FILESYSTEM 424 | #else 425 | /// AssemblyResolve handler. Default implementation searches .dll file in registered folders 426 | abstract ResolveAssembly : System.ResolveEventArgs -> Assembly 427 | default ResolveAssembly : System.ResolveEventArgs -> Assembly 428 | 429 | /// Registers custom probing path that can be used for probing assemblies 430 | member RegisterProbingFolder : folder : string -> unit 431 | /// Registers location of RuntimeAssembly (from TypeProviderConfig) as probing folder 432 | member RegisterRuntimeAssemblyLocationAsProbingFolder : cfg : Core.CompilerServices.TypeProviderConfig -> unit 433 | 434 | #endif 435 | 436 | [] 437 | member Disposing : IEvent 438 | 439 | interface ITypeProvider 440 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/ProvidedTypesExtensions.fs: -------------------------------------------------------------------------------- 1 | module System.Reflection.MemberInfo 2 | 3 | let inline addXmlDoc xmlDoc (memberInfo: #MemberInfo) = 4 | (^T : (member AddXmlDoc: string -> unit) (memberInfo, xmlDoc)) 5 | 6 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/PythonProvider.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {380603c0-72b7-4e76-8307-907344cdd78e} 9 | Library 10 | PythonTypeProvider 11 | FSharp.Interop.PythonProvider 12 | v4.0 13 | PythonProvider 14 | 4.3.1.0 15 | ..\..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | ..\..\bin 24 | DEBUG;TRACE 25 | 3 26 | 27 | 28 | AnyCPU 29 | Program 30 | C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 31 | $(SolutionDir)PythonTypeProvider.Tests.sln 32 | 33 | 34 | pdbonly 35 | true 36 | true 37 | ..\..\bin 38 | TRACE 39 | 3 40 | ..\..\bin\FSharp.Interop.PythonProvider.XML 41 | AnyCPU 42 | 43 | 44 | 11 45 | 46 | 47 | 48 | 49 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 50 | 51 | 52 | 53 | 54 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | True 77 | 78 | 79 | 80 | ..\..\pythonnet\src\runtime\bin\x86\DebugWin\Python.Runtime.dll 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | PythonProvider.TypesDiscoveryServer 89 | {f5932d2f-eb19-45b6-961d-01acf9e086bd} 90 | True 91 | 92 | 93 | 100 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/PythonTypeProvider.fs: -------------------------------------------------------------------------------- 1 | namespace FSharp.Interop 2 | 3 | open Microsoft.Win32 4 | open Microsoft.FSharp.Core.CompilerServices 5 | open Microsoft.FSharp.Quotations 6 | open System 7 | open System.IO 8 | open System.Linq.Expressions 9 | open System.Security 10 | open System.Reflection 11 | open System.Diagnostics 12 | open PythonTypeProvider.Server 13 | open System.Threading.Tasks 14 | 15 | open ProviderImplementation.ProvidedTypes 16 | 17 | //type Platform = x86 = 0 | x64 = 1 18 | 19 | module PythonStaticInfo = 20 | 21 | [] 22 | let pythonDesignTimeProxy = "PythonProvider.TypesDiscoveryServer.exe" 23 | 24 | let mutable lastServer = None 25 | 26 | let GetServer() = 27 | match lastServer with 28 | | Some s -> s 29 | | None -> 30 | // Restart the server 31 | let channelName = 32 | let randomSalt = System.Random() 33 | let pid = System.Diagnostics.Process.GetCurrentProcess().Id 34 | let tick = System.Environment.TickCount 35 | let salt = randomSalt.Next() 36 | sprintf "PythonStaticInfoServer_%d_%d_%d" pid tick salt 37 | 38 | let exePath = Path.Combine(Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location), pythonDesignTimeProxy) 39 | let startInfo = ProcessStartInfo( UseShellExecute = false, CreateNoWindow = true, FileName=exePath, Arguments = channelName, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true) 40 | let p = Process.Start( startInfo, EnableRaisingEvents = true) 41 | 42 | let proxyStarted = async { while p.StandardOutput.ReadLine() <> sprintf "%s started." channelName do () } |> Async.StartAsTask 43 | if not( proxyStarted.Wait( TimeSpan.FromSeconds( 15.))) 44 | then 45 | p.Kill() 46 | 47 | p.Exited.Add(fun _ -> lastServer <- None) 48 | let server = Activator.GetObject(typeof,"ipc://" + channelName + "/PythonStaticInfoServer") :?> PythonStaticInfoServer 49 | lastServer <- Some server 50 | server 51 | 52 | // This is needed, look on stackoverflow for CreateInstanceFromAndUnwrap errors 53 | AppDomain.CurrentDomain.add_AssemblyResolve(ResolveEventHandler(fun _ args -> 54 | if args.Name = typeof.Assembly.FullName then 55 | typeof.Assembly 56 | else 57 | null)) 58 | 59 | open Python.Runtime 60 | 61 | module PythonRuntime = 62 | let init = 63 | lazy 64 | try PythonEngine.Initialize() with _ -> () 65 | System.AppDomain.CurrentDomain.DomainUnload.Add (fun _ -> Python.Runtime.PythonEngine.Shutdown()) 66 | 67 | let convertToPyObject (x : obj) = 68 | match x with 69 | | null -> failwith "invalid null argument value to python function call" 70 | | :? PyObject as v -> v 71 | | :? double as v -> new PyFloat(v) :> PyObject 72 | | :? float32 as v -> new PyFloat(double v) :> PyObject 73 | | :? int as v -> new PyInt(v) :> PyObject 74 | | :? int64 as v -> new PyLong(v) :> PyObject 75 | | :? string as v -> new PyString(v) :> PyObject 76 | | _ -> failwith "unknown argument type %A" (box(x).GetType()) 77 | 78 | /// Used at runtime 79 | type RuntimeAPI () = 80 | 81 | // Runtime entry points, called by Linq Expressions 82 | static member GetPythonProperty(pyModule:string,pyValueName:string) : Python.Runtime.PyObject = 83 | PythonRuntime.init.Force() 84 | let pyModuleObj = Python.Runtime.PythonEngine.ImportModule(pyModule) 85 | pyModuleObj.GetAttr(pyValueName) 86 | 87 | static member Call(pyModule: string, name: string, args: obj[]) : Python.Runtime.PyObject = 88 | PythonRuntime.init.Force() 89 | let pyModuleObj = Python.Runtime.PythonEngine.ImportModule(pyModule) 90 | pyModuleObj.GetAttr(name).Invoke([| for a in args -> PythonRuntime.convertToPyObject a |]) 91 | 92 | // Runtime methods to be called by "invoker" Linq expr 93 | /// Helpers to find the handles in type provider runtime DLL. 94 | type internal RuntimeInfo (config : TypeProviderConfig) = 95 | let runtimeAssembly = System.Reflection.Assembly.LoadFrom(config.RuntimeAssembly) 96 | let pythonRuntimeAssembly = System.Reflection.Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(config.RuntimeAssembly), typeof.Assembly.GetName().Name + ".dll")) 97 | 98 | // This is needed to load quotation literals 99 | do System.AppDomain.CurrentDomain.add_AssemblyResolve(ResolveEventHandler(fun _ args -> 100 | if args.Name = runtimeAssembly.FullName then 101 | runtimeAssembly 102 | elif args.Name = pythonRuntimeAssembly.FullName then 103 | pythonRuntimeAssembly 104 | else 105 | null)) 106 | 107 | //add resolution folder to sys.path 108 | // do 109 | // PythonRuntime.init.Force() 110 | // let pySysModule = PythonEngine.ImportModule("sys") 111 | // let sysPath = pySysModule.GetAttr("path") 112 | // sysPath.InvokeMethod("append", new PyString( config.ResolutionFolder)) |> ignore 113 | 114 | member x.RuntimeAssembly = 115 | runtimeAssembly 116 | 117 | // static member GetPythonPropertyExpr (pyModule:string, pyValueName:string) = 118 | // Expr.Call(typeof.GetMethod("GetPythonProperty"), [ Expr.Value(pyModule); Expr.Value(pyValueName)] ) 119 | 120 | 121 | 122 | // TypeProvider Boiler Plate (must be in namespace not a module) 123 | [] 124 | type PythonTypeProvider(config : TypeProviderConfig) as this = 125 | inherit TypeProviderForNamespaces() 126 | 127 | let runtimeInfo = RuntimeInfo(config) 128 | let nameSpace = this.GetType().Namespace 129 | let targetAssembly = runtimeInfo.RuntimeAssembly 130 | 131 | let addPythonModulesAsMembers (t:ProvidedTypeDefinition, pyModuleName, xmlDoc) = 132 | 133 | t.AddXmlDocDelayed (fun () -> 134 | match xmlDoc with 135 | | Some doc -> doc 136 | | None -> sprintf "The Python module %s" pyModuleName) 137 | t.AddMembersDelayed (fun () -> 138 | [ for memberName, docs, pyArgs in PythonStaticInfo.GetServer().GetModuleInfo(pyModuleName) do 139 | 140 | let doc = 141 | sprintf "%s" <| 142 | match docs with 143 | | null -> "The Python value " + pyModuleName + "." + memberName 144 | | doc -> SecurityElement.Escape(doc) 145 | 146 | let newMember : MemberInfo = 147 | if Array.isEmpty pyArgs 148 | then 149 | let prop = ProvidedProperty(memberName, 150 | typeof, 151 | IsStatic=true, 152 | GetterCode=(fun _args -> <@@ RuntimeAPI.GetPythonProperty(pyModuleName,memberName) @@>)) 153 | 154 | MemberInfo.addXmlDoc doc prop 155 | upcast prop 156 | elif pyArgs = [| "params" |] 157 | then 158 | let parameters = [for a in pyArgs -> ProvidedParameter("args", typeof)] 159 | let method' = ProvidedMethod(memberName, parameters, returnType = typeof, IsStaticMethod = true) 160 | method'.InvokeCode <- fun args -> 161 | <@@ RuntimeAPI.Call(pyModuleName, memberName, (%%args.Head: obj[])) @@> 162 | 163 | MemberInfo.addXmlDoc doc method' 164 | upcast method' 165 | else 166 | let parameters = [for a in pyArgs -> ProvidedParameter(a, typeof)] 167 | let method' = ProvidedMethod(memberName, parameters, returnType = typeof, IsStaticMethod = true) 168 | method'.InvokeCode <- fun args -> 169 | let argsArray = Expr.NewArray(typeof, args) 170 | <@@ RuntimeAPI.Call(pyModuleName, memberName, %%argsArray) @@> 171 | 172 | method'.AddXmlDoc("" + SecurityElement.Escape(doc) + "") 173 | upcast method' 174 | 175 | yield newMember ] 176 | ) 177 | 178 | // let typesAll = 179 | // [ for (pyModuleName, xmlDoc) in PythonStaticInfo.GetServer().GetLoadedModulesInfo() do 180 | // let t = ProvidedTypeDefinition(targetAssembly, nameSpace, pyModuleName, Some typeof ) 181 | // addPythonModulesAsMembers (t, pyModuleName, xmlDoc) 182 | // yield t ] 183 | 184 | let providerType = ProvidedTypeDefinition(targetAssembly, nameSpace, "PythonProvider", Some typeof, HideObjectMethods = true) 185 | 186 | do 187 | providerType.DefineStaticParameters( 188 | parameters = [ 189 | ProvidedStaticParameter("Import", typeof, "") 190 | ], 191 | instantiationFunction = this.CreateType 192 | ) 193 | 194 | this.AddNamespace( nameSpace, [ providerType]) 195 | 196 | member internal this.CreateType typeName parameters = 197 | let modulesToImport : string = unbox parameters.[0] 198 | 199 | let rootType = ProvidedTypeDefinition(targetAssembly, nameSpace, typeName, baseType = Some typeof, HideObjectMethods = true) 200 | 201 | rootType.AddMembersDelayed <| fun() -> 202 | [ 203 | let server = PythonStaticInfo.GetServer() 204 | for pyModuleName, xmlDoc in server.GetLoadedModulesInfo(workingFolder = config.ResolutionFolder, import = modulesToImport.Split(',')) do 205 | yield this.GetTypeForModule(pyModuleName, xmlDoc) 206 | ] 207 | 208 | 209 | rootType 210 | 211 | member internal this.GetTypeForModule(pyModuleName, xmlDoc) = 212 | let t = ProvidedTypeDefinition( pyModuleName, Some typeof) 213 | addPythonModulesAsMembers (t, pyModuleName, xmlDoc) 214 | t 215 | 216 | 217 | 218 | // Allow references to user scripts. Disabled as the ModuleFromString is relying on having a side effect 219 | // on the server (loading the script using ModuleFromString), but we allow restarts of the server. Instead 220 | // we should probaly start a new server for each different use of the type provider (loading only the modules 221 | // indicated), to get more isolation, or have the seerver only play the call to ModuleFromString once. 222 | #if USER_SCRIPTS 223 | let rootNamespace2 = "FSharp.Interop" 224 | let typeBeforeStaticParams = 225 | let t = ProvidedTypeDefinition(targetAssembly, rootNamespace2, "PythonProvider", Some typeof ) 226 | t.AddXmlDoc("""Experimental: PythonProvider<"script.py">""") 227 | t.DefineStaticParameters( [ ProvidedStaticParameter("Script",typeof,null) ] , (fun typeName args -> 228 | let scriptFile = args.[0] :?> string 229 | let moduleName = Path.GetFileNameWithoutExtension(scriptFile) 230 | PythonStaticInfo.Server.ModuleFromString(moduleName,File.ReadAllText(scriptFile)) 231 | //if result = -1 then failwith "error from RunSimpleString - todo, report the error properly" 232 | 233 | let typeWithStaticParams = ProvidedTypeDefinition(targetAssembly, rootNamespace2, typeName, Some typeof ) 234 | addPythonModulesAsMembers (typeWithStaticParams, moduleName, None) 235 | typeWithStaticParams)) 236 | t 237 | do this.AddNamespace(rootNamespace2, [typeBeforeStaticParams]) 238 | #endif 239 | interface IDisposable with 240 | member __.Dispose() = () 241 | 242 | [] 243 | do() 244 | -------------------------------------------------------------------------------- /src/PythonTypeProvider/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/PythonProvider.Runtime.Tests/PyObject.Tests.fs: -------------------------------------------------------------------------------- 1 | namespace FSharp.Interop 2 | 3 | open Xunit 4 | open FSharp.Interop.Python 5 | open Python.Runtime 6 | open Swensen.Unquote 7 | 8 | type PyObjectTests() = 9 | 10 | do 11 | init.Force() 12 | let sys = PythonEngine.ImportModule("sys") 13 | let inspect = PythonEngine.ImportModule("inspect") 14 | 15 | [] 16 | member __.Doc() = 17 | let expected = "chr(i) -> character\n\nReturn a string of one character with ordinal i; 0 <= i < 256." 18 | let chr = PythonEngine.ImportModule("__builtin__").GetAttr("chr") 19 | Assert.Equal(expected, chr.Doc) 20 | 21 | [] 22 | member __.Name() = 23 | Assert.Equal("sys", sys.Name) 24 | 25 | [] 26 | member __.IsModule() = 27 | Assert.True(sys.IsModule) 28 | 29 | [] 30 | member __.GetModules() = 31 | // let expected = 32 | // Array.sort [| "heapq"; "functools"; "random"; "sysconfig"; "struct"; "base64"; "imp"; "collections"; "zipimport"; "string"; "textwrap"; "ssl"; "signal"; "threading"; "token"; "dis"; "cStringIO"; "locale"; "encodings"; "abc"; "re"; "ntpath"; "math"; "optparse"; "UserDict"; "inspect"; "codecs"; "socket"; "thread"; "traceback"; "weakref"; "itertools"; "opcode"; "os"; "operator"; "visualstudio_py_repl"; "select"; "errno"; "binascii"; "sre_constants"; "os.path"; "tokenize"; "encodings.cp1252"; "copy"; "hashlib"; "keyword"; "encodings.aliases"; "exceptions"; "sre_parse"; "copy_reg"; "sre_compile"; "site"; "visualstudio_py_util"; "strop"; "linecache"; "gettext"; "nt"; "genericpath"; "stat"; "warnings"; "encodings.ascii"; "encodings.utf_8"; "sys"; "types"; "time" |] 33 | //printfn "\nAll modules:\n%A\n\n" [| for m in SysModule().Modules() -> m.Name |] 34 | Assert.NotEmpty [| for m in SysModule().Modules() -> m.Name |] 35 | 36 | [] 37 | member __.GetMembers() = 38 | let copy = PythonEngine.ImportModule("copy") 39 | let expected = set ["Error"; "copy"; "deepcopy"] 40 | let actual = set [ for x in Module(copy).Members -> fst x ] 41 | test <@ expected = actual @> 42 | 43 | //"encodings.encodings", "encodings.__builtin__", "encodings.codecs" -------------------------------------------------------------------------------- /tests/PythonProvider.Runtime.Tests/PythonProvider.Runtime.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 345ad7b0-1de0-448a-86b0-086ac521c7a7 9 | Library 10 | PythonProvider.Runtime.Tests 11 | PythonProvider.Runtime.Tests 12 | v4.5 13 | 4.3.1.0 14 | PythonProvider.Runtime.Tests 15 | ..\..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | 3 26 | bin\Debug\PythonProvider.Runtime.Tests.XML 27 | Program 28 | C:\Users\mitekm\Downloads\xunit\xunit.gui.clr4.x86.exe 29 | 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | bin\Release\ 36 | TRACE 37 | 3 38 | bin\Release\PythonProvider.Runtime.Tests.XML 39 | 40 | 41 | 11 42 | 43 | 44 | 45 | 46 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 47 | 48 | 49 | 50 | 51 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | PreserveNewest 68 | 69 | 70 | 71 | 72 | 73 | 74 | True 75 | 76 | 77 | ..\..\lib\Python.Runtime.dll 78 | 79 | 80 | 81 | 82 | 83 | ..\..\packages\Unquote.2.2.2\lib\net40\Unquote.dll 84 | True 85 | 86 | 87 | ..\..\packages\xunit.1.9.2\lib\net20\xunit.dll 88 | True 89 | 90 | 91 | 92 | 93 | PythonProvider.Runtime 94 | {ad4d91af-3c95-485b-a141-b67a9c97cc4d} 95 | True 96 | 97 | 98 | 99 | 100 | 101 | 102 | 109 | -------------------------------------------------------------------------------- /tests/PythonProvider.Runtime.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/PythonProvider.Runtime.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/PythonProvider.Runtime.Tests/python27.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Interop.PythonProvider/0296a73dc18aaab21196ff577da69dd3e2ff6e86/tests/PythonProvider.Runtime.Tests/python27.dll -------------------------------------------------------------------------------- /tests/PythonTypeProvider.Tests/Program.fs: -------------------------------------------------------------------------------- 1 | module Program 2 | 3 | 4 | 5 | let main _ = 6 | 7 | 0 8 | 9 | -------------------------------------------------------------------------------- /tests/PythonTypeProvider.Tests/PythonTypeProvider.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | d1de417d-b34a-4f03-8755-949a54435d2a 9 | Exe 10 | PythonTypeProvider.Tests 11 | PythonTypeProvider.Tests 12 | v4.5 13 | PythonTypeProvider.Tests 14 | 4.3.0.0 15 | 16 | 17 | true 18 | full 19 | false 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | 3 24 | AnyCPU 25 | bin\Debug\PythonTypeProvider.Tests.XML 26 | true 27 | 28 | 29 | pdbonly 30 | true 31 | true 32 | bin\Release\ 33 | TRACE 34 | 3 35 | AnyCPU 36 | bin\Release\PythonTypeProvider.Tests.XML 37 | true 38 | 39 | 40 | 11 41 | 42 | 43 | 44 | 45 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 46 | 47 | 48 | 49 | 50 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | sample.fsx 59 | 60 | 61 | 62 | 63 | 64 | 65 | True 66 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | -------------------------------------------------------------------------------- /tests/PythonTypeProvider.Tests/TestScript.fsx: -------------------------------------------------------------------------------- 1 | #r "../../bin/Python.Runtime.dll" 2 | #r "../../bin/FSharp.Interop.PythonProvider.dll" 3 | 4 | open FSharp.Interop 5 | type Python = PythonProvider<"sys,math,io"> 6 | 7 | Python.sys.path 8 | printfn "Res = %A" Python.math.pi 9 | Python.math.sin(3.0) 10 | //Python.mytest.aMethod(3, 5) 11 | 12 | Python.io.``open``([| sprintf "%s\%s" __SOURCE_DIRECTORY__ "mytest.py" |]) 13 | Python.UserDict.DictMixin 14 | Python.__builtin__.ArithmeticError 15 | Python.functools.partial 16 | Python.abc.abstractproperty 17 | Python.sys.copyright 18 | Python.operator.abs( Python.math.pi) 19 | 20 | //type MyCode = PythonProvider<"test.py"> 21 | //MyCode.aMethod() 22 | 23 | (* 24 | Python.math.sin %% 3.0 25 | 26 | let x = Python.math.sin %% 3.0 27 | (x.AsManagedObject typeof :?> float) 28 | Python.math.sin.Dir() 29 | x.Dir() 30 | 31 | (Python.math.sin.GetAttr "__call__").GetPythonType() 32 | //(Python.math.sin.GetItem "__call__") 33 | 34 | let pyString (str: string) = 35 | new Python.Runtime.PyString(str) :> Python.Runtime.PyObject 36 | 37 | Python.math.sin.Invoke[|pyString "func_code"|] 38 | Python.math.sin.GetAttr "func_code" 39 | Python.math.sin.GetItem "func_code" // not subscriptable 40 | 41 | Python.math.Dir() 42 | 43 | sin 3.0 44 | 45 | //open FSharp.Data 46 | 47 | //type Freebase.* 48 | 49 | //type MyFrebase.* = FreebaseProvider 50 | 51 | *) 52 | (* 53 | (Python.math.sin %% 3.0).Dir() 54 | seq 55 | [__abs__ {Handle = 168760096n; 56 | Item = ?; 57 | Item = ?; 58 | Item = ?;}; __add__ {Handle = 168759424n; 59 | Item = ?; 60 | Item = ?; 61 | Item = ?;}; __class__ {Handle = 168761856n; 62 | Item = ?; 63 | Item = ?; 64 | Item = ?;}; 65 | __coerce__ {Handle = 168760512n; 66 | Item = ?; 67 | Item = ?; 68 | Item = ?;}; ...] 69 | 70 | Python.math.sin.Dir() 71 | seq 72 | [__call__ {Handle = 168761184n; 73 | Item = ?; 74 | Item = ?; 75 | Item = ?;}; __class__ {Handle = 168761856n; 76 | Item = ?; 77 | Item = ?; 78 | Item = ?;}; 79 | __cmp__ {Handle = 168761120n; 80 | Item = ?; 81 | Item = ?; 82 | Item = ?;}; __delattr__ {Handle = 168761280n; 83 | Item = ?; 84 | Item = ?; 85 | Item = ?;}; ...] 86 | *) 87 | -------------------------------------------------------------------------------- /tests/PythonTypeProvider.Tests/mytest.py: -------------------------------------------------------------------------------- 1 | 2 | def aMethod(x, y): 3 | return x + y 4 | 5 | --------------------------------------------------------------------------------