Lean  $LEAN_TAG$
Messages.Python.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at 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 using System.IO;
17 using System.Runtime.CompilerServices;
18 using System.Collections.Generic;
19 
20 using Python.Runtime;
21 
22 namespace QuantConnect
23 {
24  /// <summary>
25  /// Provides user-facing message construction methods and static messages for the <see cref="Python"/> namespace
26  /// </summary>
27  public static partial class Messages
28  {
29  /// <summary>
30  /// Provides user-facing common messages for the <see cref="Python"/> namespace classes
31  /// </summary>
32  public static class PythonCommon
33  {
34  [MethodImpl(MethodImplOptions.AggressiveInlining)]
35  public static string AttributeNotImplemented(string attribute, PyType pythonType)
36  {
37  return $"{attribute} must be implemented. Please implement this missing method on {pythonType}";
38  }
39  }
40 
41  /// <summary>
42  /// Provides user-facing common messages for the <see cref="Python.MarginCallModelPythonWrapper"/> namespace classes
43  /// </summary>
44  public static class MarginCallModelPythonWrapper
45  {
46  public static string GetMarginCallOrdersMustReturnTuple = "Must return a tuple, where the first item is a list and the second a boolean";
47  }
48 
49  /// <summary>
50  /// Provides user-facing common messages for the <see cref="Python.PandasConverter"/> namespace classes
51  /// </summary>
52  public static class PandasConverter
53  {
54  public static string PandasModuleNotImported = "pandas module was not imported.";
55 
56  [MethodImpl(MethodImplOptions.AggressiveInlining)]
57  public static string ConvertToDictionaryFailed(string sourceType, string targetType, string reason)
58  {
59  return $"ConvertToDictionary cannot be used to convert a {sourceType} into {targetType}. Reason: {reason}";
60  }
61  }
62 
63  /// <summary>
64  /// Provides user-facing common messages for the <see cref="Python.PandasData"/> namespace classes
65  /// </summary>
66  public static class PandasData
67  {
68  [MethodImpl(MethodImplOptions.AggressiveInlining)]
69  public static string DuplicateKey(string duplicateKey, string type)
70  {
71  return $"More than one '{duplicateKey}' member was found in '{type}' class.";
72  }
73 
74  [MethodImpl(MethodImplOptions.AggressiveInlining)]
75  public static string KeyNotFoundInSeries(string key)
76  {
77  return $"{key} key does not exist in series dictionary.";
78  }
79  }
80 
81  /// <summary>
82  /// Provides user-facing common messages for the <see cref="Python.PythonInitializer"/> namespace classes
83  /// </summary>
84  public static class PythonInitializer
85  {
86  public static string Start = "start";
87 
88  public static string Ended = "ended";
89 
90  [MethodImpl(MethodImplOptions.AggressiveInlining)]
91  public static string UnableToLocateAlgorithm(string algorithmLocation)
92  {
93  return $"Unable to find algorithm location path: {algorithmLocation}.";
94  }
95 
96  [MethodImpl(MethodImplOptions.AggressiveInlining)]
97  public static string VirutalEnvironmentNotFound(string virtualEnvPath)
98  {
99  return $"Path {virtualEnvPath} to virtual environment does not exist.";
100  }
101 
102  [MethodImpl(MethodImplOptions.AggressiveInlining)]
103  public static string FailedToFindSystemPackagesConfiguration(string virtualEnvPath, FileInfo configFile)
104  {
105  return $@"virtual env '{virtualEnvPath}'. Failed to find system packages configuration. ConfigFile.Exits: {
106  configFile.Exists}. Will default to true.";
107  }
108 
109  [MethodImpl(MethodImplOptions.AggressiveInlining)]
110  public static string SystemPackagesConfigurationFound(string virtualEnvPath, bool includeSystemPackages)
111  {
112  return $"virtual env '{virtualEnvPath}'. Will use system packages: {includeSystemPackages}";
113  }
114 
115  [MethodImpl(MethodImplOptions.AggressiveInlining)]
116  public static string PythonPathNotFound(string pythonPath)
117  {
118  return $"Unable to find python path: {pythonPath}. Skipping.";
119  }
120  }
121 
122  /// <summary>
123  /// Provides user-facing common messages for the <see cref="Python.PythonWrapper"/> namespace classes
124  /// </summary>
125  public static class PythonWrapper
126  {
127  public static string ExpectedInterfaceTypeParameter = "expected an interface type parameter.";
128 
129  [MethodImpl(MethodImplOptions.AggressiveInlining)]
130  public static string InterfaceNotFullyImplemented(string interfaceName, string pythonTypeName, IEnumerable<string> missingMembers)
131  {
132  return $@"{interfaceName} must be fully implemented. Please implement these missing methods on {
133  pythonTypeName}: {string.Join(", ", missingMembers)}";
134  }
135  }
136  }
137 }