From 3c884f2c51d5d2f35f756193c1c8c65e3f1cd482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 7 Feb 2021 22:08:29 +0000 Subject: [PATCH] Some more improvements. --- ognibuild/__main__.py | 3 ++ ognibuild/buildsystem.py | 90 ++++++++++++++++++++++++++++++++++++++++ ognibuild/dist.py | 64 ++-------------------------- 3 files changed, 96 insertions(+), 61 deletions(-) diff --git a/ognibuild/__main__.py b/ognibuild/__main__.py index aef0c6f..32a1739 100644 --- a/ognibuild/__main__.py +++ b/ognibuild/__main__.py @@ -37,6 +37,9 @@ def main(): default='.') parser.add_argument( '--schroot', type=str, help='schroot to run in.') + parser.add_argument( + '--resolve', choices=['explain', 'apt', 'native'], + help='What to do about missing dependencies') args = parser.parse_args() if args.schroot: from .session.schroot import SchrootSession diff --git a/ognibuild/buildsystem.py b/ognibuild/buildsystem.py index 9ce72be..31e8b41 100644 --- a/ognibuild/buildsystem.py +++ b/ognibuild/buildsystem.py @@ -20,6 +20,7 @@ import logging import os +from . import shebang_binary from .apt import AptManager from .fix_build import run_with_build_fixer @@ -78,8 +79,97 @@ class Pear(BuildSystem): run_with_build_fixer(self.session, ['pear', 'install']) +class SetupPy(BuildSystem): + + def prereqs(self): + apt = AptManager(self.session) + apt.install(['python3', 'python3-pip']) + with open('setup.py', 'r') as f: + setup_py_contents = f.read() + try: + with open('setup.cfg', 'r') as f: + setup_cfg_contents = f.read() + except FileNotFoundError: + setup_cfg_contents = '' + if 'setuptools' in setup_py_contents: + logging.info('Reference to setuptools found, installing.') + apt.install(['python3-setuptools']) + if ('setuptools_scm' in setup_py_contents or + 'setuptools_scm' in setup_cfg_contents): + logging.info('Reference to setuptools-scm found, installing.') + apt.install(['python3-setuptools-scm', 'git', 'mercurial']) + + # TODO(jelmer): Install setup_requires + + def test(self): + self.prereqs() + self._run_setup(['test']) + + def dist(self): + self.prereqs() + self._run_setup(['sdist']) + + def clean(self): + self.prereqs() + self._run_setup(['clean']) + + def install(self): + self.prereqs() + self._run_setup(['install']) + + def _run_setup(self, args): + apt = AptManager(self.session) + interpreter = shebang_binary('setup.py') + if interpreter is not None: + if interpreter == 'python3': + apt.install(['python3']) + elif interpreter == 'python2': + apt.install(['python2']) + elif interpreter == 'python': + apt.install(['python']) + else: + raise ValueError('Unknown interpreter %r' % interpreter) + apt.install(['python2', 'python3']) + run_with_build_fixer( + self.session, ['./setup.py'] + args) + else: + # Just assume it's Python 3 + apt.install(['python3']) + run_with_build_fixer( + self.session, ['python3', './setup.py'] + args) + + +class PyProject(BuildSystem): + + def load_toml(self): + import toml + with open('pyproject.toml', 'r') as pf: + return toml.load(pf) + + def dist(self): + apt = AptManager(self.session) + pyproject = self.load_toml() + if 'poetry' in pyproject.get('tool', []): + logging.info( + 'Found pyproject.toml with poetry section, ' + 'assuming poetry project.') + apt.install(['python3-venv', 'python3-pip']) + self.session.check_call(['pip3', 'install', 'poetry'], user='root') + self.session.check_call(['poetry', 'build', '-f', 'sdist']) + return + raise AssertionError('no supported section in pyproject.toml') + + def detect_buildsystems(session): """Detect build systems.""" if os.path.exists('package.xml'): logging.info('Found package.xml, assuming pear package.') yield Pear(session) + + if os.path.exists('setup.py'): + logging.info('Found setup.py, assuming python project.') + yield SetupPy(session) + + if os.path.exists('pyproject.toml'): + logging.info('Found pyproject.toml, assuming python project.') + yield PyProject(session) diff --git a/ognibuild/dist.py b/ognibuild/dist.py index 0000eee..dcab9b1 100644 --- a/ognibuild/dist.py +++ b/ognibuild/dist.py @@ -22,7 +22,7 @@ import re import shutil import sys import tempfile -from typing import Optional, List, Tuple, Callable, Type +from typing import Optional, List, Tuple from debian.deb822 import Deb822 @@ -39,9 +39,8 @@ from . import DetailedFailure, shebang_binary from .apt import AptManager, UnidentifiedError from .fix_build import run_with_build_fixer from .buildsystem import detect_buildsystems, NoBuildToolsFound -from .session import run_with_tee, Session +from .session import Session from .session.schroot import SchrootSession -from .debian.fix_build import DependencyContext from .vcs import dupe_vcs_tree, export_vcs_tree @@ -58,7 +57,7 @@ def satisfy_build_deps(session: Session, tree): deps.append(source[name].strip().strip(',')) except KeyError: pass - for name in ['Build-Conflicts', 'Build-Conflicts-Indeo', + for name in ['Build-Conflicts', 'Build-Conflicts-Indep', 'Build-Conflicts-Arch']: try: deps.append('Conflicts: ' + source[name]) @@ -83,63 +82,6 @@ def run_dist(session): buildsystem.dist() return - if os.path.exists('package.xml'): - apt.install(['php-pear', 'php-horde-core']) - logging.info('Found package.xml, assuming pear package.') - session.check_call(['pear', 'package']) - return - - if os.path.exists('pyproject.toml'): - import toml - with open('pyproject.toml', 'r') as pf: - pyproject = toml.load(pf) - if 'poetry' in pyproject.get('tool', []): - logging.info( - 'Found pyproject.toml with poetry section, ' - 'assuming poetry project.') - apt.install(['python3-venv', 'python3-pip']) - session.check_call(['pip3', 'install', 'poetry'], user='root') - session.check_call(['poetry', 'build', '-f', 'sdist']) - return - - if os.path.exists('setup.py'): - logging.info('Found setup.py, assuming python project.') - apt.install(['python3', 'python3-pip']) - with open('setup.py', 'r') as f: - setup_py_contents = f.read() - try: - with open('setup.cfg', 'r') as f: - setup_cfg_contents = f.read() - except FileNotFoundError: - setup_cfg_contents = '' - if 'setuptools' in setup_py_contents: - logging.info('Reference to setuptools found, installing.') - apt.install(['python3-setuptools']) - if ('setuptools_scm' in setup_py_contents or - 'setuptools_scm' in setup_cfg_contents): - logging.info('Reference to setuptools-scm found, installing.') - apt.install(['python3-setuptools-scm', 'git', 'mercurial']) - - # TODO(jelmer): Install setup_requires - - interpreter = shebang_binary('setup.py') - if interpreter is not None: - if interpreter == 'python3': - apt.install(['python3']) - elif interpreter == 'python2': - apt.install(['python2']) - elif interpreter == 'python': - apt.install(['python']) - else: - raise ValueError('Unknown interpreter %r' % interpreter) - apt.install(['python2', 'python3']) - run_with_build_fixer(session, ['./setup.py', 'sdist']) - else: - # Just assume it's Python 3 - apt.install(['python3']) - run_with_build_fixer(session, ['python3', './setup.py', 'sdist']) - return - if os.path.exists('setup.cfg'): logging.info('Found setup.cfg, assuming python project.') apt.install(['python3-pep517', 'python3-pip'])