Mercurial > p > roundup > code
annotate roundup/dist/command/build.py @ 7752:b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
Converting to using the ruff linter and its rulesets. Fixed a number
of issues.
admin.py:
sort imports
use immutable tuples as default value markers for parameters where a
None value is valid.
reduced some loops to list comprehensions for performance
used ternary to simplify some if statements
named some variables to make them less magic
(e.g. _default_savepoint_setting = 1000)
fixed some tests for argument counts < 2 becomes != 2 so 3 is an
error.
moved exception handlers outside of loops for performance where
exception handler will abort loop anyway.
renamed variables called 'id' or 'dir' as they shadow builtin
commands.
fix translations of form _("string %s" % value) -> _("string %s") %
value so translation will be looked up with the key before
substitution.
end dicts, tuples with a trailing comma to reduce missing comma
errors if modified
simplified sorted(list(self.setting.keys())) to
sorted(self.setting.keys()) as sorted consumes whole list.
in if conditions put compared variable on left and threshold condition
on right. (no yoda conditions)
multiple noqa: suppression
removed unneeded noqa as lint rulesets are a bit different
do_get - refactor output printing logic: Use fast return if not
special formatting is requested; use isinstance with a tuple
rather than two isinstance calls; cleaned up flow and removed
comments on algorithm as it can be easily read from the code.
do_filter, do_find - refactor output printing logic. Reduce
duplicate code.
do_find - renamed variable 'value' that was set inside a loop. The
loop index variable was also named 'value'.
do_pragma - added hint to use list subcommand if setting was not
found. Replaced condition 'type(x) is bool' with 'isinstance(x,
bool)' for various types.
test_admin.py
added testing for do_list
better test coverage for do_get includes: -S and -d for multilinks,
error case for -d with non-link.
better testing for do_find including all output modes
better testing for do_filter including all output modes
fixed expected output for do_pragma that now includes hint to use
pragma list if setting not found.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 01 Mar 2024 14:53:18 -0500 |
| parents | 1acdc651133b |
| children | fed0f839c260 |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
6 from __future__ import print_function |
| 4068 | 7 from roundup import msgfmt |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
8 try: |
|
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
9 from setuptool.command.install import install as base |
|
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
10 except ImportError: |
|
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
11 from distutils.command.build import build as base |
| 4068 | 12 import os |
| 13 from glob import glob | |
| 14 | |
| 15 def list_message_files(suffix=".po"): | |
| 16 """Return list of all found message files and their intallation paths""" | |
| 17 _files = glob("locale/*" + suffix) | |
| 18 _list = [] | |
| 19 for _file in _files: | |
| 20 # basename (without extension) is a locale name | |
| 21 _locale = os.path.splitext(os.path.basename(_file))[0] | |
| 22 _list.append((_file, os.path.join( | |
| 23 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) | |
| 24 return _list | |
| 25 | |
| 26 def check_manifest(): | |
| 27 """Check that the files listed in the MANIFEST are present when the | |
| 28 source is unpacked. | |
| 29 """ | |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
30 manifest_file = 'roundup.egg-info/SOURCES.txt' |
| 4068 | 31 try: |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
32 f=open(manifest_file) |
| 4068 | 33 except: |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
34 print('\n*** SOURCE WARNING: The MANIFEST file "%s" is missing!' % manifest_file) |
| 4068 | 35 return |
| 36 try: | |
| 37 manifest = [l.strip() for l in f.readlines()] | |
| 38 finally: | |
| 39 f.close() | |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
40 err = set([line for line in manifest if not os.path.exists(line)]) |
| 4068 | 41 # ignore auto-generated files |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
42 err = err - set(['roundup-admin', 'roundup-demo', 'roundup-gettext', |
|
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
43 'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server']) |
| 4068 | 44 if err: |
| 45 n = len(manifest) | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
46 print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
47 n-len(err), n)) |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
48 print('Missing:', '\nMissing: '.join(err)) |
| 4068 | 49 |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
50 def build_message_files(command): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
51 """For each locale/*.po, build .mo file in target locale directory""" |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
52 for (_src, _dst) in list_message_files(): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
53 _build_dst = os.path.join("build", _dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
54 command.mkpath(os.path.dirname(_build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
55 command.announce("Compiling %s -> %s" % (_src, _build_dst)) |
|
5450
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
56 mo = msgfmt.Msgfmt(_src).get() |
|
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
57 open(_build_dst, 'wb').write(mo) |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
58 |
| 4068 | 59 |
| 60 class build(base): | |
| 61 | |
| 62 def run(self): | |
| 63 check_manifest() | |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
64 build_message_files(self) |
| 4068 | 65 base.run(self) |
| 66 |
