[Qt-creator] Dealing with python projects
Christian Gagneraud
chgans at gmail.com
Wed Apr 24 11:45:56 CEST 2019
On Wed, 24 Apr 2019 at 19:20, Christian Kandeler
<Christian.Kandeler at qt.io> wrote:
>
> On Wed, 24 Apr 2019 12:49:19 +1200
> Christian Gagneraud <chgans at gmail.com> wrote:
>
> > So I recently switched to using Qbs. It currently allows me to
> > organise my python files, and QtCreator is happy with this "broken"
> > qbs project (broken=cannot be built).
> > One interesting feature is that i can configure QtC to run the test
> > webserver using a simple wrapper script. And with a project type of
> > "python" (or whatever is not recognised by qbs) QtC skip the build
> > process.
>
> I don't think you need to do that. If there's no cpp sources or libraries around, the build process is a no-op for an Application as well.
> By the way, if your main python file has a shebang at the top, you can get a run configuration for it by simply tagging it as an application. (It involves a copy because source artifacts cannot be target artifacts in qbs atm, but that's not a limitation in practice).
> For instance:
>
> -----
> import qbs.File
>
> Application {
> Group {
> name: "main script"
> files: "pythontest.py"
> fileTags: "python"
> }
> Rule {
> inputs: "python"
> Artifact {
> filePath: input.baseName + "-exe.py"
> fileTags: "application"
> }
> prepare: {
> var cmd = new JavaScriptCommand();
> cmd.description = "creating " + output.fileName;
> cmd.sourceCode = function() { File.copy(input.filePath, output.filePath); };
> return cmd;
> }
> }
> }
> -----
>
> If you open this project in Qt Creator, Ctrl+R will run your python script.
Hi Christian,
Thanks a lot for the tip. I'll have to investigate further.
The python project i'm working on is django based [1], and it requires
me to run a particular script ("./manage.py runserver"), *in the
source directory*, within a virtual python env (hence my wrapper
script). I just started this (qtc+qbs) experiment today, and right now
i'm more interested by the "QtC experience" than the "Qbs experience".
By that i mean that i want my IDE to help me while developing:
add/remove/rename files (works better than CMake), intelligent code
completion (code model, see below), but ideally "run" and "test" steps
as well. "test" being way more important to me than "run" (by a huge
factor). I have 2 kind of tests: unit tests ("./manage.py test", light
&fast) and acceptance tests ("./manage.py behave", heavy & slow), this
is classic django stuff really.
As well i've noticed some sort of "static analyser" behaviour for
python within QtC, I know QtC picks up my .clang-tidy when i do C++,
but I wonder about python and my setup.cfg (pycodestyle+flake8), is it
recognised/supported by QtC? I definitely get insights related to my
pycodestyle+flake8 config... Looks good to me!
Downside is that code completion depends on my pip/virtualenv, so i
need to (re)start QtC within my venv shell each time i add a package
to it... :(
Chris
[1] https://www.djangoproject.com/
More information about the Qt-creator
mailing list