Skip to content

Commit

Permalink
build and ci: migrate to pyproject.toml / hatchling
Browse files Browse the repository at this point in the history
This follows along the migration in Indico 3.3.4.
  • Loading branch information
olifre committed Sep 7, 2024
1 parent 422451a commit 977aeea
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 101 deletions.
52 changes: 0 additions & 52 deletions .github/utils/check_manifests.py

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip|${{ runner.os }}|3.12|${{ hashFiles('**/setup.cfg') }}
key: pip|${{ runner.os }}|3.12|${{ hashFiles('**/pyproject.toml') }}

- uses: actions/cache@v4
id: cache-npm
Expand Down Expand Up @@ -128,9 +128,6 @@ jobs:
echo "VIRTUAL_ENV=$(pwd)/.venv" >> $GITHUB_ENV
echo "$(pwd)/.venv/bin" >> $GITHUB_PATH
- name: Check manifests
run: python .github/utils/check_manifests.py

- name: Check import sorting
if: success() || failure()
run: isort --diff --check-only .
Expand Down
58 changes: 58 additions & 0 deletions hatch_build.py
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)
49 changes: 49 additions & 0 deletions pyproject.toml
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

Check failure on line 23 in pyproject.toml

View workflow job for this annotation

GitHub Actions / lint

Ruff (RUF200)

pyproject.toml:23:21: RUF200 Failed to parse pyproject.toml: invalid string

[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']
34 changes: 0 additions & 34 deletions setup.cfg

This file was deleted.

11 changes: 0 additions & 11 deletions setup.py

This file was deleted.

0 comments on commit 977aeea

Please sign in to comment.