##// END OF EJS Templates
mercurial: implement import hook for handling C/Python modules...
mercurial: implement import hook for handling C/Python modules There are a handful of modules that have both pure Python and C extension implementations. Currently, setup.py copies files from mercurial/pure/*.py to mercurial/ during the install process if C extensions are not available. This way, "import mercurial.X" will work whether C extensions are available or not. This approach has a few drawbacks. First, there aren't run-time checks verifying the C extensions are loaded when they should be. This could lead to accidental use of the slower pure Python modules. Second, the C extensions aren't compatible with PyPy and running Mercurial with PyPy requires installing Mercurial - you can't run ./hg from a source checkout. This makes developing while running PyPy somewhat difficult. This patch implements a PEP-302 import hook for finding and loading the modules with both C and Python implementations. When a module with dual implementations is requested for import, its import is handled by our import hook. The importer has a mechanism that controls what types of modules we allow to load. We call this loading behavior the "module load policy." There are 3 settings: * Only load C extensions * Only load pure Python * Try to load C and fall back to Python An environment variable allows overriding this policy at run time. This is mainly useful for developers and for performing actions against the source checkout (such as installing), which require overriding the default (strict) policy about requiring C extensions. The default mode for now is to allow both. This isn't proper and is technically backwards incompatible. However, it is necessary to implement a sane patch series that doesn't break the world during future bisections. The behavior will be corrected in future patch. We choose the main mercurial/__init__.py module for this code out of necessity: in a future world, if the custom module importer isn't registered, we'll fail to find/import certain modules when running from a pure installation. Without the magical import-time side-effects, *any* importer of mercurial.* modules would be required to call a function to register our importer. I'm not a fan of import time side effects and I initially attempted to do this. However, I was foiled by our own test harness, which has numerous `python` invoked scripts that "import mercurial" and fail because the importer isn't registered. Realizing this problem is probably present in random Python scripts that have been written over the years, I decided that sacrificing purity for backwards compatibility is necessary. Plus, if you are programming Python, "import" should probably "just work." It's worth noting that now that we have a custom module loader, it would be possible to hook up demand module proxies at this level instead of replacing __import__. We leave this work for another time, if it's even desired. This patch breaks importing in environments where Mercurial modules are loaded from a zip file (such as py2exe distributions). This will be addressed in a subsequent patch.

File last commit:

r26827:a9ed5a8f stable
r27220:4374d819 default
Show More
environment.txt
107 lines | 3.8 KiB | text/plain | TextLexer
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999 HG
Path to the 'hg' executable, automatically passed when running
hooks, extensions or external tools. If unset or empty, this is
the hg executable's name if it's frozen, or an executable named
'hg' (with %PATHEXT% [defaulting to COM/EXE/BAT/CMD] extensions on
Windows) is searched.
HGEDITOR
This is the name of the editor to run when committing. See EDITOR.
Brodie Rao
help: refer to user configuration file more consistently...
r12083 (deprecated, use configuration file)
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999
HGENCODING
This overrides the default locale setting detected by Mercurial.
This setting is used to convert data including usernames,
changeset descriptions, tag names, and branches. This setting can
be overridden with the --encoding command-line option.
HGENCODINGMODE
This sets Mercurial's behavior for handling unknown characters
while transcoding user input. The default is "strict", which
causes Mercurial to abort if it can't map a character. Other
settings include "replace", which replaces unknown characters, and
"ignore", which drops them. This setting can be overridden with
the --encodingmode command-line option.
Matt Mackall
encoding: default ambiguous character to narrow...
r12866 HGENCODINGAMBIGUOUS
This sets Mercurial's behavior for handling characters with
"ambiguous" widths like accented Latin characters with East Asian
fonts. By default, Mercurial assumes ambiguous characters are
narrow, set this variable to "wide" if such characters cause
formatting problems.
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999 HGMERGE
An executable to use for resolving merge conflicts. The program
will be executed with three arguments: local file, remote file,
ancestor file.
Brodie Rao
help: refer to user configuration file more consistently...
r12083 (deprecated, use configuration file)
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999
HGRCPATH
Brodie Rao
help: refer to user configuration file more consistently...
r12083 A list of files or directories to search for configuration
files. Item separator is ":" on Unix, ";" on Windows. If HGRCPATH
is not set, platform default search path is used. If empty, only
the .hg/hgrc from the current repository is read.
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999
For each element in HGRCPATH:
- if it's a directory, all files ending with .rc are added
- otherwise, the file itself will be added
Brodie Rao
ui: add HGPLAIN environment variable for easier scripting...
r10455 HGPLAIN
Brodie Rao
help: refer to user configuration file more consistently...
r12083 When set, this disables any configuration settings that might
change Mercurial's default output. This includes encoding,
defaults, verbose mode, debug mode, quiet mode, tracebacks, and
Brodie Rao
ui: add HGPLAIN environment variable for easier scripting...
r10455 localization. This can be useful when scripting against Mercurial
in the face of existing user configuration.
Equivalent options set via command line flags or environment
variables are not overridden.
Brodie Rao
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT...
r13849 HGPLAINEXCEPT
This is a comma-separated list of features to preserve when
Yuya Nishihara
help: mention alias and revsetalias in description of HGPLAINEXCEPT
r26827 HGPLAIN is enabled. Currently the following values are supported:
``alias``
Don't remove aliases.
``i18n``
Preserve internationalization.
``revsetalias``
Don't remove revset aliases.
Brodie Rao
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT...
r13849
Setting HGPLAINEXCEPT to anything (even an empty string) will
enable plain mode.
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999 HGUSER
This is the string used as the author of a commit. If not set,
available values will be considered in this order:
- HGUSER (deprecated)
Brodie Rao
help: refer to user configuration file more consistently...
r12083 - configuration files from the HGRCPATH
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999 - EMAIL
- interactive prompt
- LOGNAME (with ``@hostname`` appended)
Brodie Rao
help: refer to user configuration file more consistently...
r12083 (deprecated, use configuration file)
Dan Villiom Podlaski Christiansen
setup: install translation files as package data...
r9999
EMAIL
May be used as the author of a commit; see HGUSER.
LOGNAME
May be used as the author of a commit; see HGUSER.
VISUAL
This is the name of the editor to use when committing. See EDITOR.
EDITOR
Sometimes Mercurial needs to open a text file in an editor for a
user to modify, for example when writing commit messages. The
editor it uses is determined by looking at the environment
variables HGEDITOR, VISUAL and EDITOR, in that order. The first
non-empty one is chosen. If all of them are empty, the editor
defaults to 'vi'.
PYTHONPATH
This is used by Python to find imported modules and may need to be
set appropriately if this Mercurial is not installed system-wide.