gprbuild -ws -c -f -u -PP:\Gnat\testpy.gpr Analysis.py
testpy.gpr:7:26: language unknown for "analysis.py"
gprbuild: "P:\Gnat\testpy.gpr" processing failed
[2022-11-10 16:23:10] process exited with status 4, elapsed time: 03.78s
I'm trying to compile some Python files from an Ada project (in an integration which will consist of Ada, Python and Rust).
1. If you want to create a Python module in a form of a dynamically
linked library, you must use C or Ada for that.
Not the case, I also don't see advantages of it (so I agree, I'd go directly to Ada or C).
2. If you rather meant pre-compiled binary code (*.pyc). Python creates
them by py_compile command. See
https://docs.python.org/3/library/py_compile.html#py_compile.compile
There is also command-line interface:
https://docs.python.org/3/library/compileall.html
You possibly could configure gpr to call compileall on *.py files,
though it would make no sense to me.
I think this would be the closer of what I was trying to do.
The idea is to help in the development. Instead of having to develop the Python part from a separate IDE, being able to code in the same would
speed up things.
Would you have some example of it? (how to configure gpr to call
compileall on *.py files).
Python is not a compiled language.Indeed. It will not generate an object like any compiled language.
1. If you want to create a Python module in a form of a dynamically
linked library, you must use C or Ada for that.
2. If you rather meant pre-compiled binary code (*.pyc). Python creates
them by py_compile command. See https://docs.python.org/3/library/py_compile.html#py_compile.compile
There is also command-line interface: https://docs.python.org/3/library/compileall.html
You possibly could configure gpr to call compileall on *.py files,
though it would make no sense to me.
You could start with something like this:
project Python is
for Languages use ("Python");
package Compiler is
for Driver ("Python") use "C:/GNAT/2021/libexec/gnatstudio/gnathub/share/gnathub/python/python.exe"; for Required_Switches ("Python") use ("-m", "compileall");
end Compiler;
package Naming is
for Body_Suffix ("Python") use ".py";
end Naming;
end Python;
gprbuild: no linker specified and no default linker in the configuration(where idk if it makes sense since we wont be linking to an object)
Got it. I didn't include naming and compiler options.
Now it runs, but it asks for a linker
gprbuild: no linker specified and no default linker in the configuration(where idk if it makes sense since we wont be linking to an object)
For a no error py it "compiles" clean (ok I'll call compilation, but we understand
it's not "the compilation"), but in compilation log it doesn't show the warnings
that are included in the edit window with the opened file. If I include
an error, it shows in the log where the error happened, but doesn't show in the locations. GPS will be not very useful this way.
On 2022-11-11 12:28, Rego, P. wrote:
Got it. I didn't include naming and compiler options.
Now it runs, but it asks for a linker
gprbuild: no linker specified and no default linker in the configuration(where idk if it makes sense since we wont be linking to an object)
For a no error py it "compiles" clean (ok I'll call compilation, but
we understand
it's not "the compilation"), but in compilation log it doesn't show
the warnings
that are included in the edit window with the opened file. If I include
an error, it shows in the log where the error happened, but doesn't
show in
the locations. GPS will be not very useful this way.
This "compiles" only:
project Python is
for Languages use ("Python");
package Compiler is
for Driver ("Python") use "C:/GNAT/2021/libexec/gnatstudio/gnathub/share/gnathub/python/python.exe";
for Required_Switches ("Python") use ("-m", "py_compile");
end Compiler;
package Naming is
for Body_Suffix ("Python") use ".py";
end Naming;
end Python;
It should show syntax errors. If you remove -m py_compile switches, then
it will "compile" and execute.
(Python is not the thing you would wish to use in an IDE or anywhere,
pretty much consistently so... (:-))
You could start with something like this:Thanks Dmitry!
project Python isGot it. I didn't include naming and compiler options.
for Languages use ("Python");
package Compiler is
for Driver ("Python") use "C:/GNAT/2021/libexec/gnatstudio/gnathub/share/gnathub/python/python.exe"; for Required_Switches ("Python") use ("-m", "compileall");
end Compiler;
package Naming is
for Body_Suffix ("Python") use ".py";
end Naming;
end Python;
Now it runs, but it asks for a linker
gprbuild: no linker specified and no default linker in the configuration(where idk if it makes sense since we wont be linking to an object)
For a no error py it "compiles" clean (ok I'll call compilation, but we understand
it's not "the compilation"), but in compilation log it doesn't show the warnings
that are included in the edit window with the opened file. If I include
an error, it shows in the log where the error happened, but doesn't show in the locations. GPS will be not very useful this way.
It should show syntax errors. If you remove -m py_compile switches, then
it will "compile" and execute.
(Python is not the thing you would wish to use in an IDE or anywhere,
pretty much consistently so... (:-))
There are a couple of project level attributes you can play around with:
for Object_Generated("Python") use "False";
and
for Objects_Linked("Python") use "False";
Note that Linker does not take language e.g. ("Python") you just write: package Linker is
for Driver use "pyinstaller.exe";
You have to tinker a bit since there is no object files to feed the
Linker. Maybe you could sell it *.py as an "archive" (static library). Whatever... (:-))
There are a couple of project level attributes you can play around with: for Object_Generated("Python") use "False";I had tried those before, removed because it didn't change anything (or it seemed)
and
for Objects_Linked("Python") use "False";
Now after including Linker package I put them back, still no effect.
It should show syntax errors. If you remove -m py_compile switches, then
it will "compile" and execute.
Got some error when removed -m switch C:\GNAT\2021\libexec\gnatstudio\gnathub\share\gnathub\python\python.exe: can't open file 'compileall': [Errno 2] No such file or directory
Project level, not in the Linker packageYep, as I did.
1. for Required_Switches ("Python") use ("-m", "py_compile");
2. for Required_Switches ("Python") use ("-m", "compileall");
3. nothing
Hello everyone, long time no see some of you, I hope everyone is fine.
I'm trying to compile some Python files from an Ada project (in an integration which will consist of Ada, Python and Rust). But let's
simplify the things, so I created a Python-only project using this :
-- testpy.gpr
project Testpy is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("Analysis.py");
for Languages use ("Python");
for Source_Files use ("Analysis.py");
end Testpy;
and as I tried to compile `Analysis.py` I got the messages
gprbuild -ws -c -f -u -PP:\Gnat\testpy.gpr Analysis.py
testpy.gpr:7:26: language unknown for "analysis.py"
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 43:58:32 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,952 |