Philipp Hörist pushed to branch pyproject at gajim / python-nbxmpp
Commits: 510072da by Philipp Hörist at 2023-01-18T21:57:24+01:00 change: Port package to pyproject.toml
- - - - - 0d0bb0fa by Philipp Hörist at 2023-01-18T21:57:24+01:00 ci: Use release-helper
- Remove obsolete scripts
- - - - -
8 changed files:
- − .ci/debian_build.py - − .ci/deploy.py - .gitlab-ci.yml - debian/control - pyproject.toml - scripts/bump_version.py - − setup.cfg - − setup.py
Changes:
===================================== .ci/debian_build.py deleted ===================================== @@ -1,105 +0,0 @@ -#!/usr/bin/env python3 - -from __future__ import annotations - -import argparse -import dataclasses -import logging -import shutil -import subprocess -from datetime import datetime -from datetime import timezone -from pathlib import Path - -LOG_FORMAT = '%(asctime)s %(levelname)s %(message)s' -logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG) -log = logging.getLogger() - -ROOT_DIR = Path(__file__).resolve().parent.parent -BUILD_DIR = ROOT_DIR / 'debian_build' - -DATE = datetime.now().strftime('%Y%m%d') -DATE_TIME = datetime.now(tz=timezone.utc).strftime('%a, %d %b %Y %T %z') - - -@dataclasses.dataclass -class ReleaseContext: - app: str - pkg_name: str - rev: str - release_name: str - release_dir: Path - tarball: Path - - @classmethod - def from_tarball(cls, path: str, prefix: str, rev: str) -> ReleaseContext: - tarball = Path(path) - app = tarball.name.split('-', maxsplit=1)[0] - pkg_name = f'{prefix}{app}-nightly' - release_name = f'{pkg_name}_{DATE}' - release_dir = BUILD_DIR / release_name - return cls(app=app, - pkg_name=pkg_name, - rev=rev, - release_name=release_name, - release_dir=release_dir, - tarball=tarball) - - -def clean_build_dir() -> None: - log.info('Cleanup build directory') - if BUILD_DIR.exists(): - shutil.rmtree(BUILD_DIR) - BUILD_DIR.mkdir() - - -def prepare_package_dir(context: ReleaseContext) -> None: - log.info('Extract tarball') - tarball = Path(shutil.copy(context.tarball, BUILD_DIR)) - tarball = tarball.rename(BUILD_DIR / f'{context.release_name}.orig.tar.gz') - shutil.unpack_archive(tarball, BUILD_DIR) - - log.info('Rename dir to: %s', context.release_name) - folder = list(BUILD_DIR.glob(f'{context.app}-?.?.?'))[0] - folder = folder.rename(context.release_dir) - - log.info('Copy debian folder into release directory') - shutil.copytree(ROOT_DIR / 'debian', context.release_dir / 'debian') - - -def prepare_changelog(context: ReleaseContext) -> None: - log.info('Prepare Changelog') - changelog = context.release_dir / 'debian' / 'changelog' - content = changelog.read_text() - content = content.replace('{DATE}', f'{DATE}-{context.rev}') - content = content.replace('{DATE_TIME}', DATE_TIME) - changelog.write_text(content) - - -def build(context: ReleaseContext) -> None: - log.info('Start package build') - subprocess.run( - [ - 'dpkg-buildpackage', - '--no-sign' - ], - cwd=context.release_dir, - check=True) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Build debian package') - parser.add_argument('tarball', help='Path to tarball e.g. app.tar.gz') - parser.add_argument('rev', help='The package revision e.g. 1') - parser.add_argument('--pkgprefix', default='', required=False, - help='Prefix for the package name e.g. python3-') - args = parser.parse_args() - - context = ReleaseContext.from_tarball(args.tarball, - args.pkgprefix, - args.rev) - - clean_build_dir() - prepare_package_dir(context) - prepare_changelog(context) - build(context)
===================================== .ci/deploy.py deleted ===================================== @@ -1,45 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -import subprocess -from pathlib import Path - - -REPO_DIR = Path(__file__).parent.parent -USERNAME = '__token__' -PASSWORD = os.environ['PYPI_TOKEN'] - - -def build() -> None: - cmd = [ - 'python3', - 'setup.py', - 'sdist', - 'bdist_wheel' - ] - - try: - subprocess.run(cmd, cwd=REPO_DIR, check=True) - except subprocess.CalledProcessError: - sys.exit('build failed') - - -def upload() -> None: - cmd = [ - 'twine', - 'upload', - '--username', USERNAME, - '--password', PASSWORD, - 'dist/*' - ] - - try: - subprocess.run(cmd, cwd=REPO_DIR, check=True) - except subprocess.CalledProcessError: - sys.exit('upload failed') - - -if __name__ == '__main__': - # build() - upload()
===================================== .gitlab-ci.yml ===================================== @@ -24,8 +24,10 @@ build-linux: stage: build dependencies: [] script: - - python3 setup.py sdist bdist_wheel - - python3 .ci/debian_build.py "$(find dist/nbxmpp-*.tar.gz)" 1 --pkgprefix=python3- + - pip install git+https://dev.gajim.org/gajim/release-helper.git + - pip install build + - python3 -m build + - release-helper build-debian-pkg "$(find dist/nbxmpp-*.tar.gz)" 1 --pkgprefix=python3 --pkgsuffix=nightly
artifacts: name: "nbxmpp-$CI_COMMIT_SHA" @@ -33,6 +35,7 @@ build-linux: paths: - dist/nbxmpp-*.tar.gz - dist/nbxmpp-*.whl + - debian_build/python3-nbxmpp*.deb
deploy-pypi: stage: deploy @@ -42,3 +45,4 @@ deploy-pypi: - if: '$CI_COMMIT_TAG' script: - python3 .ci/deploy.py + - twine upload --username=__token__ --password=$PYPI_TOKEN dist/*
===================================== debian/control ===================================== @@ -1,18 +1,17 @@ Source: python3-nbxmpp-nightly -Section: net +Section: python Priority: optional Maintainer: Gajim Maintainers ci@gajim.org Build-Depends: debhelper-compat (= 13), dh-python, - libglib2.0-0 (>= 2.60), gir1.2-soup-3.0, python3-all, python3-gi, python3-idna, python3-packaging, python3-precis-i18n, - python3-setuptools, + python3-setuptools (>= 65.0.0), Standards-Version: 4.1.4 Rules-Requires-Root: no Homepage: https://dev.gajim.org/gajim/python-nbxmpp @@ -23,14 +22,11 @@ Package: python3-nbxmpp-nightly Architecture: all Depends: ${misc:Depends}, ${python3:Depends}, - libglib2.0-0 (>= 2.60), gir1.2-soup-3.0, python3-gi, - python3-idna, - python3-packaging, - python3-precis-i18n, Recommends: python3-gssapi, -Breaks: gajim (<< 1.4~) +Breaks: gajim (<< 1.6~) +Conflicts: python3-nbxmpp Description: Non blocking XMPP Python library python-nbxmpp is a Python library that provides a way for Python applications - to use the XMPP network. This library was initially a fork of xmpppy. \ No newline at end of file + to use the XMPP network. This library was initially a fork of xmpppy.
===================================== pyproject.toml ===================================== @@ -1,9 +1,44 @@ [build-system] -requires = [ - "setuptools >= 43.0.0", -] +requires = ["setuptools >= 65.0.0"] build-backend = "setuptools.build_meta"
+[project] +name = "nbxmpp" +description = "XMPP Library" +keywords = ["chat", "messaging", "im", "xmpp"] +readme = "README.md" +requires-python = ">=3.10" +license = {text = "GPL-3.0-or-later"} +authors = [ + {name = "Philipp Hörist", email = "philipp@hoerist.com"}, + {name = "Yann Leboulanger", email = "yann@leboulanger.org"}, +] +classifiers = [ + "Programming Language :: Python :: 3.10", +] +dependencies = [ + "precis-i18n>=1.0.0", + "packaging", + "idna", + "PyGObject", +] + +dynamic = ["version"] + +[project.optional-dependencies] +gssapi = ["gssapi"] + +[project.urls] +repository = "https://dev.gajim.org/gajim/python-nbxmpp" + +[tool.setuptools.packages.find] +include = ["nbxmpp*"] + +[tool.setuptools.package-data] +"nbxmpp" = ["py.typed"] + +[tool.setuptools.dynamic] +version = {attr = "nbxmpp.__version__"}
[tool.pyright] pythonVersion = "3.10"
===================================== scripts/bump_version.py ===================================== @@ -9,7 +9,6 @@ REPO_DIR = Path(__file__).resolve().parent.parent
INIT = REPO_DIR / 'nbxmpp' / '__init__.py' -CFG = REPO_DIR / 'setup.cfg' CHANGELOG = REPO_DIR / 'ChangeLog'
VERSION_RX = r'\d+.\d+.\d+' @@ -28,10 +27,6 @@ def bump_version(current_version: str, new_version: str) -> None: content = content.replace(current_version, new_version, 1) INIT.write_text(content, encoding='utf8')
- content = CFG.read_text(encoding='utf8') - content = content.replace(current_version, new_version, 1) - CFG.write_text(content, encoding='utf8') -
def make_changelog(new_version: str) -> None:
===================================== setup.cfg deleted ===================================== @@ -1,32 +0,0 @@ -[metadata] -name = nbxmpp -version = 4.0.1 -description = XMPP Library -author = Yann Leboulanger, Philipp Hoerist -author_email = gajim-devel@gajim.org -long_description = file: README.md -long_description_content_type = text/markdown -keywords = xmpp chat -url = https://dev.gajim.org/gajim/python-nbxmpp -license_file = COPYING -license = GPL v3 -classifiers = - Programming Language :: Python :: 3.10 - -[options] -python_requires = >=3.10 -packages = find: -install_requires = - precis-i18n>=1.0.0 - packaging - idna - -[options.extras_require] -gssapi = gssapi - -[options.packages.find] -exclude = - test* - -[options.package_data] -nbxmpp = py.typed
===================================== setup.py deleted ===================================== @@ -1,5 +0,0 @@ -#!/usr/bin/env python3 - -from setuptools import setup - -setup()
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/a394f955f57b3f118085e576...