Python: FootprintEnumerate can't deal with unicode paths

Bug #1740881 reported by kaspar
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Unknown

Bug Description

import pcbnew
src_plugin = pcbnew.IO_MGR.PluginFind(1)
src_plugin.FootprintEnumerate('你好.pretty')

results in

/usr/lib/python2.7/dist-packages/pcbnew.py in footprintPyEnumerate(self, aLibraryPath, aExitOnError)
   5641 def footprintPyEnumerate(self, aLibraryPath, aExitOnError):
   5642 """footprintPyEnumerate(PLUGIN self, wxString aLibraryPath, bool aExitOnError) -> wxArrayString"""
-> 5643 return _pcbnew.PLUGIN_footprintPyEnumerate(self, aLibraryPath, aExitOnError)
   5644
   5645

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

---

If there is unicode in any .kicad_mod filenames those files are simply ignored by FootprintEnumerate.

---

Application: kicad
Version: no-vcs-found-7d6230a~61~ubuntu16.04.1, release build
Libraries:
    wxWidgets 3.0.2
    libcurl/7.47.0 OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
Platform: Linux 4.4.0-104-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.58.0
    Curl: 7.47.0
    Compiler: GCC 5.4.0 with C++ ABI 1009

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_SPICE=ON

Tags: python
kaspar (kaspar-emanuel)
description: updated
tags: added: python
kaspar (kaspar-emanuel)
description: updated
description: updated
Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

I thought python unicode strings had to be prepended with a u''. At least that is what the documentation https://docs.python.org/2/howto/unicode.html would suggest. As long as wxWidgets was built with unicode support, it should accept unicode strings directly. If a wrapper has to written to support this, it could be a while before it's fix as we really do not have a python scripting developer.

Revision history for this message
kaspar (kaspar-emanuel) wrote :

Oh, indeed. Since I am not writing my paths manually, I can't prepend a u'' so my actual issue is with `os.walk` which seems return undecodable bytes.

>On Python 2, use Unicode strings for filenames on Windows (Unicode API), OS X (utf-8 is enforced) and use bytestrings on Linux and other systems.

https://stackoverflow.com/questions/21772271/unicodedecodeerror-when-performing-os-walk

Anyway, I believe you can close this bug as invalid.

Changed in kicad:
status: New → Invalid
Revision history for this message
kaspar (kaspar-emanuel) wrote :

On second thought:

>If there is unicode in any .kicad_mod filenames those files are simply ignored by FootprintEnumerate.

Is still a bug actually and I've just confirmed this behaviour. Should I open another issue?

$ tree footprints/
footprints/
└── a.pretty
    └── 和平.kicad_mod

import pcbnew
src_plugin = pcbnew.IO_MGR.PluginFind(1)
src_plugin.FootprintEnumerate('foots/a.pretty') == []

Revision history for this message
kaspar (kaspar-emanuel) wrote :

Last line should be:

src_plugin.FootprintEnumerate('footprints/a.pretty') == []

Revision history for this message
kaspar (kaspar-emanuel) wrote :

Or maybe clearer:

$ tree footprints/
footprints/
└── a.pretty
    ├── b.kicad_mod
    └── 和平.kicad_mod

1 directory, 2 files

import pcbnew
src_plugin = pcbnew.IO_MGR.PluginFind(1)
print src_plugin.FootprintEnumerate('footprints/a.pretty')

# prints "['b']" although both kicad_mod files have the same content

Revision history for this message
Nick Østergaard (nickoe) wrote :

I guess this could be an issue with the swig interface files for this function. I guess we can not reject it entirely.

Changed in kicad:
status: Invalid → New
Revision history for this message
kaspar (kaspar-emanuel) wrote :

Thanks for re-opening. It also crashes on otherwise valid foorprint libraries if there is unicode in the path:

$ tree footprints/
footprints/
└── 和.pretty
    ├── b.kicad_mod
    └── 和平.kicad_mod

1 directory, 2 files

---

# -*- coding: utf-8 -*-
import pcbnew
src_plugin = pcbnew.IO_MGR.PluginFind(1)
print src_plugin.FootprintEnumerate(u'footprints/和.pretty')

---

terminate called after throwing an instance of 'IO_ERROR'
Aborted (core dumped)

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@kasper, this issue must be due to the conversion from a python string to a wxString because I can load your footprint with the kicad footprint viewer (see attached image). Anyone else have any ideas why the python unicode string is not being properly converted to a wxString?

Revision history for this message
kaspar (kaspar-emanuel) wrote : Re: [Bug 1740881] Re: Python: FootprintEnumerate can't deal with unicode paths

Yeah, it seems like the problem is restricted to the Python bindings

Revision history for this message
KiCad Janitor (kicad-janitor) wrote :

KiCad bug tracker has moved to Gitlab. This report is now available here: https://gitlab.com/kicad/code/kicad/-/issues/2543

Changed in kicad:
status: New → Expired
Changed in kicad:
importance: Undecided → Unknown
status: Expired → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.