Skip to content

Commit

Permalink
rfe: Migrate deprecated "python setup.py" to modern usage
Browse files Browse the repository at this point in the history
Migrate deprecated "setup.py install/develop" with "pip install", also
some "setup.py build" to "python -m build". For the custom clean target,
convert it to shell in the Makefile.

Also use the hatch cli as the entry to run formatter and linter.

Refs: https://packaging.python.org/en/latest/discussions/setup-py-deprecated
Signed-off-by: Yihuang Yu <[email protected]>
  • Loading branch information
PaulYuuu committed Jun 11, 2024
1 parent 5bf477b commit 46f9738
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fedora_35_task:
# Latest LTS release is 103.x
- AVOCADO_SRC: avocado-framework<104.0
matrix:
- SETUP: setup.py develop --user
- SETUP: -m pip install --user -e .
- SETUP: -m pip install .
- SETUP: -m pip install PYPI_UPLOAD/*.whl
matrix:
Expand All @@ -25,6 +25,7 @@ fedora_35_task:
- (echo $SETUP | grep -v PYPI_UPLOAD) || make pypi
setup_script: &setup_scr
- python3 --version
- python3 -m pip install --upgrade pip
- test -z $AVOCADO_SRC || python3 -m pip install $AVOCADO_SRC
- python3 $SETUP
bootstrap_script: &bootstrap_scr
Expand Down Expand Up @@ -61,7 +62,7 @@ avocado_devel_task:
# 103lts tree (from where new 103.x releases will come)
- AVOCADO_SRC: git+https://github.com/avocado-framework/avocado@103lts#egg=avocado_framework
matrix:
- SETUP: setup.py develop --user
- SETUP: -m pip install --user -e .
- SETUP: -m pip install .
- SETUP: -m pip install PYPI_UPLOAD/*.whl
matrix:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
working-directory: ./avocado-libs
run: |
python -m pip install --upgrade pip
pip install 'setuptools-rust==1.1.2'
pip install -e .
- name: Finish installing dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion CODING_STYLE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Base coding style

The coding style for all Python code is the one enforced by black (see
https://black.readthedocs.io/en/stable/the_black_code_style/). The
selftests/style.sh script can be used to verify the code style matches.
"hatch fmt -f" command can be used to verify the code style matches.


Variable names and UpPeR cAsE
Expand Down
33 changes: 16 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
ifndef PYTHON
PYTHON=$(shell which python3 2>/dev/null || which python2 2>/dev/null || which python 2>/dev/null)
PYTHON=$(shell which python3 2>/dev/null || which python 2>/dev/null)
endif
VERSION=$(shell $(PYTHON) setup.py --version 2>/dev/null)
PYTHON_DEVELOP_ARGS=$(shell if ($(PYTHON) setup.py develop --help 2>/dev/null | grep -q '\-\-user'); then echo "--user"; else echo ""; fi)
VERSION=$(shell $(PYTHON) -m hatchling version 2>/dev/null)
DESTDIR=/
AVOCADO_DIRNAME?=avocado

Expand All @@ -14,15 +13,17 @@ COMMIT_DATE=$(shell git log --pretty='format:%cd' --date='format:%Y%m%d' -n 1)
SHORT_COMMIT=$(shell git log --abbrev=8 --pretty=format:'%h' -n 1)
MOCK_CONFIG=default
ARCHIVE_BASE_NAME=avocado-vt
PKG_NAME=avocado-framework-plugin-vt
RPM_BASE_NAME=avocado-plugins-vt

CLEAN_LIST := MANIFEST BUILD BUILDROOT SPECS RPMS SRPMS SOURCES PYPI_UPLOAD build dist

all:
@echo
@echo "Development related targets:"
@echo "check: Runs tree static check, unittests and fast functional tests"
@echo "develop: Runs 'python setup.py --develop' on this tree alone"
@echo "link: Runs 'python setup.py --develop' in all subprojects and links the needed resources"
@echo "develop: Runs 'python -m pip install -e .' on this tree alone"
@echo "link: Runs 'python -m pip install -e .' in all subprojects and links the needed resources"
@echo "clean: Get rid of scratch, byte files and removes the links to other subprojects"
@echo "unlink: Disables egg links and unlinks needed resources"
@echo
Expand All @@ -42,25 +43,23 @@ all:

include Makefile.include

requirements: pip
- $(PYTHON) -m pip install -r requirements.txt

check:
./selftests/style.sh
./selftests/isort.sh
inspekt lint --disable W,R,C,E0203,E0601,E1002,E1101,E1102,E1103,E1120,F0401,I0011,E1003,W605,I1101 --exclude avocado-libs,scripts/github
pylint --errors-only --disable=all --enable=spelling --spelling-dict=en_US --spelling-private-dict-file=spell.ignore *
hatch fmt --check
inspekt lint --disable W,R,C,E0203,E0601,E1002,E1101,E1102,E1103,E1120,F0401,I0011,E1003,W605,I1101 --exclude scripts/github

clean:
$(PYTHON) setup.py clean
rm -rf $(CLEAN_LIST)
for pattern in "*.pyc" "__pycache__"; do \
find . -name "$$pattern" -exec rm -rf {} +; \
done

develop:
$(PYTHON) setup.py develop $(PYTHON_DEVELOP_ARGS)
$(PYTHON) -m pip install --user -e .

link: develop

unlink:
$(PYTHON) setup.py develop --uninstall $(PYTHON_DEVELOP_ARGS)
$(PYTHON) -m pip uninstall -y $(PKG_NAME)
# For compatibility reasons remove old symlinks
for NAME in $$(ls -1 avocado_vt/conf.d); do\
CONF="etc/avocado/conf.d/$$NAME";\
Expand All @@ -70,8 +69,8 @@ unlink:

pypi: clean
if test ! -d PYPI_UPLOAD; then mkdir PYPI_UPLOAD; fi
$(PYTHON) setup.py bdist_wheel -d PYPI_UPLOAD
$(PYTHON) setup.py sdist -d PYPI_UPLOAD
$(PYTHON) -m pip install build
$(PYTHON) -m build -o PYPI_UPLOAD
@echo
@echo "Please use the files on PYPI_UPLOAD dir to upload a new version to PyPI"
@echo "The URL to do that may be a bit tricky to find, so here it is:"
Expand Down
6 changes: 1 addition & 5 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ source-release: clean
git archive --prefix="$(ARCHIVE_BASE_NAME)-$(VERSION)/" -o "SOURCES/$(ARCHIVE_BASE_NAME)-$(VERSION).tar.gz" $(VERSION)

install:
if [ "$$($(PYTHON) --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)" == "2" ]; then \
$(PYTHON) setup.py install --root $(DESTDIR) $(COMPILE); \
else \
$(PYTHON) -m pip install --prefix $(DESTDIR) --upgrade .; \
fi
$(PYTHON) -m pip install --prefix $(DESTDIR) --upgrade .

srpm: source
if test ! -d BUILD/SRPM; then mkdir -p BUILD/SRPM; fi
Expand Down
4 changes: 2 additions & 2 deletions avocado-plugins-vt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Source0: https://github.com/avocado-framework/%{srcname}/archive/%{commit}.tar.g
# old way of retrieving snapshot sources
#Source0: https://github.com/avocado-framework/%{srcname}/archive/%{commit}/%{srcname}-%{version}-%{shortcommit}.tar.gz
%endif
BuildRequires: python3-devel, python3-setuptools, python3-six
BuildRequires: python3-devel, python3-six, python3-hatchling, python3-wheel
Requires: python3-six
BuildArch: noarch
Requires: autotest-framework, xz, tcpdump, iproute, iputils, gcc, glibc-headers, nc, git
Expand Down Expand Up @@ -88,7 +88,7 @@ Xunit output, among others.

%install
%{__mkdir} -p %{buildroot}%{_sysconfdir}/avocado/conf.d
%{__python3} setup.py install --root %{buildroot} --skip-build
%{__python3} -m pip install --prefix=%{buildroot} --no-build-isolation .
%{__mv} %{buildroot}%{python3_sitelib}/avocado_vt/conf.d/* %{buildroot}%{_sysconfdir}/avocado/conf.d

%files -n python3-%{name}
Expand Down
2 changes: 1 addition & 1 deletion contrib/packages/debian/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prepare-source:
# build the source package in the parent directory
# then rename it to project_version.orig.tar.gz
dch -D "bionic" -M -v "$(VERSION)" "Automated (make builddeb) build."
$(PYTHON) setup.py sdist $(COMPILE) --dist-dir=../ --prune
$(PYTHON) -m build --sdist --outdir=../
rename -f 's/$(PROJECT)-(.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*

deb-src: prepare-source
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing/Guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Rules for Maintainers
Rules for Contributors
======================

1. [Must] Coding style should conform to what's enforced by black (see ``selftests/style.sh``)
1. [Must] Coding style should conform to what's enforced by black and isort (see black configuration in ``pyproject.toml``)
2. [Must] PR commit message is meaningful. Refer to the link on how to write a good commit message
3. [Must] Travis CI pass and no conflict
4. [Must] Provide test results. If no, provide justification. Apply to any PR
Expand Down
1 change: 1 addition & 0 deletions requirements-travis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ netifaces==0.11.0
pyenchant==3.2.2
black==22.3.0
isort==5.10.1
hatch
3 changes: 0 additions & 3 deletions selftests/isort.sh

This file was deleted.

4 changes: 0 additions & 4 deletions selftests/style.sh

This file was deleted.

6 changes: 3 additions & 3 deletions virttest/utils_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def env_check(self):
if self.session.cmd_status(cmd, timeout=self.timeout) != 0:
LOG.error("Failed to restart libvirtd inside guest")
return False
pip_pack = ["setuptools", "netifaces", "aexpect"]
pip_pack = ["hatchling", "netifaces", "aexpect"]
cmd = ""
for each in pip_pack:
cmd = "%s install %s --upgrade" % (self.pip_bin, each)
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def install_avocado(self):
return False
for plugin in self.plugins[self.installtype]:
cmd = "cd %s;" % os.path.join(self.plugins_path, plugin)
cmd += "%s setup.py install" % self.python
cmd += "%s install ." % self.pip_bin
if self.session.cmd_status(cmd, timeout=self.timeout) != 0:
LOG.error("Avocado plugin %s git " "installation failed", plugin)
return False
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def git_install(self, repo_path, branch="", make="", install=True):
if make:
cmd += "make %s;" % make
if install:
cmd += "%s setup.py install" % self.python
cmd += "%s install ." % self.pip_bin
return self.session.cmd_status(cmd, timeout=self.timeout) == 0

def repo_name(self, repo_path):
Expand Down

0 comments on commit 46f9738

Please sign in to comment.