Skip to content

Code conversion tools, mostly just for removing dependencies so far. Eliminates various issues and .NET calls such as introduced by icsharpcode snippet converter C# to Python translation. NOTE: Should be rewritten to use SLY.

License

Notifications You must be signed in to change notification settings

Hierosoft/pycodetool

Repository files navigation

pycodetool

(formerly PythonCodeTranslators)

Process code using Python. Search and process various languages using context (such as scope, comments, quotes, and escaping).

Features

Python parsing

  • Export a list of all global identifiers (after pre-processing on load).
  • Convert IronPython to standard Python: Remove the need for framework dependencies, using automatic refactoring and shim functions (see fxshim.py).

Commands

Installing the module provides the following commands:

  • changes: Look for repos in the current directory and show what changes are not yet committed (including untracked).
  • ggrep: Get a geany command to go to the line in the file from grep (searching within file(s)). Recursively search directories by default.

This package is used by:

  • linux-preinstall: Extract linux-preinstall and add linux-preinstall/utilities and linux-preinstall/utilities-developer to your environment's PATH to get the commands above without installing pycodetool. For best results, place the linux-preinstall and pycodetool repos in the same directory.

Python.NET to standard Python

(framework_to_standard_python)

Note that GUI conversion is not tested or supported, but you can try it the manually implement whatever is missing (or use IronPython as necessary and not use pycodetool).

STEP 1

For now, you must use SharpDevelop 4.4.

  • Why: The snippet converter isn't online anymore--only a stripped down open source one is there and it only converts between C# and VB.NET. See icsharpcode/CodeConverter#709.
  1. Open the project in SharpDevelop (4.4 is tested). If you can't open the project, merely create a new project and add all of the C# files first.
  2. Click "Project" (in the Menu bar at the top), "Convert", "From C# to Python"

See also C# to Haxe converters:

(Haxe can now output Python)

See also C# to Python converters:

Discussions about C# to Python conversion:

Non-working:

STEP 2

This step (and this project) is only necessary if you have some sort of IronPython code (such as created using SharpDevelop's C# to Python converter).

python_remove_dotnet.py removes non-standard Python as follows:

  • Eliminates various issues and .NET calls such as introduced by SharpDevelop's C# to Python translation (formerly available in icsharpcode snippet converter)
  • Removes "from System" imports
  • Removes "Exception" and uses traceback instead of an exception object
  • Changes "Substring" to slice notation (converts count to end)
  • Fixes issue with icsharpcode snippet converter using ArrayList and forgetting it renamed it starting with _
  • Changes ArrayList iteration to list iteration
  • Comments duplicate methods (and shows warning during parsing)
  • Changes Console.Error.Write to sys.stdout.write (and ALWAYS prepends 'import sys' if not already present)
  • Changes Console.WriteLine to print
  • Changes Console.Error.WriteLine to sys.stderr.write, write("\n"), flush()
  • Changes something.ToString() to str(something)
  • Add 'pass' where icsharpcode converter issue leaves no indented area under 'except' or 'finally'
  • Parse StreamReader (local) usage, changing 'while' to 'for', making temp variable for ReadLine and then putting temp.rstrip() into the programmer's variable
  • Parse StreamWriter (scope not yet checked) changing WriteLine(something) to write(something+"\n")
  • Change '.Trim()' to '.strip()'

Changes

See changelog.md.

Known Issues

Developer Notes

Documentation

Tools

Testing

Use nose such as via python3 -m nose in the repo directory (requires the nose package such as via python3 -m pip install --user nose).

About

Code conversion tools, mostly just for removing dependencies so far. Eliminates various issues and .NET calls such as introduced by icsharpcode snippet converter C# to Python translation. NOTE: Should be rewritten to use SLY.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published