#421 Use generic Makefile provided by qa-make
Opened 4 years ago by frantisekz. Modified 4 years ago

file added
+133
@@ -0,0 +1,133 @@ 

+ # Copyright 2018, Red Hat, Inc.

+ # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+>

+ # See the LICENSE file for more details on Licensing

+ 

+ #######################################################################

+ #      _____            _        _ _           _   _                  #

+ #     / ____|          | |      (_) |         | | (_)                 #

+ #    | |     ___  _ __ | |_ _ __ _| |__  _   _| |_ _ _ __   __ _      #

+ #    | |    / _ \| '_ \| __| '__| | '_ \| | | | __| | '_ \ / _` |     #

+ #    | |___| (_) | | | | |_| |  | | |_) | |_| | |_| | | | | (_| |     #

+ #     \_____\___/|_| |_|\__|_|  |_|_.__/ \__,_|\__|_|_| |_|\__, |     #

+ #                                                           __/ |     #

+ #     If you want to add/fix anything here, please create  |___/      #

+ #     PR at qa-make https://pagure.io/fedora-qa/qa-make               #

+ #                                                                     #

+ #######################################################################

+ 

+ # Allows to print variables, eg. make print-SRC

+ print-%  : ; @echo $* = $($*)

+ 

+ # Get variables from Makefile.cfg

+ SRC=$(shell grep -s SRC Makefile.cfg | sed 's/SRC=//')

+ VENV=$(shell grep -s VENV Makefile.cfg | sed 's/VENV=//')

+ MODULENAME=$(shell grep -s MODULENAME Makefile.cfg | sed 's/MODULENAME=//')

+ 

+ # Try to detect SRC in case we didn't find Makefile.cfg

+ ifeq ($(SRC),)

+ SRC=$(shell rpmspec -q --queryformat="%{NAME}\n" *.spec | head -1)

+ SPECNUM=$(shell ls -1 *.spec | wc -l)

+ ifneq ($(SPECNUM),1)

+ $(error Make sure you have either one spec file in the directory or configure it in Makefile.cfg)

+ endif

+ endif

+ 

+ # Variables used for packaging

+ SPECFILE=$(SRC).spec

+ BASEARCH:=$(shell uname -i)

+ DIST:=$(shell rpm --eval '%{dist}')

+ TARGETVER:=$(shell lsb_release -r |grep -o '[0-9]*')

+ TARGETDIST:=fc$(TARGETVER)

+ VERSION:=$(shell rpmspec -q --queryformat="%{VERSION}\n" $(SPECFILE) | head -1)

+ RELEASE:=$(shell rpmspec -q --queryformat="%{RELEASE}\n" $(SPECFILE) | head -1 | sed 's/$(DIST)/\.$(TARGETDIST)/g')

+ NVR:=$(SRC)-$(VERSION)-$(RELEASE)

+ GITBRANCH:=$(shell git rev-parse --abbrev-ref HEAD)

+ BUILDTARGET:=fedora-$(TARGETVER)-x86_64

+ KOJITARGET:=$(shell echo $(TARGETDIST) | sed 's/c//' | sed 's/el/epel-/')

+ 

+ .PHONY: update-makefile

+ update-makefile:

+ 	curl --fail https://pagure.io/fedora-qa/qa-make/raw/master/f/Makefile -o Makefile.new

+ 	if ! cmp Makefile Makefile.new ; then mv Makefile.new Makefile ; fi

+ 

+ .PHONY: test

+ .ONESHELL: test

+ test: $(VENV)

+ 	set -e

+ 	source $(VENV)/bin/activate;

+ 	TEST='true' py.test --cov-report=term-missing --cov $(MODULENAME);

+ 	deactivate

+ 

+ .PHONY: test-ci

+ .ONESHELL: test-ci

+ test-ci: $(VENV)

+ 	set -e

+ 	source $(VENV)/bin/activate

+ 	TEST='true' py.test --cov-report=xml --cov $(MODULENAME)

+ 	deactivate

+ 

+ .PHONY: pylint

+ pylint:

+ 	pylint -f parseable $(SRC) | tee pylint.out

+ 

+ .PHONY: pep8

+ pep8:

+ 	pep8 $(SRC)/*.py $(SRC)/*/*.py | tee pep8.out

+ 

+ .PHONY: ci

+ ci: test-ci pylint pep8

+ 

+ .PHONY: docs

+ docs:

+ 	sphinx-build  -b html -d docs/_build/doctrees docs/source docs/_build/html

+ 

+ .PHONY: clean

+ clean:

+ 	rm -rf dist

+ 	rm -rf $(SRC).egg-info

+ 	rm -rf build

+ 	rm -f pep8.out

+ 	rm -f pylint.out

+ 

+ .PHONY: archive

+ archive: $(SRC)-$(VERSION).tar.gz

+ 

+ .PHONY: $(SRC)-$(VERSION).tar.gz

+ $(SRC)-$(VERSION).tar.gz:

+ 	git archive $(GITBRANCH) --prefix=$(SRC)-$(VERSION)/ | gzip -c9 > $@

+ 	mkdir -p build/$(VERSION)-$(RELEASE)

+ 	mv $(SRC)-$(VERSION).tar.gz build/$(VERSION)-$(RELEASE)/

+ 

+ .PHONY: srpm

+ srpm: archive

+ 	mock -r $(BUILDTARGET) --buildsrpm --spec $(SPECFILE) --sources build/$(VERSION)-$(RELEASE)/

+ 	cp /var/lib/mock/$(BUILDTARGET)/result/$(NVR).src.rpm build/$(VERSION)-$(RELEASE)/

+ 

+ .PHONY: build

+ build: srpm

+ 	mock -r $(BUILDTARGET) --no-clean --rebuild build/$(VERSION)-$(RELEASE)/$(NVR).src.rpm

+ 	cp /var/lib/mock/$(BUILDTARGET)/result/*.rpm build/$(VERSION)-$(RELEASE)/

+ 

+ .PHONY: scratch

+ scratch: srpm

+ 	koji build --scratch $(KOJITARGET) build/$(VERSION)-$(RELEASE)/$(NVR).src.rpm

+ 

+ .PHONY: nvr

+ nvr:

+ 	@echo $(NVR)

+ 

+ .PHONY: cleanvenv

+ cleanvenv:

+ 	rm -rf $(VENV)

+ 

+ .PHONY: virtualenv

+ virtualenv: $(VENV)

+ 

+ .PHONY: $(VENV)

+ .ONESHELL: $(VENV)

+ $(VENV):

+ 	virtualenv --system-site-packages $(VENV)

+ 	set -e

+ 	source $(VENV)/bin/activate

+ 	pip install -r requirements.txt

+ 	deactivate

file modified
+4 -1
@@ -12,13 +12,16 @@ 

  # serve to show the default.

  

  import sys, os

- from utils import build

  

  # If extensions (or modules to document with autodoc) are in another directory,

  # add these directories to sys.path here. If the directory is relative to the

  # documentation root, use os.path.abspath to make it absolute, like shown here.

  sys.path.insert(0, os.path.abspath('../../'))

  

+ # This needs to be imported after adding ../../ to the sys.path

+ # if we want to build docs without virtual_env

+ from utils import build

+ 

  # -- General configuration -----------------------------------------------------

  

  # Include __init__ method documentation

Everything looks like it's working just fine. I've added fix (separate commit) that allows to build docs without using virtual_env.

qa-make: https://pagure.io/fedora-qa/qa-make

I'll remove dodo after the review :)

$ make test
set -e
source /bin/activate;
TEST='true' py.test --cov-report=term-missing --cov ;
deactivate
/bin/sh: line 1: /bin/activate: No such file or directory
make: *** [Makefile:56: test] Error 1

Perhaps Makefile.cfg is missing?
Also, we want to run tox (as we do in dodo.py, not py.test).

For building docs, we used to call pushd docs && make html, now you call just sphinx-build. But that doesn't build directives (see docs/Makefile). Also, I believe this needs to run in virtualenv, otherwise you need to have all libtaskotron dependencies installed locally on your computer (sphinx imports all the modules).

I don't see any command to clean the docs.

It would be nice if the commands activating venv found first check if they're not already in an active venv (and that case just skipped it).

There are other smaller issues, like $(VENV) target hardcoding --system-site-packages (that should be project specific), or pep8 target hardcoding paths. But those are tiny details.

I'm not sure if we can really make a universal Makefile across all our projects, without making it really complex with everything configurable (and for that, heresy heresy, might be doit a better fit:)). Do you think you can fix the mentioned issues without making the universal Makefile overly complex?

Metadata