After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 757126 - Make scripts in giscanner/ work for Python 2.x and Python 3.x in Visual Studio builds too
Make scripts in giscanner/ work for Python 2.x and Python 3.x in Visual Studi...
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: g-ir-scanner
unspecified
Other Windows
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-10-26 07:23 UTC by Fan, Chun-wei
Modified: 2016-02-19 06:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
g-ir-tool-template.in: Re-enable 'relocatability' on Windows (1.18 KB, patch)
2015-10-28 08:04 UTC, Fan, Chun-wei
committed Details | Review
msvccompiler.py: Make preprocessing work on Python 3.x (1.06 KB, patch)
2015-10-28 08:36 UTC, Fan, Chun-wei
committed Details | Review
ccompiler.py: Fix lib resolution on Windows for Python 3.x (1.86 KB, patch)
2015-10-28 08:39 UTC, Fan, Chun-wei
committed Details | Review
dumper.py: Fix ignore-of-embedding-manifest-errors for Python 3.x (1.12 KB, patch)
2015-10-28 08:40 UTC, Fan, Chun-wei
committed Details | Review
transformer.py: Fix --identifier-filter on Python 3.x (1.29 KB, patch)
2015-10-28 08:44 UTC, Fan, Chun-wei
committed Details | Review

Description Fan, Chun-wei 2015-10-26 07:23:40 UTC
Hi,

This is meant to continue the work in 679438 to make the introspection Python scripts work for Visual Studio builds, especially as better Visual Studio support came after Simon's work in bug 679438.

I will post my progress here...

With blessings, thank you!
Comment 1 Fan, Chun-wei 2015-10-28 08:04:40 UTC
Created attachment 314287 [details] [review]
g-ir-tool-template.in: Re-enable 'relocatability' on Windows

Hi,

First up is to make the template tool script work again on Windows with its 'relocatable' feature re-enabled, as the move to Python 3 compatibility removed this by accident...
Comment 2 Fan, Chun-wei 2015-10-28 08:36:10 UTC
Created attachment 314289 [details] [review]
msvccompiler.py: Make preprocessing work on Python 3.x

Hi,

This updates msvccompiler.py to make it work with Python 3.x, specifically the preprocessing part, when handling exceptions from distutils...
Comment 3 Fan, Chun-wei 2015-10-28 08:39:08 UTC
Created attachment 314290 [details] [review]
ccompiler.py: Fix lib resolution on Windows for Python 3.x

Hi,

This updates ccompiler.py where we look into the lib file(s) fed into g-ir-scanner to deduce the correct DLL that would be used by the generated .gir/.typelib files...
Comment 4 Fan, Chun-wei 2015-10-28 08:40:48 UTC
Created attachment 314291 [details] [review]
dumper.py: Fix ignore-of-embedding-manifest-errors for Python 3.x

Hi,

This makes the call to sys.exc_clear() only done on Python 2.x as it is only needed (and available) on Python 2.x...
Comment 5 Fan, Chun-wei 2015-10-28 08:44:15 UTC
Created attachment 314292 [details] [review]
transformer.py: Fix --identifier-filter on Python 3.x

Hi,

This is probably more of an all-platforms fix, where the case where a identifier filter script is used...

This is what I have now to fix the introspection scripts on Windows, in particular the Visual Studio builds.

With blessings, thank you!
Comment 6 Emmanuele Bassi (:ebassi) 2015-10-28 10:14:47 UTC
Review of attachment 314287 [details] [review]:

Sure.
Comment 7 Emmanuele Bassi (:ebassi) 2015-10-28 10:15:25 UTC
Review of attachment 314289 [details] [review]:

Okay.
Comment 8 Emmanuele Bassi (:ebassi) 2015-10-28 10:17:18 UTC
Review of attachment 314290 [details] [review]:

Okay.
Comment 9 Emmanuele Bassi (:ebassi) 2015-10-28 10:17:46 UTC
Review of attachment 314291 [details] [review]:

Okay.
Comment 10 Emmanuele Bassi (:ebassi) 2015-10-28 10:18:18 UTC
Review of attachment 314292 [details] [review]:

Okay.
Comment 11 Fan, Chun-wei 2015-10-28 14:11:34 UTC
Hi Emmanuele,

Thanks for the really quick reviews :)

The patches were pushed to master as:
Attachment 314287 [details]: 6492ac6
Attachment 314289 [details]: f12d853
Attachment 314290 [details]: ee28491
Attachment 314291 [details]: 3bb86de
Attachment 314292 [details]: cb1fabb

Closing bug now.

With blessings, thank you!
Comment 12 Mikhail Zabaluev 2015-10-29 04:55:12 UTC
(In reply to Fan, Chun-wei from comment #1)
> Created attachment 314287 [details] [review] [review]
> g-ir-tool-template.in: Re-enable 'relocatability' on Windows
> 
> First up is to make the template tool script work again on Windows with its
> 'relocatable' feature re-enabled, as the move to Python 3 compatibility
> removed this by accident...

Have you considered using setuptools for installation of the Python modules?
By setuptools conventions, the binaries are generated by setup.py, so you can't bake configurable values as globals into the binaries. Instead, these can be put into the package metadata by setup.py, which in turn can be created as part of AC_CONFIG_FILES by configure. On the upside, setuptools take care of the platform variation, so you can get rid of the "if os.name == 'nt'" spaghetti.

Installing the modules into standard Python locations will effectively make them public and reusable:
https://bugzilla.gnome.org/show_bug.cgi?id=755385

FYI, I have forked a part of the giscanner modules into a larger project which is installed by setuptools: https://github.com/gi-rust/grust-gen/tree/master/grust/gi

I didn't go for the metadata approach discussed above, instead I just stopped using the configured DATADIR as it is not needed for that project. Still, the template directory is resolved relatively to the package using the pkg_resources API, which could also be used to get at configure-time package artefacts:
https://github.com/gi-rust/grust-gen/blob/master/grust/genmain.py#L76
Comment 13 Fan, Chun-wei 2015-10-29 07:45:16 UTC
Hi Mikhail,

I think that suggestion might[1] be good in the long run, but since this bug is more on making the giscanner scripts work for Visual Studio builds (and at least restoring what used to be able to be done on Windows builds), let's redirect attention for this to your bug report, 755385.

The main reason for mentioning this is because the suggestion would be out of scope by quite a bit for this bug report here.

Thanks though, with blessings.

[1]: This would also involve what the core maintainers of g-i has to say about doing this.
Comment 14 Cosimo Lupo 2016-02-16 13:05:11 UTC
(In reply to Fan, Chun-wei from comment #2)
> Created attachment 314289 [details] [review] [review]
> msvccompiler.py: Make preprocessing work on Python 3.x
> 
> Hi,
> 
> This updates msvccompiler.py to make it work with Python 3.x, specifically
> the preprocessing part, when handling exceptions from distutils...


The commit f12d853 introduced an undefined name 'msg' error.
You need to use `except ... as ...` statement instead, as shown below:

diff --git a/giscanner/msvccompiler.py b/giscanner/msvccompiler.py
index d578577..86049da 100644
--- a/giscanner/msvccompiler.py
+++ b/giscanner/msvccompiler.py
@@ -80,7 +80,7 @@ class MSVCCompiler(distutils.msvccompiler.MSVCCompiler):
         if self.force or output_file is None or newer(source, output_file):
             try:
                 self.spawn(cpp_args)
-            except (DistutilsExecError, msg):
+            except DistutilsExecError as msg:
                 print(msg)
                 raise CompileError

Thanks.
Comment 15 Fan, Chun-wei 2016-02-19 06:08:08 UTC
Hi Cosimo,

Thanks, the problem was fixed in commit f5cc8f5.

With blessings.