-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build and ci: migrate to pyproject.toml / hatchling
This follows along the migration in Indico 3.3.4.
- Loading branch information
Showing
6 changed files
with
108 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# This file is part of the Indico plugin indico-sso-group-mapping. | ||
# Copyright (C) 2022 - 2024 University of Bonn | ||
# | ||
# The Indico plugin indico-sso-group-mapping is free software; you can | ||
# redistribute it and/or modify it under the terms of the MIT License; | ||
# see the LICENSE file for more details. | ||
|
||
import json | ||
import os | ||
import subprocess | ||
from contextlib import contextmanager | ||
from pathlib import Path | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
|
||
class CustomBuildHook(BuildHookInterface): | ||
def initialize(self, version, build_data): | ||
if os.environ.get('READTHEDOCS') == 'True' or version == 'editable': | ||
return | ||
if translations_dir := next(Path().glob('indico_*/translations/'), None): | ||
_compile_languages(translations_dir) | ||
_compile_languages_react(translations_dir) | ||
|
||
|
||
def _compile_languages(translations_dir: Path): | ||
from babel.messages.frontend import CompileCatalog | ||
if not any(translations_dir.glob('**/*.po')): | ||
return | ||
cmd = CompileCatalog() | ||
cmd.directory = translations_dir | ||
cmd.finalize_options() | ||
cmd.use_fuzzy = True | ||
cmd.run() | ||
|
||
|
||
def _compile_languages_react(translations_dir: Path): | ||
# we assume a ..../indico/{src,plugins/whatever}/ structure for indico and plugin repos | ||
indico_root = Path('../../../src/').absolute().resolve() | ||
for subdir in translations_dir.absolute().iterdir(): | ||
po_file = subdir / 'LC_MESSAGES' / 'messages-react.po' | ||
json_file = subdir / 'LC_MESSAGES' / 'messages-react.json' | ||
if not po_file.exists(): | ||
continue | ||
with _chdir(indico_root): | ||
output = subprocess.check_output(['npx', 'react-jsx-i18n', 'compile', po_file], stderr=subprocess.DEVNULL) | ||
json.loads(output) # just to be sure the JSON is valid | ||
json_file.write_bytes(output) | ||
|
||
|
||
@contextmanager | ||
def _chdir(path: Path): | ||
old_path = Path.cwd() | ||
os.chdir(path) | ||
try: | ||
yield | ||
finally: | ||
os.chdir(old_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
[project] | ||
name = 'indico-sso-group-mapping' | ||
description = 'SSO group mapping plugin for Indico' | ||
readme = 'README.md' | ||
version = '1.0.2' | ||
license = 'MIT' | ||
authors = [{ name = 'University of Bonn' }] | ||
classifiers = [ | ||
'Environment :: Plugins', | ||
'Environment :: Web Environment', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3.12', | ||
] | ||
requires-python = '>=3.12.2, <3.13' | ||
dependencies = ['indico>=3.3'] | ||
|
||
[project.urls] | ||
GitHub = 'https://github.com/unibonn/indico-sso-group-mapping' | ||
|
||
[project.entry-points.'indico.plugins'] | ||
sso_group_mapping = indico_sso_group_mapping.plugin:SSOGroupMappingPlugin | ||
|
||
[build-system] | ||
requires = ['hatchling==1.25.0'] | ||
build-backend = 'hatchling.build' | ||
|
||
[tool.hatch.build] | ||
packages = ['indico_sso_group_mapping'] | ||
exclude = [ | ||
'*.no-header', | ||
'.keep', | ||
# exclude original client sources (they are all included in source maps anyway) | ||
'indico_*/client/', | ||
# no need for tests outside development | ||
'test_snapshots/', | ||
'tests/', | ||
'*_test.py', | ||
] | ||
artifacts = [ | ||
'indico_*/translations/**/messages-react.json', | ||
'indico_*/translations/**/*.mo', | ||
'indico_*/static/dist/', | ||
] | ||
|
||
[tool.hatch.build.targets.sdist.hooks.custom] | ||
path = 'hatch_build.py' | ||
dependencies = ['babel==2.16.0'] |