launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12114
[Merge] lp:~jtv/launchpad/format-relative-imports into lp:launchpad
Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/format-relative-imports into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/launchpad/format-relative-imports/+merge/124878
This is a backport of a change I made in MAAS: an import in python can now start with a module/package name or now, for a relative import, with a series of dots. From the script's perspective, either plays the same role in the import statement.
I discussed my solution with wgrant, SteveK, and lifeless but not very much came out. I had a bug and a fix so I took silence as assent.
It's not a particularly forward-looking solution: “.” is defined as local (duh) but there's no cleverness for “..” or “...” etc. — they're /probably/ local imports but the more dots there are, the less likely that becomes. At least my immediate problem of “.” is a clear-cut case. If we ever see more leading dots, that'd be a good time to figure out what the right thing to do is.
Jeroen
--
https://code.launchpad.net/~jtv/launchpad/format-relative-imports/+merge/124878
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/format-relative-imports into lp:launchpad.
=== modified file 'utilities/format-imports'
--- utilities/format-imports 2012-02-21 22:46:28 +0000
+++ utilities/format-imports 2012-09-18 10:19:18 +0000
@@ -152,7 +152,10 @@
comment_regex = re.compile(
"(?P<comment>(^#.+\n)+)(^import|^from) +(?P<module>[a-zA-Z0-9_.]+)", re.M)
split_regex = re.compile(",\s*")
-module_base_regex = re.compile("([^. ]+)")
+
+# The base part of an import is its leading part: either a series of
+# dots, or a leading identifier.
+module_base_regex = re.compile("([.]+|[^. ]+)")
# Module docstrings are multiline (""") strings that are not indented and are
# followed at some point by an import .
@@ -287,7 +290,7 @@
return imports
LOCAL_PACKAGES = (
- 'canonical', 'lp', 'launchpad_loggerhead', 'devscripts',
+ '.', 'canonical', 'lp', 'launchpad_loggerhead', 'devscripts',
# database/* have some implicit relative imports.
'fti', 'replication', 'preflight', 'security', 'upgrade',
)
Follow ups