Skip to content

Commit

Permalink
perf: remove dependency support
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Jun 5, 2024
1 parent 41135db commit e1273ab
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 157 deletions.
2 changes: 0 additions & 2 deletions src/PipManager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
using PipManager.Services.Overlay;
using PipManager.ViewModels.Pages.Overlay;
using PipManager.Views.Pages.Overlay;
using Python.Runtime;
using Wpf.Ui;
using AboutViewModel = PipManager.ViewModels.Pages.About.AboutViewModel;
using ActionViewModel = PipManager.ViewModels.Pages.Action.ActionViewModel;
Expand Down Expand Up @@ -188,7 +187,6 @@ private async void OnExit(object sender, ExitEventArgs e)
}
await Host.StopAsync();
Host.Dispose();
PythonEngine.Shutdown();
Log.Information("Logging ended");
await Log.CloseAndFlushAsync();
}
Expand Down
1 change: 0 additions & 1 deletion src/PipManager/Models/Package/PackageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class PackageItem
public string? AuthorEmail { get; init; }
public List<LibraryDetailProjectUrlModel>? ProjectUrl { get; init; }
public Dictionary<string, List<string>>? Classifier { get; init; }
public List<string>? RequiresDist { get; init; }
public Dictionary<string, List<string>>? Metadata { get; init; }
public List<string>? Record { get; init; }
}
3 changes: 1 addition & 2 deletions src/PipManager/PipManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2365.46" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="pythonnet" Version="3.1.0-preview2024-04-07" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Expand Down
36 changes: 0 additions & 36 deletions src/PipManager/Services/Environment/EnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using Python.Runtime;
using Wpf.Ui.Controls;
using Path = System.IO.Path;

Expand Down Expand Up @@ -220,7 +219,6 @@ public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem)
AuthorEmail = metadata.GetValueOrDefault("author-email", [""])[0],
ProjectUrl = projectUrlDictionary,
Classifier = classifiers,
RequiresDist = metadata.GetValueOrDefault("requires-dist", []),
Metadata = metadata,
Record = record
});
Expand All @@ -232,40 +230,6 @@ public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem)
return [.. packages.OrderBy(x => x.Name)];
}

public void RefreshPythonEngine()
{
PythonEngine.Shutdown();
Runtime.PythonDLL = configurationService.AppConfig.CurrentEnvironment!.PythonDllPath!;
PythonEngine.Initialize();
}

public ParseRequirementsResponse ParseRequirements(IEnumerable<string> requirements)
{
var parsedRequirements = new ParseRequirementsResponse { Success = true, Requirements = [] };
using (Py.GIL())
{
try
{
dynamic packagingModule = Py.Import("packaging.requirements");
dynamic requirementClass = packagingModule.Requirement;
foreach (var requirement in requirements)
{
dynamic requirementParser = requirementClass(requirement);
parsedRequirements.Requirements.Add(new ParsedRequirement
{
Name = requirementParser.name.ToString(),
Specifier = requirementParser.specifier.ToString()
});
}
}
catch (PythonException ex)
{
Log.Error(ex.Message);
}
}
return parsedRequirements;
}

public async Task<GetVersionsResponse> GetVersions(string packageName, CancellationToken cancellationToken, bool detectNonRelease = true)
{
try
Expand Down
2 changes: 0 additions & 2 deletions src/PipManager/Services/Environment/IEnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public interface IEnvironmentService
public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem);

public Task<List<PackageItem>?> GetLibraries();
public void RefreshPythonEngine();

public Task<GetVersionsResponse> GetVersions(string packageName, CancellationToken cancellationToken, bool detectNonRelease = true);
public bool TryKillProcess();
public ParseRequirementsResponse ParseRequirements(IEnumerable<string> requirements);

public ActionResponse Install(string packageName, DataReceivedEventHandler consoleOutputCallback, string[]? extraParameters = null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
mainWindowViewModel.ApplicationTitle = $"Pip Manager | {CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion}";
configurationService.AppConfig.CurrentEnvironment = CurrentEnvironment;
configurationService.Save();
environmentService.RefreshPythonEngine();
Log.Information($"[Environment] Environment changed ({CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion})");
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ public partial class LabViewModel(IActionService actionService, IEnvironmentServ
{
private bool _isInitialized;

[RelayCommand]
private void ParseTest()
{
var parsed = environmentService.ParseRequirements(["requests", "numpy"]);
parsed.Requirements?.ForEach(item => Log.Information(item.Specifier));
}

[RelayCommand]
private void ActionTest()
{
Expand Down
15 changes: 2 additions & 13 deletions src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using PipManager.Models.Package;
using PipManager.Models.Pages;
using System.Collections.ObjectModel;
using PipManager.Services.Environment;
using PipManager.Services.Environment.Response;
using PipManager.Services.Toast;
using PipManager.Views.Pages.Library;
Expand All @@ -14,14 +13,12 @@ namespace PipManager.ViewModels.Pages.Library;

public partial class LibraryDetailViewModel : ObservableObject, INavigationAware
{
private readonly IEnvironmentService _environmentService;
private readonly INavigationService _navigationService;
private readonly IToastService _toastService;
public record LibraryDetailMessage(PackageItem Package, List<PackageItem> Library);
private bool _isInitialized;

[ObservableProperty]
private PackageItem? _package;
[ObservableProperty] private PackageItem? _package;
[ObservableProperty] private List<PackageItem>? _library;

#region Contact
Expand All @@ -31,8 +28,6 @@ public record LibraryDetailMessage(PackageItem Package, List<PackageItem> Librar
[ObservableProperty] private ObservableCollection<LibraryDetailProjectUrlModel>? _projectUrl;

#endregion Contact

[ObservableProperty] private ObservableCollection<ParsedRequirement>? _requireDist;

#region Classifier

Expand All @@ -47,9 +42,8 @@ public record LibraryDetailMessage(PackageItem Package, List<PackageItem> Librar

#endregion Classifier

public LibraryDetailViewModel(IEnvironmentService environmentService, INavigationService navigationService, IToastService toastService)
public LibraryDetailViewModel(INavigationService navigationService, IToastService toastService)
{
_environmentService = environmentService;
_navigationService = navigationService;
_toastService = toastService;
WeakReferenceMessenger.Default.Register<LibraryDetailMessage>(this, Receive);
Expand Down Expand Up @@ -95,11 +89,6 @@ private void Receive(object recipient, LibraryDetailMessage message)
ProjectUrl = new ObservableCollection<LibraryDetailProjectUrlModel>(Package.ProjectUrl!);

#endregion Contact

if (Package.RequiresDist != null)
{
RequireDist = new ObservableCollection<ParsedRequirement>(_environmentService.ParseRequirements(Package.RequiresDist).Requirements!);
}

#region Classifier

Expand Down
1 change: 0 additions & 1 deletion src/PipManager/ViewModels/Windows/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public MainWindowViewModel(IConfigurationService configurationService, IEnvironm

if (configurationService.AppConfig.CurrentEnvironment != null)
{
environmentService.RefreshPythonEngine();
Log.Information($"[MainWindow] Environment loaded ({configurationService.AppConfig.CurrentEnvironment.PipVersion} for {configurationService.AppConfig.CurrentEnvironment.PythonVersion})");
ApplicationTitle = $"Pip Manager | {configurationService.AppConfig.CurrentEnvironment.PipVersion} for {configurationService.AppConfig.CurrentEnvironment.PythonVersion}";
}
Expand Down
139 changes: 47 additions & 92 deletions src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
<!-- ReSharper disable Xaml.PossibleNullReferenceException -->
<Page
FontFamily="/PipManager;component/Resources/Fonts/MiSans-Regular.ttf#MiSans"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Title="LibraryDetailPage"
d:DataContext="{d:DesignInstance library:LibraryDetailPage,
IsDesignTimeCreatable=False}"
d:DesignHeight="700"
d:DesignWidth="1200"
mc:Ignorable="d"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ui:NavigationView.HeaderContent="{I18N {x:Static lang:LangKeys.LibraryDetail_Header}}"
x:Class="PipManager.Views.Pages.Library.LibraryDetailPage"
x:Name="LibraryDetail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="clr-namespace:PipManager.Languages"
xmlns:library="clr-namespace:PipManager.Views.Pages.Library"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page x:Class="PipManager.Views.Pages.Library.LibraryDetailPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="clr-namespace:PipManager.Languages"
xmlns:library="clr-namespace:PipManager.Views.Pages.Library"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
x:Name="LibraryDetail"
Title="LibraryDetailPage"
d:DataContext="{d:DesignInstance library:LibraryDetailPage,
IsDesignTimeCreatable=False}"
d:DesignHeight="700"
d:DesignWidth="1200"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ui:NavigationView.HeaderContent="{I18N {x:Static lang:LangKeys.LibraryDetail_Header}}"
FontFamily="/PipManager;component/Resources/Fonts/MiSans-Regular.ttf#MiSans"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">

<Grid Margin="0,0,0,20">
<StackPanel>
<ui:Card>
<StackPanel>
<StackPanel Orientation="Horizontal">
<ui:TextBlock
FontTypography="Subtitle"
Text="{Binding ViewModel.Package.Name, Mode=TwoWay}"
VerticalAlignment="Center" />
<ui:Badge
Appearance="Info"
Margin="5,0,0,0"
VerticalAlignment="Center">
<ui:TextBlock VerticalAlignment="Center"
FontTypography="Subtitle"
Text="{Binding ViewModel.Package.Name, Mode=TwoWay}" />
<ui:Badge Margin="5,0,0,0"
VerticalAlignment="Center"
Appearance="Info">
<ui:TextBlock FontTypography="Caption" Text="{Binding ViewModel.Package.Version, Mode=TwoWay}" />
</ui:Badge>
</StackPanel>

<ui:TextBlock
FontTypography="Body"
Margin="0,3,0,0"
Text="{Binding ViewModel.Package.Summary, Mode=TwoWay}"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock Margin="0,3,0,0"
FontTypography="Body"
Text="{Binding ViewModel.Package.Summary, Mode=TwoWay}"
TextWrapping="WrapWithOverflow" />

</StackPanel>
</ui:Card>
<ui:CardExpander Icon="{ui:SymbolIcon Person24}" Margin="0,10,0,0">
<ui:CardExpander Margin="0,10,0,0" Icon="{ui:SymbolIcon Person24}">
<ui:CardExpander.Header>
<StackPanel>
<ui:TextBlock Text="{Binding ViewModel.Author, Mode=TwoWay}" />
<ui:TextBlock
FontTypography="Caption"
Foreground="Gray"
Text="{Binding ViewModel.AuthorEmail, Mode=TwoWay}"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock FontTypography="Caption"
Foreground="Gray"
Text="{Binding ViewModel.AuthorEmail, Mode=TwoWay}"
TextWrapping="WrapWithOverflow" />
</StackPanel>
</ui:CardExpander.Header>
<ItemsControl HorizontalAlignment="Left" ItemsSource="{Binding ViewModel.ProjectUrl}">
Expand All @@ -66,67 +61,27 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<ui:HyperlinkButton
Content="{Binding UrlType}"
Icon="{Binding Icon}"
NavigateUri="{Binding Url}"
ToolTip="{Binding Url}"
Visibility="{Binding Url, Converter={StaticResource NullToVisibility}}" />
<ui:TextBlock
FontTypography="Body"
Margin="3,5,0,5"
Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Unknown}}"
Visibility="{Binding Url, Converter={StaticResource NotNullToVisibility}}" />
<ui:HyperlinkButton Content="{Binding UrlType}"
Icon="{Binding Icon}"
NavigateUri="{Binding Url}"
ToolTip="{Binding Url}"
Visibility="{Binding Url, Converter={StaticResource NullToVisibility}}" />
<ui:TextBlock Margin="3,5,0,5"
FontTypography="Body"
Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Unknown}}"
Visibility="{Binding Url, Converter={StaticResource NotNullToVisibility}}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ui:CardExpander>

<ui:CardExpander Icon="{ui:SymbolIcon BoxArrowUp24}" Margin="0,10,0,0">
<ui:CardExpander.Header>
<StackPanel>
<ui:TextBlock Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Dependency_Header}}" />
<ui:TextBlock FontTypography="Caption" Foreground="Gray">
<ui:TextBlock.Text>
<I18N Key="{x:Static lang:LangKeys.LibraryDetail_Dependency_Caption}">
<Binding Path="ViewModel.Package.RequiresDist.Count" />
</I18N>
</ui:TextBlock.Text>
</ui:TextBlock>
</StackPanel>
</ui:CardExpander.Header>
<Grid>
<ui:TextBlock Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Dependency_Empty}}" Visibility="{Binding ViewModel.RequireDist.Count, Converter={StaticResource IntegerToVisibility}}" />
<ItemsControl ItemsSource="{Binding ViewModel.RequireDist}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:HyperlinkButton Grid.Column="0" Content="{Binding Name}" Command="{Binding ElementName=LibraryDetail, Path=ViewModel.NavigateToDependencyCommand}" CommandParameter="{Binding Name}"></ui:HyperlinkButton>
<ui:TextBlock
FontTypography="Body"
Grid.Column="1"
Margin="3,5,0,5"
Text="{Binding Specifier}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>

</ui:CardExpander>

<ui:Card Margin="0,10,0,0">
<StackPanel>
<TextBlock Margin="0,0,0,5" Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Classifier_DevelopmentStatus}}" />
<ui:Badge
Appearance="{Binding ViewModel.DevelopmentStatusAppearance}"
Content="{Binding ViewModel.DevelopmentStatus}"
HorizontalAlignment="Left" />
<ui:Badge HorizontalAlignment="Left"
Appearance="{Binding ViewModel.DevelopmentStatusAppearance}"
Content="{Binding ViewModel.DevelopmentStatus}" />
<TextBlock Margin="0,5,0,5" Text="{I18N {x:Static lang:LangKeys.LibraryDetail_Classifier_ProgrammingLanguage}}" />
<ItemsControl HorizontalAlignment="Left" ItemsSource="{Binding ViewModel.ProgrammingLanguage}">
<ItemsControl.ItemsPanel>
Expand Down

0 comments on commit e1273ab

Please sign in to comment.