mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
edenscm: move sys.path handling to top-level edenscm
Summary: Make `import edenscm` take care of `sys.path` so as long as `import edenscm` works, 3rd party pure Python dependencies and edenscmnative should be importable. This reduces adhoc sys.path handling in testutil.dott, and fixes an issue where testing on Windows where `testuitl.dott` fails to run hg commands due to missing 3rd party dependencies (because `edenscm.mercurial.entrypoint.run` is not called, and edenscmdeps.zip is not in sys.path). Reviewed By: sfilipco Differential Revision: D16499458 fbshipit-source-id: 17e6e5754614dfcf352127d471c649ded4189e1a
This commit is contained in:
parent
d2b564dcac
commit
eaabc7f3c6
@ -2,3 +2,42 @@
|
||||
#
|
||||
# This software may be used and distributed according to the terms of the
|
||||
# GNU General Public License version 2 or any later version.
|
||||
|
||||
|
||||
def _fixsyspath():
|
||||
"""Fix sys.path so core edenscm modules (edenscmnative, and 3rd party
|
||||
libraries) are in sys.path
|
||||
"""
|
||||
# Do not expose those modules to edenscm.__dict__
|
||||
import sys
|
||||
import os
|
||||
|
||||
dirname = os.path.dirname
|
||||
|
||||
# __file__ is "hg/edenscm/__init__.py"
|
||||
# libdir is "hg/"
|
||||
# Do not follow symlinks (ex. do not use "realpath"). It breaks buck build.
|
||||
libdir = dirname(dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Make "edenscmdeps.zip" available in sys.path. It includes 3rd party
|
||||
# pure-Python libraries like IPython, thrift runtime, etc.
|
||||
#
|
||||
# Note: On Windows, the released version of hg uses python27.zip for all
|
||||
# pure Python modules including edenscm and everything in edenscmdeps.zip,
|
||||
# so not being able to locate edenscmdeps.zip is not fatal.
|
||||
for candidate in [libdir, os.path.join(libdir, "build")]:
|
||||
depspath = os.path.join(candidate, "edenscmdeps.zip")
|
||||
if os.path.exists(depspath) and depspath not in sys.path:
|
||||
sys.path.insert(0, depspath)
|
||||
|
||||
# Make sure "edenscmnative" can be imported. Error early.
|
||||
import edenscmnative
|
||||
|
||||
edenscmnative.__name__
|
||||
|
||||
|
||||
_fixsyspath()
|
||||
|
||||
|
||||
# Keep the module clean
|
||||
del globals()["_fixsyspath"]
|
||||
|
@ -13,10 +13,6 @@ import sys
|
||||
|
||||
|
||||
def run():
|
||||
# Do not follow symlinks (ex. do not use "realpath"). It breaks buck build.
|
||||
filedir = os.path.dirname(os.path.abspath(__file__))
|
||||
libdir = os.path.dirname(os.path.dirname(filedir))
|
||||
|
||||
from edenscm import hgdemandimport
|
||||
from edenscm.mercurial import encoding
|
||||
|
||||
@ -27,21 +23,6 @@ def run():
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
# Make available various deps that are either not new enough on the system
|
||||
# or not provided by the system. These include a newer version of IPython
|
||||
# for `hg dbsh` and the thrift runtime for the eden extension
|
||||
import edenscm
|
||||
|
||||
depspath = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(edenscm.__file__))),
|
||||
"edenscmdeps.zip",
|
||||
)
|
||||
if not os.path.exists(depspath):
|
||||
# we keep the edenscmdeps.zip in different location in case of dev builds
|
||||
depspath = os.path.join(libdir, "build", "edenscmdeps.zip")
|
||||
if depspath not in sys.path and os.path.exists(depspath):
|
||||
sys.path.insert(0, depspath)
|
||||
|
||||
if (
|
||||
sys.argv[1:5] == ["serve", "--cmdserver", "chgunix2", "--address"]
|
||||
and sys.argv[6:8] == ["--daemon-postexec", "chdir:/"]
|
||||
|
@ -31,11 +31,7 @@ def editsyspath(modname, relpaths):
|
||||
path = os.path.abspath(path)
|
||||
for relpath in relpaths:
|
||||
candidate = os.path.realpath(os.path.join(path, relpath))
|
||||
if (
|
||||
candidate.endswith("zip")
|
||||
and os.path.exists(candidate)
|
||||
or os.path.exists(os.path.join(candidate, modname, "__init__.py"))
|
||||
):
|
||||
if os.path.exists(os.path.join(candidate, modname, "__init__.py")):
|
||||
if candidate not in sys.path:
|
||||
sys.path.insert(0, candidate)
|
||||
return
|
||||
@ -48,11 +44,9 @@ def editsyspath(modname, relpaths):
|
||||
# - sys.path includes "$TESTDIR" (because run-tests.py path is in $TESTDIR)
|
||||
# - "$TESTDIR/.." has the desired modules (in-place local build)
|
||||
#
|
||||
# "../../.." and "../python27.zip" works when:
|
||||
# "../../.." works when:
|
||||
# - `fb/packaging/build_nupkg.py --test` copies `tests/` to `build/embedded`
|
||||
# - `build/embedded/python27.zip` includes `edenscm` packages.
|
||||
editsyspath("edenscmnative", ["..", "../../.."])
|
||||
editsyspath("edenscm", ["..", "../python27.zip"])
|
||||
editsyspath("edenscm", ["..", "../../.."])
|
||||
|
||||
|
||||
for candidate in sys.path:
|
||||
|
Loading…
Reference in New Issue
Block a user