Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*.cs]
# Requerir this para miembros de instancia
dotnet_style_qualification_for_field = true:error
dotnet_style_qualification_for_property = true:error
dotnet_style_qualification_for_method = true:error
dotnet_style_qualification_for_event = true:error
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"modAuthor": "tutosrive",
"enforceHeader": true,
"exclude": ["json", "jsonc", "gitignore", "md", "txt", "sln", "csproj"],
"excludeGlob": ["**/settings.json", "**/*.sln", "**/*.csproj", "**/.gitignore", "**/LICENSE", "**/README.md"]
"excludeGlob": ["**/.editorconfig", "**/settings.json", "**/*.sln", "**/*.csproj", "**/.gitignore", "**/LICENSE", "**/README.md"]
}
}
6 changes: 3 additions & 3 deletions InitVenv.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
</PropertyGroup>

</Project>
</Project>
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* File: \Program.cs
* Created: Friday, 18th July 2025 7:00:41 pm
* -----
* Last Modified: Sunday, 27th July 2025 8:17:43 pm
* Last Modified: Monday, 28th July 2025 3:07:33 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/
Expand Down
43 changes: 0 additions & 43 deletions src/App/CommandsValidations.cs

This file was deleted.

49 changes: 1 addition & 48 deletions src/App/Utils/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
* File: \Files.cs
* Created: Friday, 18th July 2025 7:00:41 pm
* -----
* Last Modified: Sunday, 27th July 2025 2:07:13 pm
* Last Modified: Monday, 28th July 2025 2:56:10 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/

using System.Text.Json;

namespace InitVenv.src.App.utils
{
public static class Files
Expand All @@ -29,50 +27,5 @@ public static bool Exists(string arg)
string fullPath = Paths.ToUniversalPaths(arg);
return Path.Exists(fullPath);
}

/// <summary>
/// Try "read" JSON files and return its content (Needs a class to understand the JSON format)
/// </summary>
/// <typeparam name="T">The "interface" to understand the file format (its keys, values, types...)</typeparam>
/// <param name="pathFile">The path to the file (Absolute path)</param>
/// <returns>If not have errors, return the file content (The interface <strong>T</strong>)</returns>
/// <exception cref="FileNotFoundException">This function check if the file exists</exception>
/// <exception cref="JsonException">When the file contains an invalid format</exception>
public static T ReadJSON<T>(string pathFile)
{
string content;
T? commands;

// Get absolute "Universal path"
pathFile = Paths.AbsoluteUniversalPath(pathFile);

Console.WriteLine($"PathFile => | {pathFile} |");

// Check file exist before read
if (Exists(pathFile))
{
try
{
// Try read and "Deserialize" the content
using StreamReader reader = new(pathFile);
content = reader.ReadToEnd();
commands = JsonSerializer.Deserialize<T>(content);

// The file is OK and was deserialized
if (commands != null) return commands;

}
catch (Exception)
{
throw;
}
}
else
{
throw new FileNotFoundException(string.Format("File \"{0}\" not found", pathFile));
}

throw new JsonException(string.Format("Was not possible deserialize the file \"{0}\"", pathFile));
}
}
}
1 change: 0 additions & 1 deletion src/App/configs/commands/Linux.jsonc

This file was deleted.

1 change: 0 additions & 1 deletion src/App/configs/commands/MacOs.jsonc

This file was deleted.

7 changes: 0 additions & 7 deletions src/App/configs/commands/Windows.jsonc

This file was deleted.

31 changes: 10 additions & 21 deletions src/App/models/os.commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* File: \os.commands.cs
* Created: Sunday, 20th July 2025 12:32:02 am
* -----
* Last Modified: Sunday, 27th July 2025 8:40:06 pm
* Last Modified: Monday, 28th July 2025 2:53:08 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/
Expand All @@ -23,36 +23,23 @@ public abstract class IOsCommands()
/// <summary>
/// On windows, command to show the "pip"
/// </summary>
public required string PipPaths { get; set; }
public abstract string PipPaths { get; }
/// <summary>
/// Find out the route of the "python"
/// </summary>
public required string PythonPaths { get; set; }
public abstract string PythonPaths { get; }
/// <summary>
/// Command to create new "venv"
/// </summary>
public required string CreateVenv { get; set; }
public abstract string CreateVenv { get; }
/// <summary>
/// Is used to activate the venv (usally is ".\venv\Scripts\activate" on Windows)
/// </summary>
public required string ActivateVenv { get; set; }
public abstract string ActivateVenv { get; }
/// <summary>
/// Usually is "pip -r requirements.txt"
/// </summary>
public required string RequirementsInstall { get; set; }

/// <summary>
/// Load the configs for the OS
/// </summary>
/// <typeparam name="T">The class Type</typeparam>
/// <returns>A object with the OS commands (Object type "T")</returns>
public static T LoadConfigs<T>() where T : IOsCommands
{
string OSName = typeof(T).Name.Replace("Commands", "");
T configs = Files.ReadJSON<T>($"./src/App/configs/commands/{OSName}.jsonc");
return configs;
}

public abstract string RequirementsInstall { get; }
public override string ToString()
{
string response = @$"OS Commands:
Expand All @@ -65,12 +52,14 @@ public override string ToString()

}

public static T Create<T>() where T : IOsCommands, new() => new();

/// <summary>
/// Get the properties of this Object
/// </summary>
/// <returns>A string array that contains all object properties</returns>
/// <exception cref="Exception"></exception>
public static string[] Properties()
public string[] Properties()
{
PropertyInfo[] props = typeof(IOsCommands).GetProperties();
string[] propStrings = new string[props.Length];
Expand All @@ -86,7 +75,7 @@ public static string[] Properties()
throw new Exception("Error trying get properties");
}

public static string GetProperty(IOsCommands instance, string property)
public string GetProperty(IOsCommands instance, string property)
{
string? value = typeof(IOsCommands).GetProperty(property)?.GetValue(instance)?.ToString();

Expand Down
36 changes: 36 additions & 0 deletions src/App/models/os.validators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* models - Initialize a virtual environment automatically
* Copyright 2025 - 2025 Dev2Forge
* Licence: GPL-3
* More information: https://github.com/Dev2Forge/Init-Venv/blob/main/LICENSE
* Author: tutosrive (tutosrive@Dev2Forge.software)
*
* File: \os.validators.cs
* Created: Monday, 28th July 2025 3:17:00 pm
* -----
* Last Modified: Monday, 28th July 2025 4:31:30 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/

namespace InitVenv.src.App.models
{
interface IOsValidators
{
/// <summary>
/// Check that <strong>python</strong> exixts in the system
/// </summary>
/// <returns>A bool that represents if <strong>python</strong> exists</returns>
public abstract Task<bool> CheckPythonPaths();
/// <summary>
/// Check that <strong>pip</strong> exists in the system
/// </summary>
/// <returns>A bool that represents if <strong>pip</strong> exists</returns>
public abstract Task<bool> CheckPipPaths();
/// <summary>
/// Check that <strong>requirements.txt</strong> exists in the same <strong>.venv</strong> directory
/// </summary>
/// <returns>A bool that represents if <strong>requirements.txt</strong> exists</returns>
public abstract bool CheckRequirementsFile();
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
/*
* models - Initialize a virtual environment automatically
* windows - Initialize a virtual environment automatically
* Copyright 2025 - 2025 Dev2Forge
* Licence: GPL-3
* More information: https://github.com/Dev2Forge/Init-Venv/blob/main/LICENSE
* Author: tutosrive (tutosrive@Dev2Forge.software)
*
* File: \windows.commands.cs
* Created: Friday, 18th July 2025 11:51:38 pm
* File: \Runner.cs
* Created: Monday, 28th July 2025 2:36:53 pm
* -----
* Last Modified: Sunday, 27th July 2025 9:20:26 pm
* Last Modified: Monday, 28th July 2025 3:57:47 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/

using System.Diagnostics;
using System.Text;
using InitVenv.src.App.os.windows.models;

namespace InitVenv.src.App.models
namespace InitVenv.src.App.os.windows
{
public class WindowsCommands : IOsCommands
class WindowsRunner
{
public static async Task<CommandResult> ExecuteCommandAsync(string filename, string argName, bool keep = false, bool userShell = false, bool wait = true)
public async Task<CommandResult> ExecuteCommandAsync(string filename, string command, bool keep = false, bool userShell = false, bool wait = true)
{
// Keep the console while command is completed
string ConsoleKeep = keep ? "/k" : "/c";

WindowsCommands commands = LoadConfigs<WindowsCommands>();
string? command = null;
int index = 0;
var propertiesCommands = Properties();

// Validate Property name (command name)
while (index < propertiesCommands.Length && command == null)
{
string prop = propertiesCommands[index];
if (prop != argName)
{
if (prop == propertiesCommands.Last())
{
throw new ArgumentException("The \"argName\" is invalid");
}
}
else
{
command = GetProperty(commands, prop);
}
index++;
}

Console.WriteLine($"[INFO] Executing command: \"{command}\"");

try
Expand Down Expand Up @@ -154,6 +132,5 @@ public static async Task<CommandResult> ExecuteCommandAsync(string filename, str
};
}
}

}
}
26 changes: 17 additions & 9 deletions src/App/os/windows/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@
* File: \Start.cs
* Created: Sunday, 27th July 2025 8:31:25 pm
* -----
* Last Modified: Sunday, 27th July 2025 8:46:31 pm
* Last Modified: Tuesday, 29th July 2025 7:40:57 pm
* Modified By: tutosrive (tutosrive@Dev2Forge.software)
* -----
*/

using InitVenv.src.App.models;
using InitVenv.src.App.os.windows.models;

namespace InitVenv.src.App.os.windows
{
public class WindowsInit
{
public static async Task Run()
{
CommandResult result = await WindowsCommands.ExecuteCommandAsync("cmd.exe", "PipPaths");
if (result.ExceptionData != null)
// Objects instances
WindowsRunner runner = new();
Validators validators = new(runner);
Commands commands = new();

// Validations
bool pythonIsOk = await validators.CheckPythonPaths();
bool pipIsOk = await validators.CheckPipPaths();
bool requirementsIsOk = validators.CheckRequirementsFile();

// Commands Executions
/* if (pythonIsOk)
{
foreach (var item in result.ExceptionData)
{
Console.WriteLine(item);
}
}
CommandResult resultPythonCommand = await runner.ExecuteCommandAsync("cmd.exe", commands.CreateVenv);
Console.WriteLine(resultPythonCommand.Error);
} */
}
}
}
Loading