The gettext.install() function installs a builtin _() function which
translates a string in the translation domain supplied to the install()
function. If gettext.install() is called multiple times, it's the last
call to the function which wins and the last supplied translation domain
which is used e.g.
>>> import os
>>> os.environ['LANG'] = 'ja.UTF-8'
>>> import gettext
>>> gettext.install('keystone', unicode=1, localedir='/opt/stack/keystone/keystone/locale')
>>> print _('Invalid syslog facility')
無効な syslog ファシリティ
>>> gettext.install('nova', unicode=1, localedir='/opt/stack/nova/nova/locale')
>>> print _('Invalid syslog facility')
Invalid syslog facility
Usually this function is called early on in a toplevel script and we
assume that no other code will call it and override the installed _().
However, in Nova, we have taken a shortcut to avoid having to call it
explicitly from each script and instead call it from nova/__init__.py.
This shortcut would be perfectly fine if we were absolutely sure that
nova modules would never be imported from another program. It's probably
quite incorrect for a program to use nova code (indeed, if we wanted to
support this, Nova code shouldn't use the default _() function) but
nevertheless there are some corner cases where it happens. For example,
the keystoneclient auth_token middleware tries to import cfg from
nova.openstack.common and this in turn causes gettext.install('nova')
in other projects like glance or quantum.
To avoid any doubt here, let's just rip out the shortcut and always
call gettext.install() from the top-level script.
Change-Id: If4125d6bcbde63df95de129ac5c83b4a6d6f130a
The nova gate should recommend 50 characters or less for a git commit
but actually enforce 72 characters.
This patch changes the hacking.rst docs to indicate the actual limit
is 72 characters rather then 50 characters.
Change-Id: I47f1f1f1007f5744bf1fef419df7e033803b4a53
Fixes: Bug #1144840
If a module isn't importable due to an unexpected error during
__import__. Ignore it, hacking.py is only a style checker.
Fix bug 1134622
Change-Id: I704b7cc9a7bd415018ae7634767b7bd9c3b7d9b2
Previously: def foo():\n a = '''This is not a docstring'''
would be counted as a docstring even though it isn't.
Fix this and add docstring tests.
Fix bug 1100912
Change-Id: Id4d4aa382713eea340720e166e418262ba68eaaf
Fix missingImport logic to handle a module that cannot be imported, due
to a missing dependant module.
Due to the nature of this bug doctests cannot cover it.
Fix bug 1133103
Change-Id: Ia067bacc125b67e2d9e0cfc72495e4f13a8648ad
This fixes all of the files incorrectly importing logging directly
and removes the workaround in hacking.py that was due to improper
from nova.openstack.common.log import logging statements.
Change-Id: Icfc25dc148c4a7b5fa7f6a7b609cd6c3d94efee1
This removes our workaround for namespace packages and improves
detection of missing imports due to non-existent dependencies.
Fixes bug 1130411
Change-Id: I89ee8249580e395f786289792cdf74219d041f2f
The cfg API is now available via the oslo-config library, so switch to
it and remove the copied-and-pasted version.
Add the 2013.1b4 tarball to tools/pip-requires - this will be changed
to 'oslo-config>=2013.1' when oslo-config is published to pypi. This
will happen in time for grizzly final.
Add dependency_links to setup.py so that oslo-config can be installed
from the tarball URL specified in pip-requires.
Remove the 'deps = pep8==1.3.3' from tox.ini as it means all the other
deps get installed with easy_install which can't install oslo-config
from the URL.
Make tools/hacking.py include oslo in IMPORT_EXCEPTIONS like it already
does for paste. It turns out imp.find_module() doesn't correct handle
namespace packages.
Retain dummy cfg.py file until keystoneclient middleware has been
updated (I18c450174277c8e2d15ed93879da6cd92074c27a).
Change-Id: I4815aeb8a9341a31a250e920157f15ee15cfc5bc
There were a few incompatibilities with the hacking tests and
OSX. Readlink -f doesn't work so use cd and pwd instead. Importing
a module with path separators doesn't work, so recursively import
the module. Finally the extra / in the find command was not needed.
Add a 'set -e' to run_pep8 to make sure test fails on any error
Ignore paste as it doesn't have an __init__ in its top level directory
Change-Id: Ifc66da7b872faa08f3be98f8b10486181ba77861
* Implementing the * import detection (it is disabled for now)
* New style relative import testing based on syntax rules
* Old style relative import testing based on module search
* Inspection based solution replaced by PYTHONPATH search
in order to avoid module compile and initialization steps
(code execution) in a syntax checking phase.
This solution is faster and safer, but does not able to recognize
modules added dynamically to the module scope.
Change-Id: Ifc871f4fdbcd4a9a736170ceb4475f4f2cbe66bc
HACKING.rst was updated in I7534ef73e6fd525fd8f4bee594a4b37524699c08.
This adds hacking.py enforcement.
Change-Id: I5d75d536762449d0a7ae38213addd02aeceede0b
* Includes some general tools/hacking cleanup
* Fix several N302 cases
* Disable N302 until all cases are fixed
Change-Id: Iddba07ff13e10dc41a6930749044bb8c0572d279
* Fixes N403, along with docstring test
* Adds N404, multi line start
* Disable N403 and N404 until all cases are fixed
* Remove obsolote '--repeat' flag from tox.ini
Change-Id: Ibf6371efc1cdc764e66f6f7c5c4362440101f963
triggered by this slipping into quantum, now that we have more windows
developers we should ensure that \r\n doesn't land in the code as
a line ending. This check prevents it.
Change-Id: I0a82be0e74915d3c3c25203db110d279580c148b
pep8 and hacking.py (by inheritance) have the ability to run self
tests via docstrings, if we format the comments correctly, and change
the docstring test regex. Include self testing in our normal pep8
tests.
fix the comments to actually be test case compliant
fix nova_import_alphabetical to pass on short import lists (only 2
lines, starting at the beginning of a file)
comment where it doesn't appear that hacking.py tests are working
(though there could be deeper black magic in some of them).
fix a doc string in pep8 self tests that breaks N301
fix the fact that pep8 error strings are supposed to start with
\w\d\d\d, we were just lucking out on some formatting because the
string NOVA happened to be only 4 chars long.
Add a couple of escapes so that we don't recursively fail on our
own fail self tests for comments. (boy that's fun)
Change-Id: I14d5e04cfc092b37ec4967cd7485e9975a5eb820
We had previously been ignoring all our custom N4xx hacking.py
errors. This fixes all the N401 errors "doc strings
should not start with a space" and reduces the ignore set down
to N402 only "single line docstrings should end with period".
It also fixes the N401 parser to catch only docstrings, and
not tripple quoted string blocks used later on in a function.
Clean up a few of the more crazy uses of """ in our code
Clean up additional funky comments to make indents a bit more
consistent, and pull in lines when possible.
Change-Id: I9040a1d2ca7efda83bd5e425b95d1408b5b63577
* With pep8 1.3.3 the exclude logic monkey patch broke causing
tools/hacking to run on openstack/common code
* Also add .git to exclude list
Fix bug 1086410
Change-Id: Ifc50ac1963c50c338432bbb4b1e15cdf58ed2128
This makes hacking.py complain if someone adds something like:
from nova import db
into any of the files in nova/virt/* (aside from the fake.py file).
It also removes the rest of the dangling db imports that are no
longer needed.
Yay!
Change-Id: Iba3d53b87e65e33a55f8e5033b5d1d33b28d12f7
Only logical lines (does not include comments) should be checked for
alphabetical import order. This patch changes N306
(imports not in alphabetical order) to run on logical lines not physical lines.
Fixes bug 1071849
Change-Id: Ib2cb92f9eb82aeed1ff5879d3e38c8961b4f06cc
Right now, any line that starts with "from" (after whitespace
removal) is considered an import line. That assumption leads to
some unsavory parsing and crashing if the line doesn't match
the expected format.
This patch checks to make sure that the word "import" is in the line
as well as starting with "from", which at least gets us a bit closer
to a reasonable assumption.
Fixes bug 1071849
Change-Id: Iab666fcd04a9aaa3a490737a173ee3189b9b8329
* b9f72b1601
broke tools/hacking.py
* Upgrade pep8 to 1.2 and disable the following new tests: E12,E711,E712,E721,E502
Change-Id: I32a8808c6c9cccfedcc4d2a26649333aca1cd713
First of all, our pep8 exclude was excluding openstack, to trap
for not doing pep8 checks on openstack/common, which comes from elsewhere.
But, pep8 strips filenames down to basename when doing exclude checks on
them, which makes no sense. To fix this, grab the two functions from pep8,
fix them, and monkeypatch them from within hacking.py.
Patch has been submitted upstream as:
https://github.com/jcrocholl/pep8/pull/111
Also, changed the exclude to catch just openstack/common.
Change-Id: If0b18ae828e74203f84a8b6f8b4ba0100b3bbc59
recent openstack-common brought in it's own def of _() which trips
up our checking that all _ calls contain a message string.
This explicitly excludes the definition of this in function from
that check.
Fixes LP Bug #1020792.
Change-Id: If647d77a5ae5560935bb2e032331c34b896b8614
i18n stands for internationalization, while l10n stands for
localization. l18n stands for nothing.
Change-Id: Iebfe2dcbc12919875c0ecee8aa9223dc107239d7
The latest release of pep8 adds stricter rules for extraneous
whitespace within lines. This patch also addresses these new
violations acoss the codebase.
Change-Id: Ib7e50281870473df1704ed50868c5c2e26bdb02e
* cleaner output
* fix bug 980009
* Fix N201
* N306: alphabetical order imports
* N401: docstring start
* N402: one line docstring start
* N403: multi line docstring end
* Until fixed, N40* will be disabled by default
Change-Id: I9addafdaa7a1f8fb950e14a5409f661dec6c7b87
Looks like this fixes all HACKING problems that were around.
Thanks to Dina Belova and Alexander Kovalev for this work.
Change-Id: I8157f0d4890184c1216aab63ef7180ee8b7a184d
Tests so far:
N101 TODO format
N201 Except format
N301 One import per line
N302 import only modules
N303 Invalid Import
N304 Relative Import
Change-Id: I33c021b842e7199b1f5f1f699ea17f7fa5f8ca49