xolstice / protobuf-maven-plugin

Maven Plugin that executes the Protocol Buffers (protoc) compiler
https://www.xolstice.org/protobuf-maven-plugin/
Other
232 stars 76 forks source link

Protobuf compiler removes __init__.py when compiling python #9

Closed dtracers closed 8 years ago

dtracers commented 8 years ago

I am compiling the protobuf code to a source directory but it removes the init.py every single time.

It would be awesome if there was a parameter to have it not delete init.py for python.

sergei-ivanov commented 8 years ago

I would generally advise against compiling into source directory (and storing generated files under version control). But nevertheless, you may try setting clearOutputDirectory parameter to false in plugin configuration. It is true by default because of backward compatibility.

dtracers commented 8 years ago

That directory is ignored by version control.

My preference would be to compile to temp then copy to directory but maven has a really hard time copying reliably.

What would be best practice of where to compile the python but then being able to immediately import it from src tree? On Jul 4, 2016 9:39 AM, "Sergei Ivanov" notifications@github.com wrote:

I would generally advise against compiling into source directory (and storing generated files under version control). But nevertheless, you may try setting clearOutputDirectory https://www.xolstice.org/protobuf-maven-plugin/compile-python-mojo.html#clearOutputDirectory parameter to false in plugin configuration. It is true by default because of backward compatibility.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xolstice/protobuf-maven-plugin/issues/9#issuecomment-230316088, or mute the thread https://github.com/notifications/unsubscribe/AB2CDIptVQ04j173Oil0fyko7KSfuHvJks5qSSkjgaJpZM4JEdC1 .

sergei-ivanov commented 8 years ago

Obviously, Python is not a first class citizen in the Maven universe, and I don't know if there're any best practices with regard to generating and distributing Python sources from a Maven build.

Would you be able to share the set-up for your Maven project (feel free to remove/obfuscate any organisation-specific parts)? Maybe a gist with a stripped-down version to demonstrate the source tree layout and POM configuration.

dtracers commented 8 years ago

https://github.com/DonaldMcRonald/SketchRecognitionWithTensorFlow/blob/master/pom.xml

Here is the pom.

I get proto files from two places. Another library (that also uses the same protobuf plugin so I can't put the init.py form their) And the plugin itself.

Here is where the files are added https://github.com/DonaldMcRonald/SketchRecognitionWithTensorFlow/tree/master/src/main/python/generated_proto

notice that the init.py is in version control but non of the genereted files are. (I put it in vc so it is easier to add it back and notice when it is gone)

Here is the library that the first set of proto files are grabbed from. https://github.com/dtracers/SketchRecognitionFramework/blob/master/pom.xml

Its smaller and is much easier to read

sergei-ivanov commented 8 years ago

I think I've got an idea of what you are trying to achieve.

I suggest that you do the following:

  1. Add <clearOutputDirectory>false</clearOutputDirectory> configuration parameter to the compile-python execution. That will suppress automatic clearing out of the generated_proto directory by protobuf-maven-plugin.
  2. Add a separate execution of maven-clean-plugin, bound to the clean phase, which will clear out everything but __init__.py from the generated_proto directory when you run mvn clean goal. See here and here for inspiration.
  3. And it's probably a good time to ditch protoc-plugin-default and protoc-plugin-backup repository definitions from the POM: they are legacy.
sergei-ivanov commented 8 years ago

BTW, the above suggestion applies to both projects, only that maven-clean-plugin configuration for SketchRecognitionFramework will be simpler: it will simply blitz the entire generated_proto directory.

dtracers commented 8 years ago

Thank you that was exactly what I needed!