Make tox and Makefile more similar.

This does a few things with the end goal of making simplifying and
making consistent tox and 'make' methods of test or check.

Things here:
 * move python programs out of bin and into their own main.  Use
   entry_points to get scripts written for them.  One gain here is
   that we no longer have python programs that are not named .py.
   flake8 and friends would not check those programs by default.
 * install scripts in bin/ using the setup.py scripts and adjust
   snapcraft.yaml and debian packaging for that.
 * declare and use PYTHON in Makefile to avoid repeating 'python3'
 * declare and use CHECK_DIRS in Makefile for list of dirs to check.
 * no longer run 'flake8' from 'make check' by default.
 * remove the old tests/ directory.
This commit is contained in:
Scott Moser 2018-06-05 16:38:28 -04:00
parent bf807867c3
commit af94275618
15 changed files with 53 additions and 108 deletions

3
.flake8 Normal file
View File

@ -0,0 +1,3 @@
[flake8]
# gettext inserts _ into builtin path.
builtins = _

View File

@ -9,6 +9,9 @@ PROBERT_REPO=https://github.com/CanonicalLtd/probert
export PYTHONPATH
CWD := $(shell pwd)
CHECK_DIRS := console_conf/ subiquity/ subiquitycore/
PYTHON := python3
ifneq (,$(MACHINE))
MACHARGS=--machine=$(MACHINE)
endif
@ -21,10 +24,10 @@ install_deps:
sudo apt-get install -y python3-urwid python3-pyudev python3-nose python3-flake8 \
python3-yaml python3-coverage python3-dev pkg-config libnl-genl-3-dev \
libnl-route-3-dev python3-attr python3-distutils-extra python3-requests \
python3-requests-unixsocket pep8
python3-requests-unixsocket
i18n:
python3 setup.py build
$(PYTHON) setup.py build
dryrun: probert i18n
$(MAKE) ui-view DRYRUN="--dry-run --uefi"
@ -35,27 +38,25 @@ ui-view:
ui-view-serial:
(TERM=att4424 bin/$(PYTHONSRC)-tui $(DRYRUN) --serial)
lint: pep8 pyflakes3
lint: flake8
pep8:
@$(CWD)/scripts/run-pep8
pyflakes3:
@$(CWD)/scripts/run-pyflakes3
flake8:
@echo 'tox -e flake8' is preferred to 'make flake8'
$(PYTHON) -m flake8 $(CHECK_DIRS)
unit:
echo "Running unit tests..."
nosetests3 $(PYTHONSRC)/tests
$(PYTHON) -m nose $(CHECK_DIRS)
check: lint unit
check: unit
probert:
@if [ ! -d "$(PROBERTDIR)" ]; then \
git clone -q $(PROBERT_REPO) $(PROBERTDIR); \
(cd probert && python3 setup.py build_ext -i); \
(cd probert && $(PYTHON) setup.py build_ext -i); \
fi
clean:
./debian/rules clean
.PHONY: lint pyflakes3 pep8
.PHONY: flake8 lint

View File

@ -15,11 +15,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from console_conf.controllers.identity import write_login_details_standalone
from subiquitycore.log import setup_logger
setup_logger(dir='/var/log/console-conf')
sys.exit(write_login_details_standalone())
def main():
setup_logger(dir='/var/log/console-conf')
write_login_details_standalone()
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,5 +1,5 @@
bin/console-conf-tui usr/share/subiquity
bin/console-conf-wait usr/share/subiquity
bin/console-conf-wrapper usr/share/subiquity
bin/console-conf-write-login-details usr/share/subiquity
debian/tmp/usr/bin/console-conf-tui usr/share/subiquity
debian/tmp/usr/bin/console-conf-wait usr/share/subiquity
debian/tmp/usr/bin/console-conf-wrapper usr/share/subiquity
debian/tmp/usr/bin/console-conf-write-login-details usr/share/subiquity
usr/share/subiquity/console_conf

View File

@ -1,4 +1,5 @@
bin/subiquity-tui usr/share/subiquity
bin/subiquity-debug usr/share/subiquity
bin/subiquity-loadkeys usr/share/subiquity
debian/tmp/usr/bin/subiquity-debug usr/share/subiquity
debian/tmp/usr/bin/subiquity-loadkeys usr/share/subiquity
debian/tmp/usr/bin/subiquity-tui usr/share/subiquity
debian/tmp/usr/bin/subiquity-service usr/share/subiquity
usr/share/subiquity/subiquity

View File

@ -1,2 +1,2 @@
usr/share/subiquity/subiquitycore
usr/share/locale
usr/share/subiquity/subiquitycore

View File

@ -1,32 +0,0 @@
#!/bin/bash
# This file is part of subiquity. See LICENSE file for copyright and license info.
pycheck_dirs=(
"console_conf/"
"subiquity/"
"subiquitycore/"
"tests/"
)
bin_files=(
"bin/console-conf-tui"
"bin/subiquity-tui"
)
CR="
"
[ "$1" = "-v" ] && { verbose="$1"; shift; } || verbose=""
set -f
if [ $# -eq 0 ]; then unset IFS
IFS="$CR"
files=( "${bin_files[@]}" "${pycheck_dirs[@]}" )
unset IFS
else
files=( "$@" )
fi
myname=${0##*/}
cmd=( "${myname#run-}" $verbose "${files[@]}" )
echo "Running: " "${cmd[@]}" 1>&2
exec "${cmd[@]}"
# vi: ts=4 expandtab syntax=sh

View File

@ -1,34 +0,0 @@
#!/bin/bash
# This file is part of curtin. See LICENSE file for copyright and license info.
pycheck_dirs=(
"console_conf/"
"subiquity/"
"subiquitycore/"
"tests/"
)
bin_files=(
"bin/console-conf-tui"
"bin/subiquity-tui"
)
CR="
"
[ "$1" = "-v" ] && { verbose="$1"; shift; } || verbose=""
set -f
if [ $# -eq 0 ]; then unset IFS
IFS="$CR"
files=( "${bin_files[@]}" "${pycheck_dirs[@]}" )
unset IFS
else
files=( "$@" )
fi
cmd=( "python3" -m "pyflakes" "${files[@]}" )
echo "Running: " "${cmd[@]}" 1>&2
export PYFLAKES_BUILTINS="_"
exec "${cmd[@]}"
# vi: ts=4 expandtab syntax=sh

View File

@ -1,4 +1,4 @@
#!/bin/bash
python3 -m unittest discover
# The --foreground is important to avoid subiquity getting SIGTTOU-ed.
timeout --foreground 60 sh -c 'LANG=C.UTF-8 PYTHONPATH=. python3 bin/subiquity-tui --answers examples/answers.yaml --dry-run --machine-config examples/mwhudson.json'
timeout --foreground 60 sh -c 'LANG=C.UTF-8 PYTHONPATH=. python3 -m subiquity.cmd.tui --answers examples/answers.yaml --dry-run --machine-config examples/mwhudson.json'

View File

@ -36,7 +36,8 @@ if sys.argv[1] in ("build", "install"):
'build_i18n': build_i18n.build_i18n}
with open(os.path.join(os.path.dirname(__file__), 'subiquitycore', '__init__.py')) as init:
with open(os.path.join(os.path.dirname(__file__),
'subiquitycore', '__init__.py')) as init:
lines = [line for line in init if 'i18n' not in line]
ns = {}
exec('\n'.join(lines), ns)
@ -56,5 +57,20 @@ setup(name='subiquity',
url='https://github.com/CanonicalLtd/subiquity',
license="AGPLv3+",
packages=find_packages(exclude=["tests"]),
scripts=[
'bin/console-conf-wait',
'bin/console-conf-wrapper',
'bin/subiquity-debug',
'bin/subiquity-loadkeys',
'bin/subiquity-service',
],
entry_points={
'console_scripts': [
'subiquity-tui = subiquity.cmd.tui:main',
'console-conf-tui = console_conf.cmd.tui:main',
('console-conf-write-login-details = '
'console_conf.cmd.write_login_details:main'),
],
},
data_files=[],
**setup_kwargs)

View File

@ -43,21 +43,12 @@ parts:
#- urwid
source: .
source-type: git
wrappers:
plugin: dump
source: .
source-type: git
organize:
'bin/console-conf-tui': usr/bin/console-conf
'bin/subiquity-tui': usr/bin/subiquity
'bin/subiquity-loadkeys': usr/bin/subiquity-loadkeys
'bin/curtin-journald-forwarder': usr/bin/curtin-journald-forwarder
'bin/subiquity-service': usr/bin/subiquity-service
stage-packages: [libc6]
stage:
- usr/bin
prime:
- usr/bin
users-and-groups:
plugin: dump
build-packages:

View File

10
tox.ini
View File

@ -26,14 +26,14 @@ deps =
pyflakes==1.6.0
commands = {envpython} -m flake8 \
{posargs:subiquity/ subiquitycore/ console_conf/ bin/}
{posargs:console_conf/ subiquity/ subiquitycore/}
[testenv:py3]
deps =
{[testenv]deps}
nose
commands = {envpython} -m nose \
{posargs:subiquity/ subiquitycore/ console_conf/ bin/}
{posargs:console_conf/ subiquity/ subiquitycore/}
[testenv:coverage]
deps = {[testenv:py3]deps}
@ -43,8 +43,4 @@ commands = {envpython} -m nose \
--with-timer --timer-top-n 10 \
--with-coverage --cover-erase --cover-branches --cover-inclusive \
--cover-package=subiquity --cover-package=subiquitycore \
{posargs:subiquity/ subiquitycore/ console_conf/ bin/}
[flake8]
# gettext inserts _ into builtin path.
builtins = _
{posargs:console_conf subiquity/ subiquitycore/}