improve building and importing of the eden hg extension

Summary:
This updates how we build and package the eden hg extension, and how we find it
during integration tests.

- Update the extension to always look relative to its current location to find
  the other modules it depends on.  This ensures that the integration tests
  always find modules from the local repository, and do not use the modules
  installed on the system.

- Add a buck rule to unpack the python archive at build time.  This is needed
  for integration tests to use the local version of the module.

- Ensure that we install a correct `hgext3rd/__init__.py` module in the eden
  extension directory.  This is required to correctly set up `hgext3rd` as a
  namespace package.  This also unfortunately needs to be a `.py` file, and not
  just a .pyc file.  (The pkgutil.expand_path() code looks specifically for
  directories containing `__init__.py` files, and does not check for
  `__init__.pyc`.)

- Update the extension to only try importing the native thrift modules if we
  are running python 2.7.6 or greater.  Python 2.7.6 is the first that supports
  unicode arguments to `struct.pack()`, which thrift requires.  Python 2.7.5 can
  import the thrift modules, but throws errors when trying to run them.

Reviewed By: bolinfest

Differential Revision: D4935279

fbshipit-source-id: 9af81736124c55476a5eb5beba9474a4371a639b
This commit is contained in:
Adam Simpkins 2017-04-24 11:06:23 -07:00 committed by Facebook Github Bot
parent d792d1607c
commit 5da361f55b
3 changed files with 18 additions and 7 deletions

View File

@ -12,6 +12,7 @@ python_unittest(
srcs = glob(['*.py']),
env = artifacts['env'],
deps = artifacts['deps'] + [
'@/eden/hg/eden:eden',
'@/eden/integration/hg/lib:testutil',
],
)

View File

@ -25,12 +25,21 @@ def _find_post_clone():
def _eden_ext_dir():
hg_ext_dir = os.path.join(find_executables.REPO_ROOT, 'eden/hg/eden')
if not os.path.isdir(hg_ext_dir):
msg = ('unable to find Hg extension for integration testing: {!r}'
.format(hg_ext_dir))
raise Exception(msg)
return hg_ext_dir
check_locations = [
# In dev mode, the python_binary link-tree can be found here:
'buck-out/gen/eden/hg/eden/eden#link-tree',
# In other modes, we unpack the python archive here:
'buck-out/gen/eden/hg/eden/eden/output',
]
for location in check_locations:
hg_ext_dir = os.path.join(find_executables.REPO_ROOT, location,
'hgext3rd/eden')
if os.path.isdir(hg_ext_dir):
return hg_ext_dir
msg = ('unable to find Hg extension for integration testing: {!r}'
.format(hg_ext_dir))
raise Exception(msg)
POST_CLONE = _find_post_clone()

View File

@ -67,7 +67,8 @@ EDEN_CLI = _find_cli()
def _find_daemon():
edenfs = os.environ.get('EDENFS_SERVER_PATH')
if not edenfs:
edenfs = os.path.join(BUCK_OUT, 'gen/eden/fs/service/edenfs%s' % EDENFS_SUFFIX)
edenfs = os.path.join(BUCK_OUT,
'gen/eden/fs/service/edenfs%s' % EDENFS_SUFFIX)
if not os.access(edenfs, os.X_OK):
msg = 'unable to find eden daemon for integration testing: {!r}'.format(
edenfs)