summaryrefslogtreecommitdiff
path: root/giscanner/utils.py
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'mypy-basics' into 'master'Christoph Reiter2020-11-081-2/+2
|\ | | | | | | | | Add basic mypy support; Require Python 3.5 See merge request GNOME/gobject-introspection!251
| * Add basic mypy supportChristoph Reiter2020-11-071-2/+2
| | | | | | | | | | | | Silence some errors, run mypy in CI Adding annotations to functions/classes will make mypy check them.
* | Merge branch 'open-cleanup' into 'master'Christoph Reiter2020-11-071-2/+2
|\ \ | | | | | | | | | | | | open cleanup: explicit encoding, close fds See merge request GNOME/gobject-introspection!250
| * | Always pass an encoding to open() using text modeChristoph Reiter2020-11-071-2/+2
| |/ | | | | | | | | | | | | | | Otherwise we'll end up using the locale encoding. While it's usually utf-8, that's not the case on Windows. There is one place where a file with filenames is passed, not sure there so I left it and passed a explicit None.
* | Remove LibtoolImporterChristoph Reiter2020-11-071-15/+1
|/ | | | | From what I can see this was used for importing the C ext in an uninstalled libtool build of g-i. We no longer use libtool, so this is no longer needed.
* monkey patch distutils.cygwinccompiler.get_msvcrjensgoe2020-10-141-0/+30
|
* Update utils.pyneok2020-05-101-1/+1
|
* Windows: Fix building and running on Python 3.8+Chun-wei Fan2020-01-161-0/+36
| | | | | | | | | | | | | | | | | | | | | | | Python 3.8.x and later changed the way how dependent DLLs can be found for a given Python module that depends on the presence of external, non-system DLLs, for more fine-grained DLLs searching and loading, as well as for security purposes, which required the use of os.add_dll_directory(). Thus, the scripts in scanner/ must be updated such that: -We are able to find and load the GObject and GLib DLLs, at least, on initialization, via the use of 'pkg-config --variable bindir', as we already depend on the GLib DLLs. Note that since the gobject-2.0.pc file does not have a 'bindir' entry, we use gio-2.0.pc instead to discover the bindir of the GObject and GLib DLLs. Likewise, we use the same technique for pkg-config files that are dependent upon when using g-ir-scanner (or friends) on items that are higher up in the stack. -We are able to find any other DLLs (e.g. non-GNOME DLLs such as ZLib) that are dependent but are not found in the path(s) given by 'pkg-config --variable bindir' with the envvar GI_EXTRA_BASE_DLL_DIRS, as needed. Note that GI_EXTRA_BASE_DLL_DIRS can be multiple paths, and that the results from 'pkg-config --variable bindir' takes precendence, in a LIFO manner.
* Drop all Python 2 compat codeChristoph Reiter2018-12-081-40/+2
| | | | We only support 3.4+ now.
* flake8 updates, fixes "make check.quality"Christoph Reiter2018-11-041-1/+1
| | | | | Disables the new "W504 line break after binary operator" warning. Fixes wrong escape sequences "W605 invalid escape sequence '\.'"
* tests: depend on flake8 instead of including pep8/pyflakesChristoph Reiter2018-08-151-2/+3
| | | | | | | | | | | | | | | | g-i includes an old version of pep8 and pyflakes and uses that during "make check". It (1) doesn't catch all cases newer versions of pycodestyle/pyflakes catch and (2) doesn't test all Python files (3) doesn't work with meson. Instead of updating just remove them and depend on flake8 instead. To run the checks simply run flake8 in the root dir. This also makes it possible to run those checks when using meson and not autotools. To not get test suite failures on flake8 updates move the checks from "make check" to an extra "make check.quality" target.
* utils: fix undefined cdir variableChristoph Reiter2018-08-111-0/+3
| | | | | The docstring states that makedirs() was ported from python3, but this code part was missing. Found with newer pyflakes.
* Add utils.rmtree() which waits and tries again if a file is still in useChristoph Reiter2018-06-201-0/+25
| | | | | | | | | | | | | | | On Windows the dumper cleanup regularely fails because the created .exe is still in use by some process and shutil.rmtree() fails with: OSError: [WinError 145] The directory is not empty I'm not 100% sure what's the cause for this, but searching for similar issues suggests that it might be Windows Defender scanning the newly created .exe file and because it's so short lifed the scanning and deleting conflict. This adds a helper which tries a few times and waits a bit before giving up. A similar patch has been in MSYS2 for some time: https://github.com/Alexpux/MINGW-packages/blob/d0c39af02a669e45272c713e912ee63b0dd94157/mingw-w64-gobject-introspection/0025-more-tolerant-rmtreeing.patch
* Allow overriding of the host os nameNicola Fontana2018-01-251-0/+4
| | | | | | | | Added the GI_HOST_OS environment variable to eventually specify the host OS explicitely. It fall backs to os.name to retain backward compatibility. https://bugzilla.gnome.org/show_bug.cgi?id=761985
* When handling errors according to errno, catch both IOError and OSErrorSimon McVittie2017-06-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Different Python versions are not completely consistent about the error that is raised and its class hierarchy: Python 3.5.3rc1 (default, Jan 3 2017, 04:40:57) >>> try: open('/foo') ... except Exception as e: print(e.__class__.__mro__) (<class 'FileNotFoundError'>, <class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>) Python 2.7.13 (default, Dec 18 2016, 20:19:42) >>> try: open('/foo') ... except Exception as e: print e.__class__.__mro (<type 'exceptions.IOError'>, <type 'exceptions.EnvironmentError'>, <type 'exceptions.StandardError'>, <type 'exceptions.Exception'>, <type 'exceptions.BaseException'>, <type 'object'>) This can lead to a race condition during cache cleaning, where two processes both try to delete the same file, and the one that loses the race fails. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Iain Lane <laney@ubuntu.com> Reviewed-by: Colin Walters <walters@verbum.org> Bug: https://bugzilla.gnome.org/show_bug.cgi?id=772173
* giscanner/utils.py: Fix on non-UNIX-like platformsChun-wei Fan2017-06-151-1/+1
| | | | | | | | | | Commit 85b1d70b93211415d975deff6050f1401743e72d changed the null device from the platform-independent os.devnull to the UNIX /dev/null, which broke introspection builds on non-UNIX-like platforms, as /dev/null is a notion that does not exist on those platforms. Fix this by changing back to os.devnull, but still opening it as writable. https://bugzilla.gnome.org/show_bug.cgi?id=781312
* Fix 'Bad file descriptor' error when checking libtool versionSam Thursfield2017-04-151-1/+1
| | | | | | | | | | | | Running g-ir-scanner on Fedora 25 (libtool 2.4.6) produces the following message on stderr, twice: /usr/bin/libtool: line 2460: printf: write error: Bad file descriptor This is because we were redirecting stdout to /dev/null incorrectly -- we were opening /dev/null for reading rather than for writing. https://bugzilla.gnome.org/show_bug.cgi?id=781312
* giscanner: Use unicode literals in all Python filesSimon Feltman2015-09-291-1/+2
| | | | | | | | | | | | Add unicode_literals future import which turns any string literal into a unicode string. Return unicode strings from the Python C extension module. Force writing of annotations (g-ir-annotation-tool) to output utf8 encoded data to stdout. This is an initial pass at following the "unicode sandwich" model of programming (http://nedbatchelder.com/text/unipain.html) needed for supporting Python 3. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Use print as a function for Python 3 compatibilitySimon Feltman2015-09-291-0/+1
| | | | | | | Use future import "print_function" and update relevant uses of print as a function call. See: PEP 3105 https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Enable "true division" for all Python filesSimon Feltman2015-09-291-0/+1
| | | | | | | | | | Import Python 3 compatible "true division" from the future (PEP 238). This changes the Python 2 classic division which uses floor division on integers to true division. Verfied we don't actually use the division operator anywhere in the code base so this a safety for supporting both Python 2 and 3. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Use absolute_import for all Python filesSimon Feltman2015-09-291-0/+1
| | | | | | Use absolute_import to ensure Python 3 compatibility of the code base. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Use binary files for comparison utilitySimon Feltman2015-09-291-1/+1
| | | | | | | Explicitly open files for comparison in utils.files_are_identical() in binary mode for reading (rb). https://bugzilla.gnome.org/show_bug.cgi?id=679438
* scanner: use open() as os.fdopen as context managersDieter Verfaillie2015-08-211-14/+9
| | | | | | Ensures files are correctly and immediately closed. https://bugzilla.gnome.org/show_bug.cgi?id=751926
* scanner: add "XDG Base Directory" functionsDieter Verfaillie2015-06-201-0/+79
| | | | | | | | | | | | Extract cache and data dir lookup code into documented get_user_cache_dir() and get_system_data_dirs() functions. Note that previously, the data dirs code did not fall back to '/usr/local/share:/usr/share' when the XDG_DATA_DIRS environment variable was either not set or empty, as required by the XDG Base Directory Specification. https://bugzilla.gnome.org/show_bug.cgi?id=747770
* Fix some PEP8 errors from previous commitsColin Walters2014-02-221-1/+4
|
* scanner: Support running under MSYSРуслан Ижбулатов2014-02-221-0/+24
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=724880
* Extend the hack towards backslashes as path separatorsРуслан Ижбулатов2014-02-221-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=724877
* scanner: Improve compatibility with OS XClemens Lang2014-02-101-2/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While gobject-introspection works on OS X, a few circumstances are handled a little different there. For one, libraries are linked using absolute paths. The current gobject-introspection code however strips any path components and just uses the filename in the .gir file – while this doesn't cause failure, the generated typlibs will only work in presence of a correctly set DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH environment variable. Setting DYLD_LIBRARY_PATH on OS X often is a bad idea due to the side-effects: Doing so causes the directory parts of libraries referenced using an absolute path to be ignored if there is a equally named file in the directory listed in $DYLD_LIBRARY_PATH, possibly overriding referenced system libraries with incompatible versions. Setting DYLD_FALLBACK_LIBRARY_PATH is the better solution for this problem; however because this variable has an implicit default value it's not simple to do so correctly. The best solution to the problem is referencing libraries from .girs using absolute paths, just as all other binaries on OS X. The attached patches against 2.38.0 implement that. Another quirk one needs to be aware of on OS X is that Apple ships a program called libtool, which is not GNU libtool and incompatible with it. GNU libtool, if present, is usually called glibtool on OS X. The patches also fix this. https://bugzilla.gnome.org/show_bug.cgi?id=709583
* giscanner: Make sure we use real paths in more placesCarlos Garcia Campos2013-11-151-0/+7
| | | | | | | | Ensure we are using the real path also for cflags comming from pkg_config files and command line options. This fixes the generation of the gir files when include paths contain symlinks. https://bugzilla.gnome.org/show_bug.cgi?id=712211
* tests: Update misc/pep8.py to 1.4.5Dieter Verfaillie2013-05-071-0/+9
| | | | | | | | | | | | | | | | | Version in our tree is a wee bit outdated. For example, later work will introduce an utf8 encoded python source file which our old pep8.py does not yet understand (yeah, it really was *that* ancient)... Updated from: https://raw.github.com/jcrocholl/pep8/1.4.5/pep8.py Takes 552c1f1525e37a30376790151c1ba437776682c5, f941537d1c0a40f0906490ed160db6c79af572d3, 5a4afe2a77d0ff7d9fea13dd93c3304a6ca993de and a17f157e19bd6792c00321c8020dca5e5a281f45 into account... https://bugzilla.gnome.org/show_bug.cgi?id=699535
* giscanner: remove unused variablesDieter Verfaillie2012-11-281-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=688897
* scanner: complete the enum-to-error-quark fixGiovanni Campagna2012-06-181-1/+4
| | | | | | | | | | Turns out that the problem was not only in the wrong matching to GType enums, but also that the non-GType heuristics used to_underscores instead of to_underscores_noprefix, turning DBusError into D_Bus_Error instead of DBus_Error. Complete with various tests. https://bugzilla.gnome.org/show_bug.cgi?id=669350
* scanner: Add various static debug hooks in GI_SCANNER_DEBUGColin Walters2010-09-071-0/+21
| | | | | | | For backwards compat, keep the presence of the environment variable at all to mean "exception". Also start a HACKING file.
* Major rewriteColin Walters2010-08-311-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One of the first big changes in this rewrite is changing the Type object to have separate target_fundamental and target_giname properties, rather than just being strings. Previously in the scanner, it was awful because we used heuristics around strings. The ast.py is refactored so that not everything is a Node - that was a rather useless abstraction. Now, only things which can have a GIName are Node. E.g. Type and Field are no longer Node. More things were merged from glibast.py into ast.py, since it isn't a very useful split. transformer.py gains more intelligence and will e.g. turn GLib.List into a List() object earlier. The namespace processing is a lot cleaner now; since we parse the included .girs, we know the C prefix for each namespace, and have functions to parse both C type names (GtkFooBar) and symbols gtk_foo_bar into their symbols cleanly. Type resolution is much, much saner because we know Type(target_giname=Gtk.Foo) maps to the namespace Gtk. glibtransformer.py now just handles the XML processing from the dump, and a few miscellaneous things. The major heavy lifting now lives in primarytransformer.py, which is a combination of most of annotationparser.py and half of glibtransformer.py. annotationparser.py now literally just parses annotations; it's no longer in the business of e.g. guessing transfer too. finaltransformer.py is a new file which does post-analysis for "introspectability" mainly. girparser.c is fixed for some introspectable=0 processing.
* [giscanner] Catch CalledProcessError and OSErrorJohan Dahlin2010-02-171-1/+1
| | | | | Instead of catching all errors, including AttributeError, TypeError and NameError.
* [scanner] Catch OSError too when checking for libtoolColin Walters2010-02-171-1/+1
| | | | | | If we don't have permission to execute the libtool binary, we'd just throw here which is wrong. Fix this by catching all exceptions.
* Bug 592055 - Build/test fixesColin Walters2009-08-171-1/+2
| | | | The last few commits regressed 'check'; fix those up.
* Support passing --library=lib<foo>.laOwen W. Taylor2009-08-171-5/+27
| | | | | | | | | | | | | | | | In addition to the current --library=<foo>, support --library=lib<foo>.la. This makes it unambiguous that we are referencing an uninstalled library and allows accurate extraction of the shared library name for the uninstalled library. * tests/scanner/Makefile.am tests/offsets/Makefile.am: Use the new form of --library=. Also some LD_LIBRARY_PATH frobbing as needed. *-expected.gir *-expected.tgir: We now pick out the shared library accurately, so fix shared-library="" in our reference girs. (The comparison may need some pre-sanitization now to work on non-ELF) http://bugzilla.gnome.org/show_bug.cgi?id=591669
* Resolve library names to shared libraries ourselvesOwen W. Taylor2009-08-171-0/+22
| | | | | | | | | | | | | | | | | | | | | Using ctypes.util.find_library() to resolve library names to sonames causes problems with dealing with uninstalled libtool operation properly. We're unlikely to find any way of combining the two that will be robust against future changes in both facilities. Switch to a different approach - run 'ldd' on the compiled introspection binary and extract sonames from there This is less portable but should be quite robust where it works. utils.py dumper.py: Move libtool-command-line finding into utils.py girwriter.py: Remove library name resolution from here, expect libraries to be passed in preresolved. shlibs.py scannermain.py: New file including resolve_shlibs() to resolve library names using the introspection binary. tests/scanner/Makefile.am: Add .libs to LD_LIBRARY_PATH http://bugzilla.gnome.org/show_bug.cgi?id=591669
* Bug 575613 - Enum stripping with common prefix, also use "_" consistentlyColin Walters2009-03-171-11/+0
| | | | | | | | | | | | | Some enums have members which have a common prefix which doesn't match that of the enum name, but it also longer than the global namespace prefix. Instead, try stripping the common prefix first, and only if that fails fall back to the global strip. Also, for glib-registered enums we were using the nick, which typically has "-" as a separator. Replace that with "_" for consistency between unregistered enums and registered. utils.py:strip_common_prefix is now unused, delete.
* Relicense the giscanner library under LGPLv2+. This has been approved byJohan Dahlin2008-11-041-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2008-11-04 Johan Dahlin <jdahlin@async.com.br> * giscanner/__init__.py: * giscanner/ast.py: * giscanner/cachestore.py: * giscanner/cgobject.py: * giscanner/girparser.py: * giscanner/girwriter.py: * giscanner/giscannermodule.c: * giscanner/glibast.py: * giscanner/glibtransformer.py: * giscanner/libtoolimporter.py: * giscanner/minixpath.py: * giscanner/odict.py: * giscanner/sourcescanner.c: * giscanner/sourcescanner.h: * giscanner/sourcescanner.py: * giscanner/transformer.py: * giscanner/utils.py: * giscanner/xmlwriter.py: * COPYING: Relicense the giscanner library under LGPLv2+. This has been approved by all contributors. svn path=/trunk/; revision=862
* Bug 556358 - don't use libtool internalsJohan Dahlin2008-10-211-0/+4
| | | | | | | | | | | | | | | 2008-10-21 Johan Dahlin <johan@gnome.org> Bug 556358 - don't use libtool internals * giscanner/Makefile.am: * giscanner/libtoolimporter.py: * giscanner/sourcescanner.py: * giscanner/utils.py: Add a python meta importer and remove a libtool symlink hack. svn path=/trunk/; revision=767
* Bug 552376: scanner generates wrong names for enum members when there's noLucas Rocha2008-10-111-1/+4
| | | | | | | | | | | | | | | | 2008-10-11 Lucas Rocha <lucasr@gnome.org> Bug 552376: scanner generates wrong names for enum members when there's no defined gtype. * giscanner/utils.py (strip_common_prefix): Always strip common prefix exactly up to the last "_", and not beyond. * tests/scanner/foo.h (FooEnumNoType): add FOO_ENUM_NEUF. The point here is that the first character after the last '_' should should be the same as the character in the same position on the type name. * tests/scanner/foo-expected.gir: test that svn path=/trunk/; revision=664
* Bug 554521: scanner generates wrong names for enum members withDan Winship2008-10-021-2/+2
| | | | | | | | | | | | | full type name prefix * giscanner/utils.py (strip_common_prefix): Fix this to strip the right amount when the entire "first" string is a prefix of "second" * tests/scanner/foo.h (FooEnumFullname): * tests/scanner/foo-expected.gir: test that svn path=/trunk/; revision=640
* Bug 552390: Handle capitialization like "DBus" more robustlyColin Walters2008-09-201-0/+7
| | | | | | | | The to_underscores function was designed for use against prefixed names; we need a separate function which will convert names like DBusFoo into dbus_foo, not d_bus_foo. svn path=/trunk/; revision=621
* Fix up strip logic to not regressJohan Dahlin2008-08-311-1/+1
| | | | svn path=/trunk/; revision=555
* Clean up a huge if. Do not add methods or constructors to enums/flags.Johan Dahlin2008-08-311-1/+1
| | | | | | | | | | | | | 2008-08-31 Johan Dahlin <johan@gnome.org> * giscanner/glibtransformer.py: Clean up a huge if. Do not add methods or constructors to enums/flags. * giscanner/utils.py: second might be longer than first, check that. svn path=/trunk/; revision=550
* Much simpler approach of mapping uscored names to classes. RemoveColin Walters2008-08-211-17/+0
| | | | | | | | | | 2008-08-21 Colin Walters <walters@verbum.org> * giscanner/glibtransformer.py: Much simpler approach of mapping uscored names to classes. * giscanner/utils.py: Remove unnecessary function. svn path=/trunk/; revision=443
* Look up all permutations of class names when scanning methods/ctors basedColin Walters2008-08-211-0/+18
| | | | | | | | | | | 2008-08-21 Colin Walters <walters@verbum.org> * giscanner/glibtransformer.py: Look up all permutations of class names when scanning methods/ctors based on the prefix instead of using the return value. This associates gtk_window_new with the right class. svn path=/trunk/; revision=442
* Set ctype of enums Improve enum parsing for enums without a GType. MakeJohan Dahlin2008-08-181-2/+2
| | | | | | | | | | | | | | | | | | | | | 2008-08-18 Johan Dahlin <johan@gnome.org> * gir/Makefile.am: * giscanner/girparser.py: Set ctype of enums * giscanner/transformer.py: Improve enum parsing for enums without a GType. Make flags/enum references to other girs work * giscanner/utils.py: Simplify this a bit * tests/scanner/Makefile.am: * tests/scanner/foo-object.h: * tests/scanner/utility-expected.gir: * tests/scanner/utility.h: Add a new test for external enum references svn path=/trunk/; revision=397