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

Modify setup.py to build protos on Windows #723

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

daiweili
Copy link
Contributor

@daiweili daiweili commented Feb 15, 2018

Also change yaml library to one that builds on Windows. I've test python setup.py install on Windows 10 and Linux. Let me know if there's anything else you'd like me to test. Thanks!


This change is Reviewable

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

setup.py Outdated
@@ -109,6 +114,9 @@ def run(self):
'"protobuf-compiler" and "libprotobuf-dev" packages.')
elif sys.platform == 'darwin':
print('On Mac, protobuf is often installed via homebrew.')
else:
print('On Windows, protoc should be installed and added '
'to the path.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could leave more of a bread crumb here for how the user should go about getting protoc for windows, even if it's just to point them at the protobuf website. The Linux and Mac strings at least mention which method is recommended to get protoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup.py Outdated
if not self.protoc:
self.protoc = find_executable('protoc')
pc_path = os.path.dirname(find_executable('protoc'))
self.protodir = os.path.abspath(os.path.dirname(pc_path) + '/../lib')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using os.path.join instead of hard-coding path separators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Also change yaml library to one that builds on Windows

Also add some setup instructions for Windows
@daiweili
Copy link
Contributor Author

PTAL at the latest change. Sorry, I force pushed and overwrote the first commit (haven't worked with pull requests before).

setup.py Outdated
if not self.protoc:
self.protoc = find_executable('protoc')
pc_path = os.path.dirname(find_executable('protoc'))
self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), '../lib'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'../' should probably be os.path.pardir instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@daiweili
Copy link
Contributor Author

PTAL

jettisonjoe
jettisonjoe previously approved these changes Apr 25, 2018
@jettisonjoe
Copy link
Contributor

Try re-running that unit test after rebasing on master. I made a change recently that should have fixed its flakiness.

self.protoc = 'protoc'

self.protodir = os.path.join(prefix, 'include')
if not self.protoc:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes, Mac and Linux will fallback to using the Windows logic if maybe_protoc is not found. This doesn't seem right. For example, the proto dir should remain as os.path.join(prefix, 'include') on Mac/Linux instead of using /usr/lib/.

It seems like the Mac/Linux logic should remain unchanged by this PR, so I suggest restructuring the flow control to something like:

if prefix:
  # Linux/Mac.
  maybe_protoc = os.path.join(prefix, 'bin', 'protoc')
  if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK):
    self.protoc = maybe_protoc
  else:
    print('Warning: protoc not found at %s' % maybe_protoc)
    print('setup will attempt to run protoc with no prefix.')
    self.protoc = 'protoc'
  self.protodir = os.path.join(prefix, 'include')
else:
  # Windows.
  ...

if not self.protoc:
self.protoc = find_executable('protoc')
pc_path = os.path.dirname(find_executable('protoc'))
self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), os.path.pardir, 'lib'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with protos on Windows, but this looks a bit suspicious, in that you're going up two directory levels and assuming that lib/ is there.

If you expect lib/ in a certain place on Windows, consider hardcoding that path. This is similar to what we do for Mac/Linux where we check /usr/local/include/ on Mac and /usr/include/ on Linux. If needed, you can get the drive path using os.path.splitdrive(self.protoc)[0].

If you actually want to go up two directories then this should be cleaned up as:

self.protoc = find_executable('protoc')
self.protodir = os.path.join(
    os.path.dirname(os.path.dirname(os.path.dirname(self.protoc))), 'lib')

@arsharma1 arsharma1 dismissed jettisonjoe’s stale review May 14, 2019 20:43

This review is a year old and hasn't been committed.

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

Successfully merging this pull request may close these issues.

4 participants