Skip to content

Commit

Permalink
Merge pull request #269 from jim-easterbrook/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
jim-easterbrook authored Sep 10, 2024
2 parents 2a4656e + c611405 commit a108b8a
Show file tree
Hide file tree
Showing 30 changed files with 908 additions and 543 deletions.
81 changes: 0 additions & 81 deletions custom_build/backend.py

This file was deleted.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

[build-system]
requires = ["setuptools >= 59.6", "setuptools_scm[toml]>=6.2", "toml"]
#build-backend = "setuptools.build_meta"
build-backend = "backend"
backend-path = ["custom_build"]
build-backend = "setuptools.build_meta"

[project]
name = "Photini"
Expand All @@ -47,6 +45,7 @@ dependencies = [
"filetype >= 1.0",
"Pillow >= 2.0",
"requests >= 2.4",
"pywin32 >= 302; platform_system == 'Windows'",
]
dynamic = ["version"]

Expand Down
155 changes: 126 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,109 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.

from setuptools import setup
import os
import xml.etree.ElementTree as ET

from distutils.command.build import build
from distutils.errors import DistutilsOptionError
from setuptools import Command, setup
from setuptools import __version__ as setuptools_version

if tuple(map(int, setuptools_version.split('.')[:2])) >= (61, 0):
# use metadata from pyproject.toml directly
setup()
else:
import os

def strip_plurals(self, src_file, dst_file, plural_count):
# copy source to remove extra plurals not used by Qt
tree = ET.parse(src_file)
xml = tree.getroot()
for context in xml.iter('context'):
for message in context.iter('message'):
if message.get('numerus'):
translation = message.find('translation')
numerusforms = translation.findall('numerusform')
extra = len(numerusforms) - plural_count
for i in range(extra):
translation.remove(numerusforms.pop())
tree.write(dst_file, encoding='utf-8',
xml_declaration=True, short_empty_elements=False)

def run_lrelease(self, src_file, dst_file):
# run one of the possible versions of 'lrelease'
for tool in list(self.tools):
try:
self.spawn([tool, '-silent', src_file, '-qm', dst_file])
return
except Exception as ex:
self.tools.remove(tool)


# add command to 'compile' translated messages
class BuildLang(Command):
description = 'compile translated strings (.ts) to binary .qm files'
user_options = [
('input-dir=', 'i', 'location of input .ts files'),
('build-lib=', 'd', 'directory to build to'),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
]

def initialize_options(self):
self.input_dir = None
self.build_lib = None
self.build_temp = None
self.force = None

def finalize_options(self):
self.set_undefined_options('build',
('build_lib', 'build_lib'),
('build_temp', 'build_temp'),
('force', 'force'),
)
if not self.input_dir:
raise DistutilsOptionError('no input directory specified')
self.build_temp = os.path.join(self.build_temp, 'lang')
self.output_dir = os.path.join(
self.build_lib, 'photini', 'data', 'lang')

def run(self):
self.announce('running build_lang')
self.tools = ['lrelease6', 'pyside6-lrelease', 'lrelease-qt5']
self.mkpath(self.output_dir)
self.mkpath(self.build_temp)
numerus_count = {'cs': 3, 'es': 2, 'fr': 2, 'it': 2, 'pl': 3}
for lang in os.listdir(self.input_dir):
src_file = os.path.join(self.input_dir, lang, 'photini.ts')
if not os.path.exists(src_file):
continue
dst_file = os.path.join(
self.output_dir, 'photini.' + lang + '.qm')
if lang in numerus_count:
tmp_file = os.path.join(
self.build_temp, 'photini.' + lang + '.ts')
self.make_file(src_file, tmp_file, strip_plurals,
(self, src_file, tmp_file, numerus_count[lang]))
self.make_file(tmp_file, dst_file, run_lrelease,
(self, tmp_file, dst_file))
else:
self.make_file(src_file, dst_file, run_lrelease,
(self, src_file, dst_file))
if not self.tools:
self.warn('unable to compile translation files')
break


class CustomBuild(build):
sub_commands = [('build_lang', None), *build.sub_commands]


setup_kwds = {
'cmdclass': {'build': CustomBuild, 'build_lang': BuildLang},
'command_options': {
'build_lang': {
'input_dir' : ('setup.py', 'src/lang'),
},
},
}


if tuple(map(int, setuptools_version.split('.')[:2])) < (61, 0):
# get metadata from pyproject.toml
import toml
metadata = toml.load('pyproject.toml')
Expand All @@ -37,26 +131,29 @@
package_data += [
os.path.join(root.replace('src/photini/', ''), x) for x in files]

setup(name = metadata['project']['name'],
author = metadata['project']['authors'][0]['name'],
author_email = metadata['project']['authors'][0]['email'],
url = metadata['project']['urls']['Homepage'],
description = metadata['project']['description'],
long_description = long_description,
classifiers = metadata['project']['classifiers'],
license = metadata['project']['license']['text'],
packages = ['photini'],
package_dir = {'' : 'src'},
package_data = {'photini' : package_data},
entry_points = {
'console_scripts' : [
'{} = {}'.format(k, v)
for k, v in metadata['project']['scripts'].items()],
'gui_scripts' : [
'{} = {}'.format(k, v)
for k, v in metadata['project']['gui-scripts'].items()],
},
install_requires = metadata['project']['dependencies'],
extras_require = metadata['project']['optional-dependencies'],
zip_safe = metadata['tool']['setuptools']['zip-safe'],
)
setup_kwds.update(
name = metadata['project']['name'],
author = metadata['project']['authors'][0]['name'],
author_email = metadata['project']['authors'][0]['email'],
url = metadata['project']['urls']['Homepage'],
description = metadata['project']['description'],
long_description = long_description,
classifiers = metadata['project']['classifiers'],
license = metadata['project']['license']['text'],
packages = ['photini'],
package_dir = {'' : 'src'},
package_data = {'photini' : package_data},
entry_points = {
'console_scripts' : [
'{} = {}'.format(k, v)
for k, v in metadata['project']['scripts'].items()],
'gui_scripts' : [
'{} = {}'.format(k, v)
for k, v in metadata['project']['gui-scripts'].items()],
},
install_requires = metadata['project']['dependencies'],
extras_require = metadata['project']['optional-dependencies'],
zip_safe = metadata['tool']['setuptools']['zip-safe'],
)

setup(**setup_kwds)
20 changes: 20 additions & 0 deletions src/lang/ca/photini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@
<source>GPX importer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>location pin (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Map icon colours</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>location pin (unselected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (unselected)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FlickrTab</name>
Expand Down
20 changes: 20 additions & 0 deletions src/lang/cs/photini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@
<source>GPX importer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>location pin (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Map icon colours</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>location pin (unselected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (unselected)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FlickrTab</name>
Expand Down
20 changes: 20 additions & 0 deletions src/lang/de/photini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@
<source>GPX importer</source>
<translation>GPX-Importprogramm</translation>
</message>
<message>
<source>location pin (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Map icon colours</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>location pin (unselected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (selected)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPS track point (unselected)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FlickrTab</name>
Expand Down
Loading

0 comments on commit a108b8a

Please sign in to comment.