IronLanguages / IronLanguages/ironpython3

The ipyc /out: option dose not change the output path of exe host

Open
#1,785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.8k
Forks
316
Avg merge
1d 9h
Merged PRs (30d)
1

Description

Prerequisites

ipyc /out: option dose not change the output path of exe host.

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?
Description

When I set the output to bin\Program with ipyc /out:bin/Program /main:Program.py, the Program.exe still output at the path which Program.py at. And the host get the Program.dll at bin/Program.dll, as I can not just copy the exe to bin. If I set the output path to an absolute path, I even can not move the program to another place...

public class PythonMain
{
    public static int Main()
    {
        try
        {
            string currentDirectory = Environment.CurrentDirectory;
            Environment.CurrentDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).Directory.FullName;
            string fullPath = Path.GetFullPath("bin/Program.dll");
            Environment.CurrentDirectory = currentDirectory;
            return PythonOps.InitializeModuleEx(Assembly.LoadFile(fullPath), "__main__", null, ignoreEnvVars: false, null);
        }
        catch (Exception ex)
        {
            string currentDirectory = ex.Message;
            Console.WriteLine("Error occurred: {0}", currentDirectory);
            return -1;
        }
    }
}

So why not combined the host and dll just like JScript?

public class JScript Main
{
    [STAThread(/*Could not decode attribute arguments.*/)]
    public static void Main(string[] P_0)
    {
        GlobalScope globalScope = VsaEngine.CreateEngineAndGetGlobalScope(fast: true, new string[5] { "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" });
        JScript 0 obj = new JScript 0(globalScope);
        globalScope.engine.PushScriptObject(obj);
        obj.Global Code();
        new JScript 1(globalScope).Global Code();
        globalScope.engine.PopScriptObject();
    }
}

To fixed that I must create a host by myself. I referenced to the dll so I can just get the assembly by Assembly.LoadFrom.

using IronPython.Runtime.Operations;
using System.Reflection;
using System;

try
{
    return PythonOps.InitializeModuleEx(Assembly.LoadFrom("Samples.PY.dll"), "__main__", null, ignoreEnvVars: false, null);
}
catch (Exception ex)
{
    Console.WriteLine("Error occurred: {0}", ex.Message);
    return -1;
}

https://github.com/wherewhere/MSBuild.Sdk.Extras/tree/main/Samples/Samples.PY.Host

Version Information

IronPython 3.4.1 (3.4.1.1000)
[.NETFramework,Version=v4.6.2 on .NET Framework 4.8.9181.0 (64-bit)]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the ipyc /out: and /main: handling that produces the executable and DLL. Compare the reported PythonMain host behavior with the referenced Samples.PY.Host example and the Assembly.LoadFrom approach. Done means /out:bin/Program places the executable and its required output together so the executable can be moved and run from that location.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.