Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and convert to torchsharp code #99

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
25618b2
Add replacement class type
Feb 28, 2023
72aec93
Merge branch 'master' of https://github.com/toolgood/pytocs
Feb 28, 2023
4850478
fix void to object
Feb 28, 2023
86dfbf6
Convert python's [:,:,x[:,:]] syntax, used recurrence , exclude nesting
Feb 28, 2023
4c43cec
Replace type by class area and static method area , More accurate
Mar 2, 2023
a423599
Class creation of standardized import
Mar 2, 2023
c42e803
replace forward method's ReturnType object => Tensor
Mar 2, 2023
3504e68
Match method names beginning with @ . Set common name type .
Mar 2, 2023
2033357
Determine the field type of the class and the parameter type of the m…
Mar 2, 2023
3e914fb
fix split paramenter string bug.
Mar 2, 2023
890bf2e
Modify the corresponding method parameter type according to the metho…
Mar 3, 2023
ed3c5ba
Add Run Code
Mar 3, 2023
08fe416
add 'remove' method
toolgood Mar 3, 2023
40f91fc
add python list methods
Mar 4, 2023
f720d31
add python Dictionary method.
Mar 4, 2023
c795428
add python copy method
Mar 4, 2023
c24954c
add license info
Mar 4, 2023
a1fbb96
Add more default type judgments
Mar 6, 2023
bddecfd
add 'RegexOptions.IgnoreCase' and remark
Mar 6, 2023
d625769
replace throw new ValueError
Mar 6, 2023
a517174
Add method regular matching with ReturnType 'object []'
Mar 7, 2023
fef4a43
Add variable name matching in method
Mar 7, 2023
b16d839
fix 'cli -r' error. add 'cli -r XXX -o --output XXX' export files to …
Mar 7, 2023
c6cef91
fix cli bug
Mar 7, 2023
21b779b
fix Convert python's [:,:,:] syntax: ':' => TensorIndex.Colon
Mar 9, 2023
e15553e
Adapt python code
Mar 9, 2023
a625ba9
Turn off netstandard.cs code style prompt
Mar 9, 2023
b1ca10e
add PythonFile class
Mar 9, 2023
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
42 changes: 31 additions & 11 deletions src/Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Pytocs.Cli
{
public class Program
{
private const string usage =
private const string usage =
@"Usage:
pytocs [options]

Expand All @@ -37,6 +37,7 @@ pytocs [options]
all its subdirectories [default: .]
-p, --post-process PPLIST Post process the output using one or more
post-processor(s), separated by commas.
-o, --output DIRECTORY Output folder path.
-q, --quiet Run with reduced output.
";
public static void Main(string[] argv)
Expand Down Expand Up @@ -64,6 +65,7 @@ public static void Main(string[] argv)
var startDir = (string) oStartDir;
if (startDir == "." || startDir == "./" || startDir == ".\\")
startDir = Directory.GetCurrentDirectory();
startDir = Path.GetFullPath(startDir);
typeAnalysis.Analyze(startDir);
typeAnalysis.Finish();
var types = new TypeReferenceTranslator(typeAnalysis.BuildTypeDictionary());
Expand All @@ -72,6 +74,10 @@ public static void Main(string[] argv)
//{
// Console.WriteLine("{0}: {1} {2}", de.Key, de.Key.Start, de.Value);
//}
var outputDir = options.ContainsKey("--output") ? (string) options["--output"] : startDir;
if (outputDir == "." || outputDir == "./" || outputDir == ".\\")
outputDir = Directory.GetCurrentDirectory();
outputDir = Path.GetFullPath(outputDir);

var walker = new DirectoryWalker(fs, startDir, "*.py");
walker.Enumerate(state =>
Expand All @@ -91,13 +97,16 @@ public static void Main(string[] argv)
logger.Error("Unable to load {0}.", path);
continue;
}
string outputPath = Path.ChangeExtension(path, ".py.cs").Replace(startDir, outputDir);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath)!);

xlator.TranslateModuleStatements(
module.Body.Statements,
types,
Path.ChangeExtension(path, ".py.cs"));
outputPath);
}
});
}
}
else
{
if (!options.TryGetValue("<files>", out var oFiles) ||
Expand Down Expand Up @@ -134,13 +143,14 @@ public static void Main(string[] argv)
}
}

private static IDictionary<string,object> ParseOptions(string[] args)
private static IDictionary<string, object> ParseOptions(string[] args)
{
var result = new Dictionary<string, object>();
var files = new List<string>();
for (int i = 0; i < args.Length; ++i)
int i = 0;
while (i < args.Length)
{
var arg = args[i];
var arg = args[i++];
if (!arg.StartsWith('-'))
{
files = args.Skip(i).ToList();
Expand All @@ -159,17 +169,27 @@ private static IDictionary<string,object> ParseOptions(string[] args)
case "-r":
case "--recursive":
var dirname = ".";
if (i < args.Length - 1)
if (i < args.Length)
{
if (!args[i + 1].StartsWith('-'))
if (!args[i].StartsWith('-'))
{
++i;
dirname = args[i];
dirname = args[i++];
}
break;
}
result["--recursive"] = dirname;
break;
case "-o":
case "--output":
var dirname2 = ".";
if (i < args.Length)
{
if (!args[i].StartsWith('-'))
{
dirname2 = args[i++];
}
}
result["--output"] = dirname2;
break;
}
}
result["<files>"] = files;
Expand Down
Loading