Mercurial > p > roundup > code
annotate roundup/dist/command/build.py @ 6647:42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
First pass at fixing this. Seems to work in:
native install
virtual env
python 2.7 and 3.6. Also docker python 3. Could use more testing
though.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 28 Apr 2022 18:10:10 -0400 |
| parents | f2fade4552c5 |
| children | 1acdc651133b |
| 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 raise ImportError |
|
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
11 except ImportError: |
|
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
12 from distutils.command.build import build as base |
| 4068 | 13 import os |
| 14 from glob import glob | |
| 15 | |
| 16 def list_message_files(suffix=".po"): | |
| 17 """Return list of all found message files and their intallation paths""" | |
| 18 _files = glob("locale/*" + suffix) | |
| 19 _list = [] | |
| 20 for _file in _files: | |
| 21 # basename (without extension) is a locale name | |
| 22 _locale = os.path.splitext(os.path.basename(_file))[0] | |
| 23 _list.append((_file, os.path.join( | |
| 24 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) | |
| 25 return _list | |
| 26 | |
| 27 def check_manifest(): | |
| 28 """Check that the files listed in the MANIFEST are present when the | |
| 29 source is unpacked. | |
| 30 """ | |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
31 manifest_file = 'roundup.egg-info/SOURCES.txt' |
| 4068 | 32 try: |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
33 f=open(manifest_file) |
| 4068 | 34 except: |
|
6647
42bf0a707763
issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents:
5450
diff
changeset
|
35 print('\n*** SOURCE WARNING: The MANIFEST file "%s" is missing!' % manifest_file) |
| 4068 | 36 return |
| 37 try: | |
| 38 manifest = [l.strip() for l in f.readlines()] | |
| 39 finally: | |
| 40 f.close() | |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
41 err = set([line for line in manifest if not os.path.exists(line)]) |
| 4068 | 42 # ignore auto-generated files |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
43 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
|
44 'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server']) |
| 4068 | 45 if err: |
| 46 n = len(manifest) | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
47 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
|
48 n-len(err), n)) |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
49 print('Missing:', '\nMissing: '.join(err)) |
| 4068 | 50 |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
51 def build_message_files(command): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
52 """For each locale/*.po, build .mo file in target locale directory""" |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
53 for (_src, _dst) in list_message_files(): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
54 _build_dst = os.path.join("build", _dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
55 command.mkpath(os.path.dirname(_build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
56 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
|
57 mo = msgfmt.Msgfmt(_src).get() |
|
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
58 open(_build_dst, 'wb').write(mo) |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
59 |
| 4068 | 60 |
| 61 class build(base): | |
| 62 | |
| 63 def run(self): | |
| 64 check_manifest() | |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
65 build_message_files(self) |
| 4068 | 66 base.run(self) |
| 67 |
