Mercurial > hg
diff mercurial/policy.py @ 43075:57875cf423c9
style: run a patched black on a subset of mercurial
This applied black to the 20 smallest files in mercurial/:
ls -S1 mercurial/*.py | tail -n20 | xargs black --skip-string-normalization
Note that a few files failed to format, presumably due to a bug in my
patch. The intent is to be able to compare results to D5064 with
https://github.com/python/black/pull/826 applied to black.
I skipped string normalization on this patch for clarity - in reality
I think we'd want one pass without string normalization, followed by
another to normalize strings (which is basically replacing ' with "
globally.)
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6342
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 05 Oct 2019 10:29:34 -0400 |
parents | 810f66b468cd |
children | c59eb1560c44 |
line wrap: on
line diff
--- a/mercurial/policy.py Fri Oct 04 15:53:45 2019 -0400 +++ b/mercurial/policy.py Sat Oct 05 10:29:34 2019 -0400 @@ -39,6 +39,7 @@ try: from . import __modulepolicy__ + policy = __modulepolicy__.modulepolicy except ImportError: pass @@ -57,6 +58,7 @@ else: policy = os.environ.get(r'HGMODULEPOLICY', policy) + def _importfrom(pkgname, modname): # from .<pkgname> import <modname> (where . is looked through this module) fakelocals = {} @@ -69,6 +71,7 @@ getattr(mod, r'__doc__', None) return fakelocals[modname] + # keep in sync with "version" in C modules _cextversions = { (r'cext', r'base85'): 1, @@ -86,13 +89,17 @@ (r'cffi', r'parsers'): (r'pure', r'parsers'), } + def _checkmod(pkgname, modname, mod): expected = _cextversions.get((pkgname, modname)) actual = getattr(mod, r'version', None) if actual != expected: - raise ImportError(r'cannot import module %s.%s ' - r'(expected version: %d, actual: %r)' - % (pkgname, modname, expected, actual)) + raise ImportError( + r'cannot import module %s.%s ' + r'(expected version: %d, actual: %r)' + % (pkgname, modname, expected, actual) + ) + def importmod(modname): """Import module according to policy and check API version""" @@ -114,10 +121,12 @@ pn, mn = _modredirects.get((purepkg, modname), (purepkg, modname)) return _importfrom(pn, mn) + def _isrustpermissive(): """Assuming the policy is a Rust one, tell if it's permissive.""" return policy.endswith(b'-allow') + def importrust(modname, member=None, default=None): """Import Rust module according to policy and availability.