From 8d4c91be13c1af02c940bc7761546bf01a87c1fe Mon Sep 17 00:00:00 2001 From: Ana Guerrero Lopez Date: Wed, 18 Aug 2021 10:23:10 +0200 Subject: [PATCH] setup.py: add custom command clean and fix default target Remove steps from the Makefile that are already made by the custom clean command. Move the include line below, otherwise 'make' will run the clean target by default. Signed-off-by: Ana Guerrero Lopez --- Makefile | 5 ++--- setup.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7cc7f8fcd4..cc7d486be3 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,6 @@ MOCK_CONFIG=default ARCHIVE_BASE_NAME=avocado-vt RPM_BASE_NAME=avocado-plugins-vt -include Makefile.include all: @echo @@ -41,6 +40,8 @@ all: @echo "rpm-release: Generate binary RPMs for the latest tagged release" @echo +include Makefile.include + requirements: pip - $(PYTHON) -m pip install "pip>=6.0.1" - $(PYTHON) -m pip install -r requirements.txt @@ -50,8 +51,6 @@ check: clean: $(PYTHON) setup.py clean - rm -rf build/ MANIFEST BUILD BUILDROOT SPECS RPMS SRPMS SOURCES PYPI_UPLOAD - find . -name '*.pyc' -delete develop: $(PYTHON) setup.py develop $(PYTHON_DEVELOP_ARGS) diff --git a/setup.py b/setup.py index 184f85de86..adadd87f08 100644 --- a/setup.py +++ b/setup.py @@ -13,11 +13,37 @@ # Author: Lucas Meneghel Rodrigues # pylint: disable=E0611 +import os +import shutil +from distutils.command.clean import clean +from pathlib import Path from setuptools import setup, find_packages VERSION = open('VERSION', 'r').read().strip() +class Clean(clean): + """Our custom command to get rid of scratch files after build.""" + + description = "Get rid of scratch, byte files and build stuff." + + def run(self): + super().run() + cleaning_list = ["MANIFEST", "BUILD", "BUILDROOT", "SPECS", + "RPMS", "SRPMS", "SOURCES", "PYPI_UPLOAD", "./build"] + + cleaning_list += list(Path('.').rglob("*.pyc")) + cleaning_list += list(Path('.').rglob("__pycache__")) + + for e in cleaning_list: + if not os.path.exists(e): + continue + if os.path.isfile(e): + os.remove(e) + if os.path.isdir(e): + shutil.rmtree(e) + + def pre_post_plugin_type(): try: from avocado.core.plugin_interfaces import JobPreTests as Pre @@ -68,5 +94,6 @@ def pre_post_plugin_type(): ], }, install_requires=["netifaces", "simplejson", "six", "netaddr", - "aexpect", "avocado-framework>=68.0"] + "aexpect", "avocado-framework>=68.0"], + cmdclass={'clean': Clean}, )