Some more improvements.
This commit is contained in:
parent
21ed7c4a7d
commit
3c884f2c51
3 changed files with 96 additions and 61 deletions
|
@ -37,6 +37,9 @@ def main():
|
||||||
default='.')
|
default='.')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--schroot', type=str, help='schroot to run in.')
|
'--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()
|
args = parser.parse_args()
|
||||||
if args.schroot:
|
if args.schroot:
|
||||||
from .session.schroot import SchrootSession
|
from .session.schroot import SchrootSession
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from . import shebang_binary
|
||||||
from .apt import AptManager
|
from .apt import AptManager
|
||||||
from .fix_build import run_with_build_fixer
|
from .fix_build import run_with_build_fixer
|
||||||
|
|
||||||
|
@ -78,8 +79,97 @@ class Pear(BuildSystem):
|
||||||
run_with_build_fixer(self.session, ['pear', 'install'])
|
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):
|
def detect_buildsystems(session):
|
||||||
"""Detect build systems."""
|
"""Detect build systems."""
|
||||||
if os.path.exists('package.xml'):
|
if os.path.exists('package.xml'):
|
||||||
logging.info('Found package.xml, assuming pear package.')
|
logging.info('Found package.xml, assuming pear package.')
|
||||||
yield Pear(session)
|
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)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import Optional, List, Tuple, Callable, Type
|
from typing import Optional, List, Tuple
|
||||||
|
|
||||||
from debian.deb822 import Deb822
|
from debian.deb822 import Deb822
|
||||||
|
|
||||||
|
@ -39,9 +39,8 @@ from . import DetailedFailure, shebang_binary
|
||||||
from .apt import AptManager, UnidentifiedError
|
from .apt import AptManager, UnidentifiedError
|
||||||
from .fix_build import run_with_build_fixer
|
from .fix_build import run_with_build_fixer
|
||||||
from .buildsystem import detect_buildsystems, NoBuildToolsFound
|
from .buildsystem import detect_buildsystems, NoBuildToolsFound
|
||||||
from .session import run_with_tee, Session
|
from .session import Session
|
||||||
from .session.schroot import SchrootSession
|
from .session.schroot import SchrootSession
|
||||||
from .debian.fix_build import DependencyContext
|
|
||||||
from .vcs import dupe_vcs_tree, export_vcs_tree
|
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(','))
|
deps.append(source[name].strip().strip(','))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
for name in ['Build-Conflicts', 'Build-Conflicts-Indeo',
|
for name in ['Build-Conflicts', 'Build-Conflicts-Indep',
|
||||||
'Build-Conflicts-Arch']:
|
'Build-Conflicts-Arch']:
|
||||||
try:
|
try:
|
||||||
deps.append('Conflicts: ' + source[name])
|
deps.append('Conflicts: ' + source[name])
|
||||||
|
@ -83,63 +82,6 @@ def run_dist(session):
|
||||||
buildsystem.dist()
|
buildsystem.dist()
|
||||||
return
|
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'):
|
if os.path.exists('setup.cfg'):
|
||||||
logging.info('Found setup.cfg, assuming python project.')
|
logging.info('Found setup.cfg, assuming python project.')
|
||||||
apt.install(['python3-pep517', 'python3-pip'])
|
apt.install(['python3-pep517', 'python3-pip'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue