Repository navigation
Expand file tree
/
Copy pathPythonSettings.cs
More file actions
91 lines (75 loc) · 4.34 KB
/
Copy pathPythonSettings.cs
File metadata and controls
91 lines (75 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2012-2022 Keysight Technologies
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
namespace OpenTap.Python
{
/// <summary>
/// Provides capability to load Python code into step, build step as PythonStep, and build C# DLL wrapper code.
/// </summary>
[Display("Python", "Settings for the Python plugin.")]
[HelpLink("https://opentap.gitlab.io/Plugins/python/")]
[Obfuscation(Exclude = true)]
public class PythonSettings : ComponentSettings<PythonSettings>
{
/// <summary>
/// Makes it possible to configure a custom path to a python installation.
/// </summary>
[Display("Python Path", "Enables a custom path to the Python installation. After configuration, TAP should be restarted for the effect to take place. This can be used to select a python installation, which is not location in the usual places.", Order: 0)]
[DirectoryPath]
public string PythonPath { get; set; }
public IEnumerable<string> AvailableLibraries => PythonDiscoverer.Instance.AvailablePythonLibraries;
[Display("Python Library Path", "" +
"Enables a custom path to the Python installation. " +
"After configuration, TAP should be restarted for the effect to take place." +
"This is for specifying a direct path to a libpython file.",
Order: 0)]
[FilePath]
[SuggestedValues(nameof(AvailableLibraries))]
public string PythonLibraryPath {get; set; }
[DirectoryPath]
[Display("Virtual Environment", Description:"If a virtual environment is used, point this to the folder of that virtual environment. This will cause PYTHONPATH to be overwritten for the application.")]
public string VirtualEnvironment { get; set; } = null;
[Display("Plugin Module Search Path", "A list containing additional search paths for finding the Python based plugin modules.", Order: 1)]
public List<PluginSearchPath> SearchPathList { get; set; } = new ();
public string[] GetSearchList()
{
var lst = new List<string>();
var dir = Path.GetDirectoryName(typeof(TestPlan).Assembly.Location);
lst.Add(dir);
var dir2 = Path.Combine(dir, "Packages", "Python");
if (Directory.Exists(dir2))
lst.Add(dir2);
dir2 = Path.Combine(dir, "Packages");
if (Directory.Exists(dir2))
lst.Add(dir2);
foreach (var path in SearchPathList)
{
if (path.Enabled && Directory.Exists(path.SearchPath))
lst.Add(path.SearchPath);
}
return lst.ToArray();
}
public string DefaultSearchPath => Path.GetDirectoryName(typeof(PythonSettings).Assembly.Location);
public IEnumerable<string> GetSearchPaths() =>
SearchPathList.Where(x => x.Enabled).Select(x => x.SearchPath).Append(DefaultSearchPath);
[Display("Enable", "Whether to enable the debugging server inside the python interpreter. This can cause instabilities on some platforms. Not verified to work on MacOS. The process needs to be restarted for this setting to apply. Note, it also needs the debugpy package to be installed.", "Debug", Order: 1)]
public bool Debug { get; set; }
[Display("Port",
"The port which debugpy uses to connect with the developer environment. This needs to match the one defined in the launch configuration.",
"Debug", Order: 1)]
public int DebugPort { get; set; } = 5678;
public PythonSettings()
{
Rules.Add(() => !SearchPathList.Exists(x => !string.IsNullOrEmpty(x.Error)), "Search path error(s) is found.", nameof(SearchPathList));
Rules.Add(() => string.IsNullOrWhiteSpace(VirtualEnvironment) || Directory.Exists(VirtualEnvironment), "Virtual environment folder does not exist", nameof(VirtualEnvironment));
}
}
}