Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating wrappers with python 3.7 #259

Closed
ppxasjsm opened this issue Mar 14, 2019 · 20 comments
Closed

creating wrappers with python 3.7 #259

ppxasjsm opened this issue Mar 14, 2019 · 20 comments
Assignees
Milestone

Comments

@ppxasjsm
Copy link
Collaborator

@SofiaBariami and I had a go at creating wrappers and came across this error:

~/sire_cRules.app/bin/python ../AutoGenerate/create_wrappers.py
/home/sofia/sire_cRules.app/lib/python3.7/site-packages/fuzzywuzzy/fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
 warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')
Traceback (most recent call last):
 File "../AutoGenerate/create_wrappers.py", line 22, in <module>
   from pyplusplus.module_builder import module_builder_t
 File "/home/sofia/sire_cRules.app/lib/python3.7/site-packages/pyplusplus/__init__.py", line 23, in <module>
   from . import code_creators
 File "/home/sofia/sire_cRules.app/lib/python3.7/site-packages/pyplusplus/code_creators/__init__.py", line 18, in <module>
   from .code_creator import code_creator_t
 File "/home/sofia/sire_cRules.app/lib/python3.7/site-packages/pyplusplus/code_creators/code_creator.py", line 8, in <module>
   from pyplusplus import decl_wrappers
 File "/home/sofia/sire_cRules.app/lib/python3.7/site-packages/pyplusplus/decl_wrappers/__init__.py", line 13, in <module>
   from . import algorithm
 File "/home/sofia/sire_cRules.app/lib/python3.7/site-packages/pyplusplus/decl_wrappers/algorithm.py", line 51, in <module>
   __RE_VALID_IDENTIFIER = re.compile( r"[_a-z]\w*", re.I | re.L | re.U )
 File "/home/sofia/sire_cRules.app/lib/python3.7/re.py", line 234, in compile
   return _compile(pattern, flags)
 File "/home/sofia/sire_cRules.app/lib/python3.7/re.py", line 286, in _compile
   p = sre_compile.compile(pattern, flags)
 File "/home/sofia/sire_cRules.app/lib/python3.7/sre_compile.py", line 764, in compile
   p = sre_parse.parse(p, flags)
 File "/home/sofia/sire_cRules.app/lib/python3.7/sre_parse.py", line 940, in parse
   p.pattern.flags = fix_flags(str, p.pattern.flags)
 File "/home/sofia/sire_cRules.app/lib/python3.7/sre_parse.py", line 907, in fix_flags
   raise ValueError("cannot use LOCALE flag with a str pattern")
ValueError: cannot use LOCALE flag with a str pattern

After some minimal googling I would assume that there is an issue with the regular expression matching from pyplusplus that does not work with python 3.7 (or 3.6). Not 100% sure though and would love some other input.

My idea to test this was trying to use python 3.5 and see if the wrappers could be created, but a simple downgrade of python with conda wasn't possible and I didn't want to then dive down too many rabbit holes.

@jmichel80
Copy link
Contributor

I can reproduce this error on my setup. It seems it is no longer possible to compile wrappers with recent python versions using a legacy pyplusplus 1.8.5.
I also note that gccxml is deprecated.

This probably means a long term solution is needed. In the short term can you think of a quick fix @chryswoods or @lohedges ? Compile wrappers on an old OS, and commit changes ?

@lohedges
Copy link
Member

I also have the same issue with Python 3.7 on Linux. Just trying to see if I can get things working.

@lohedges
Copy link
Member

I hadn't noticed before since I hadn't needed to regenerate the any wrappers since the latest miniconda update (which took us to Python 3.7).

@lohedges
Copy link
Member

On Linux I just reinstalled pyplusplus, removing the restriction to lock it to version 1.8.5. The wrappers seem to compile just fine and I can import the resulting Python modules. Bizarrely I end up with version 1.8.1 of pyplusplus being installed:

$HOME/sire.app/bin/pip install pyplusplus --no-cache-dir 

Collecting pyplusplus
  Downloading https://files.pythonhosted.org/packages/e3/d6/6394a732d364d726fc4dfc9fa1832913f07aa2873f32c65298032e92bdb0/pyplusplus-1.8.1.tar.gz (164kB)
    100% |████████████████████████████████| 174kB 4.6MB/s
Requirement already satisfied: pygccxml in /home/lester/sire.app/lib/python3.7/site-packages (from pyplusplus) (1.8.5)
Installing collected packages: pyplusplus
  Running setup.py install for pyplusplus ... done
Successfully installed pyplusplus-1.8.1

@lohedges
Copy link
Member

Actually, version 1.8.1 is the latest version on pip.

@jmichel80
Copy link
Contributor

When I do that I now get a gccxml error. Did you also reinstall this software or change settings?
I had to compile gccxml since it is no longer available as a package on Ubuntu 18.04

julien@ubuntu:~/software/devel/Sire/wrapper/Move$ $HOME/sire.app/bin/pip install pyplusplus --no-cache-dir 
Collecting pyplusplus
  Downloading https://files.pythonhosted.org/packages/e3/d6/6394a732d364d726fc4dfc9fa1832913f07aa2873f32c65298032e92bdb0/pyplusplus-1.8.1.tar.gz (164kB)
    100% |████████████████████████████████| 174kB 7.8MB/s 
Requirement already satisfied: pygccxml in /home/julien/sire.app/lib/python3.7/site-packages (from pyplusplus) (1.8.5)
Installing collected packages: pyplusplus
  Running setup.py install for pyplusplus ... done
Successfully installed pyplusplus-1.8.1
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ $HOME/sire.app/bin/python ../AutoGenerate/create_wrappers.py
/home/julien/sire.app/lib/python3.7/site-packages/fuzzywuzzy/fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
  warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')
Using gccxml from /usr/local/bin/gccxml
Generating wrappers including OpenMM from /home/julien/sire.app/bin/../include
/home/julien/sire.app/lib/python3.7/site-packages/pyplusplus/module_builder/boost_python_builder.py:146: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
  start_time = time.clock()
INFO Parsing source file "active_headers.h" ... 
Could not determine GCCXML_EXECUTABLE setting.
Traceback (most recent call last):
  File "../AutoGenerate/create_wrappers.py", line 664, in <module>
    gccxml_config=xml_generator_config )
  File "/home/julien/sire.app/lib/python3.7/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 106, in __init__
    , indexing_suite_version)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 149, in __parse_declarations
    decls = reader.read_files( files, compilation_mode )
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/project_reader.py", line 249, in read_files
    return self.__parse_file_by_file(files)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/project_reader.py", line 278, in __parse_file_by_file
    decls = reader.read_file(header)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 380, in read_file
    return self.read_cpp_source_file(source_file)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 399, in read_cpp_source_file
    xml_file = self.create_xml_file(ffname)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 348, in create_xml_file
    ": %s status:%s" % (gccxml_msg, exit_status))
RuntimeError: Error occurred while running GCCXML:  status:1
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ gccxml 
GCC-XML version 0.9.0
No arguments given for GCC C++ parser.  Not running it.
Usage:

gccxml [options] <input-file> -fxml=<output-file>

The following options are available for running GCC-XML:
  --copyright              = Print the GCC-XML copyright and exit.
  --debug                  = Print extra debugging information.
  -fxml=<output-file>      = Specify the XML output file.
  -fxml-start=<xxx>[,...]  = Specify a list of starting declarations.
  --gccxml-compiler <xxx>  = Set GCCXML_COMPILER to "xxx".
  --gccxml-cxxflags <xxx>  = Set GCCXML_CXXFLAGS to "xxx".
  --gccxml-executable <xxx>= Set GCCXML_EXECUTABLE to "xxx".
  --gccxml-cpp <xxx>       = Set GCCXML_CPP to "xxx".
  --gccxml-config <xxx>    = Set GCCXML_CONFIG to "xxx".
  --gccxml-root <xxx>      = Set GCCXML_ROOT to "xxx".
  --gccxml-gcc-options <xxx>= Read GCC options from file "xxx".
  --help                   = Print full help and exit.
  --help-html              = Print full help in HTML format.
  --man                    = Print a UNIX man page and exit.
  --print                  = Print configuration settings and exit.
  --preprocess             = Preprocess the input and exit.
  -E                       = Alias for --preprocess.
  --version                = Show program name/version banner and exit.

Other flags, such as -I and -D, are passed on to the patched GCC C++
parser executable.
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ 

@lohedges
Copy link
Member

Is it possible to try using CastXML rather than GCC-XML. This has succeeded GCC-XML. I have both installed on my Linux machine but it looks like CastXML takes precedence.

@jmichel80
Copy link
Contributor

jmichel80 commented Mar 19, 2019

Unfortunately this triggers another error on my setup

julien@ubuntu:~/software/devel/Sire/wrapper/Move$ sudo apt-get install castxml
[sudo] password for julien: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed
  castxml
0 to upgrade, 1 to newly install, 0 to remove and 424 not to upgrade.
Need to get 14.6 MB of archives.
After this operation, 62.1 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 castxml amd64 0.1+git20170823-1 [14.6 MB]
Fetched 14.6 MB in 2s (6,887 kB/s)  
Selecting previously unselected package castxml.
(Reading database ... 272316 files and directories currently installed.)
Preparing to unpack .../castxml_0.1+git20170823-1_amd64.deb ...
Unpacking castxml (0.1+git20170823-1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up castxml (0.1+git20170823-1) ...
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ castxml 
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ castxml --version
castxml version 0.1-g927c739

CastXML project maintained and supported by Kitware (kitware.com).

clang version 4.0.1-1build1 (tags/RELEASE_401/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: 
julien@ubuntu:~/software/devel/Sire/wrapper/Move$ $HOME/sire.app/bin/python ../AutoGenerate/create_wrappers.py
(....)
<built-in>:170:9: note: previous definition is here
#define __PIE__ 2
        ^
In file included from active_headers.h:6:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireMove/dlmrigidbody.h:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireMove/integrator.h:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireBase/property.h:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireBase/sharedpolypointer.hpp:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireStream/datastream.h:38:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireStream/version_error.h:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireError/version_error.h:32:
In file included from /home/julien/software/devel/Sire/corelib/src/libs/SireError/exception.h:34:
In file included from /home/julien/sire.app/bin/../include/qt/QtCore/QString:1:
In file included from /home/julien/sire.app/bin/../include/qt/QtCore/qstring.h:48:
In file included from /home/julien/sire.app/bin/../include/qt/QtCore/qchar.h:43:
/home/julien/sire.app/bin/../include/qt/QtCore/qglobal.h:1135:4: error: "You must build your code with position independent code if Qt was built
      with -reduce-relocations. "         "Compile your code with -fPIC (-fPIE is not enough)."
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
   ^
(...)

There are also a bunch of warnings that may or may not be problematic

/home/julien/sire.app/bin/../include/qt/QtCore/qiodevice.h:68:5: warning: unknown warning group '-Wsuggest-override', ignored [-Wunknown-pragmas]
    Q_OBJECT
    ^
/home/julien/sire.app/bin/../include/qt/QtCore/qobjectdefs.h:178:5: note: expanded from macro 'Q_OBJECT'
    Q_OBJECT_NO_OVERRIDE_WARNING \
    ^
/home/julien/sire.app/bin/../include/qt/QtCore/qobjectdefs.h:163:45: note: expanded from macro 'Q_OBJECT_NO_OVERRIDE_WARNING'
#  define Q_OBJECT_NO_OVERRIDE_WARNING      QT_WARNING_DISABLE_GCC("-Wsuggest-override")
                                            ^
/home/julien/sire.app/bin/../include/qt/QtCore/qcompilerdetection.h:1305:49: note: expanded from macro 'QT_WARNING_DISABLE_GCC'
#  define QT_WARNING_DISABLE_GCC(text)          QT_DO_PRAGMA(GCC diagnostic ignored text)
                                                ^
/home/julien/sire.app/bin/../include/qt/QtCore/qcompilerdetection.h:1265:49: note: expanded from macro 'QT_DO_PRAGMA'
#define QT_DO_PRAGMA(text)                      _Pragma(#text)
                                                ^

Note that castxml did take precedence automatically as in your setup

(...)
15 warnings and 1 error generated.
Traceback (most recent call last):
  File "../AutoGenerate/create_wrappers.py", line 664, in <module>
    gccxml_config=xml_generator_config )
  File "/home/julien/sire.app/lib/python3.7/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 106, in __init__
    , indexing_suite_version)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 149, in __parse_declarations
    decls = reader.read_files( files, compilation_mode )
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/project_reader.py", line 249, in read_files
    return self.__parse_file_by_file(files)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/project_reader.py", line 278, in __parse_file_by_file
    decls = reader.read_file(header)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 380, in read_file
    return self.read_cpp_source_file(source_file)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 399, in read_cpp_source_file
    xml_file = self.create_xml_file(ffname)
  File "/home/julien/sire.app/lib/python3.7/site-packages/pygccxml/parser/source_reader.py", line 348, in create_xml_file
    ": %s status:%s" % (gccxml_msg, exit_status))
RuntimeError: Error occurred while running CASTXML:  status:1

@lohedges
Copy link
Member

lohedges commented Mar 19, 2019

That's strange. If you look at the create_wrappers.py script you'll see that the fPIC is already flag is already passed to CastXML. Looking at the output of CastXML it looks like I have a more recent clang version. Not sure if this makes any difference.

castxml --version
castxml version 0.1-gae93121-dirty

CastXML project maintained and supported by Kitware (kitware.com).

clang version 7.0.1 (tags/RELEASE_701/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir:

@jmichel80
Copy link
Contributor

Bit frustrating ! It sounds like we need to revisit how to support wrappers compilation

In the meantime could you please commit the recompiled wrappers to devel if they work correctly? I will merge the changes in @SofiaBariami 's branches so she can keep progressing with her project.

@lohedges
Copy link
Member

Agreed, it's rather frustrating. One suggestion from @chryswoods is to create a docker environment in which to build the wrappers. I'll look into this.

I'm a bit confused by you question regarding the wrappers on devel. Do you mean to compile the wrappers on @SofiaBariami's feature branch where the API has changed? (Basically recompile the Sire.Move wrappers there and upload the modified files.) The wrappers on devel work fine for me without needing any recompilation. Is this not the case for you?

@jmichel80
Copy link
Contributor

jmichel80 commented Mar 19, 2019 via email

@lohedges
Copy link
Member

Okay, the updated wrapper files have been pushed to the qube-combiningRules branch. Let me know if this works.

@lohedges lohedges added this to the 2019.2.0 milestone May 3, 2019
@lohedges lohedges self-assigned this May 3, 2019
@lohedges
Copy link
Member

lohedges commented Jul 30, 2019

I'm close to having a working Docker container for building wrappers. In building it I've come across the same error that @jmichel80 saw above, i.e.

/home/julien/sire.app/bin/../include/qt/QtCore/qglobal.h:1135:4: error: "You must build your code with position independent code if Qt was built
      with -reduce-relocations. "         "Compile your code with -fPIC (-fPIE is not enough)."
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
   ^
(...)

As mentioned previously, -fPIC is passed as a CFLAG in create_wrappers.py. However, __PIE__ is also set as a define symbol. Changing this to __PIC__ allows the wrappers to built without error. (The define seems to take precedence over the cflag.)

I've compiled the updated wrappers and they appear to work as before. If @chryswoods could confirm that this is a valid solution, then I'll update create_wrappers.py and push the Docker container. (You should also be able to build them locally too using CastXML.)

@chryswoods
Copy link
Member

Yes, this is a good solution. Thanks for getting this working in docker :-)

@lohedges
Copy link
Member

Okay, I updated the code, which didn't change a single wrapper file and now the Azure build fails with an error in SireMove::OpenMMFrEnergyST. What the heck!

@lohedges
Copy link
Member

And of course, it builds completely fine locally in a clean Sire Miniconda. Seriously, how is one meant to debug stuff like this!

@lohedges
Copy link
Member

Even more ridiculous: I've run the sire-devel-latest Dockerfile locally and it builds fine! How is this even possible? Unless some of the Conda build dependencies have updated in the last hour (which they haven't) I really can't see how this could happen. So much for reproducible builds.

I guess I'll have to push a new commit to Sire devel to see what happens. (Triggering a rebuild of the same commit failed.)

@lohedges
Copy link
Member

So, pushing a completely unrelated change to a README file appears to have fixed things. I reiterate that none of the wrappers have changed in any of the commits, nor the source code. If anyone has any explanation for why this occurred then I'm all ears.

Note that it wasn't a random failure, since both the Linux and macOS builds failed, and they failed consistently when a re-build was triggered. The only thing that I can think of is that, since the order in which the wrappers is built is variable, I hit some random situation where the wrappers were built out of order. (Perhaps due to the parallel nature of of the build with CMake.)

So far this week I've had a Dockerfile not generating a consistent image on two machines and two Conda versions (one version apart) generating completely different package plans for the same install. (One of which was broken.) Basically, the concept of reproducible builds and reproducible environments is dead. Perhaps we should just go back to shipping binaries. At least we can test those ourselves and it's our fault when they're broken!

@lohedges
Copy link
Member

I now have a working Docker container, based on sire-mol/sire-devel-latest so that we match the build environment. I can't push the image from home because of this wonderful Docker issue. Will do so when I'm next in the office on Friday, then update the wrapper documentation accordingly. You should then be able to do something like:

docker run -it siremol/sire-wrap-devel

This will place you inside Sire/wrapper, then you can run:

git fetch
git checkout my-feature

to fetch the latest updates and switch to your feature branch. Then you can build wrappers as follows:

python AutoGenerate/scan_headers.py $HOME/Sire/corelib/src/libs .
cd Move
python ../AutoGenerate/create_wrappers.py

You can then commit your changes and push the updates. (I'll think of a way of easily setting GitHub user account credentials within the container.) Alternatively, you could copy the updated files out of the Docker container and commit them in your local repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants