diff --git a/.codecov.yml b/.codecov.yml index 8380434a2a5..9be7955160d 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -158,6 +158,31 @@ coverage: # threshold: 20% + python3: + + # + # The python3 limit applies to: + # ----------------------------- + # + # - python3/** + # - excluding: **/test_*.py + # + paths: ["python3/**", "!**/test_*.py"] + + # + # For python3/** (excluding tests): + # + # For python3, coverage should not be reduced compared to its base: + # + target: auto + + # + # Exception: the threshold value given is allowed + # + # Allows for not covering 20% if the changed lines of the PR: + # + threshold: 20% + # Checks each Python version separately: python-3.11: flags: ["python3.11"] @@ -175,18 +200,26 @@ coverage: # Python modules and scripts below scripts/ (excluding tests) # scripts: + paths: ["scripts/**", "!**/test_*.py"] target: 48% threshold: 2% - paths: ["scripts/**", "!**/test_*.py"] # - # Python modules and scripts below ocaml/ + # Python modules and scripts below ocaml/ (excluding tests) # ocaml: paths: ["ocaml/**", "!**/test_*.py"] target: 51% threshold: 3% + # + # Python modules and scripts below python3/ (excluding tests) + # + python3: + paths: ["python3/**", "!**/test_*.py"] + target: 48% + threshold: 2% + # # Test files # @@ -239,6 +272,10 @@ component_management: - "ocaml/xapi-storage-script/**" - "!**/test_*.py" + - component_id: python3 + name: python3 + paths: ["python3/**", "!**/test_*.py"] + - component_id: test_cases name: test_cases paths: ["**/test_*.py"] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cadf84c35c4..7b660722b20 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,8 @@ jobs: - name: Install common dependencies for Python ${{matrix.python-version}} run: pip install future mock pytest-coverage pytest-mock - - name: Run Pytest and get code coverage for Codecov + - name: Run Pytest for python 2 and get code coverage for Codecov + if: ${{ matrix.python-version == '2.7' }} run: > pytest --cov=scripts --cov=ocaml/xcp-rrdd @@ -67,6 +68,18 @@ jobs: env: PYTHONDEVMODE: yes + - name: Run Pytest for python 3 and get code coverage for Codecov + if: ${{ matrix.python-version != '2.7' }} + run: > + pytest + --cov=scripts --cov=ocaml/xcp-rrdd --cov=python3/ + scripts/ ocaml/xcp-rrdd python3/ -vv -rA + --junitxml=.git/pytest${{matrix.python-version}}.xml + --cov-report term-missing + --cov-report xml:.git/coverage${{matrix.python-version}}.xml + env: + PYTHONDEVMODE: yes + - name: Upload Python ${{matrix.python-version}} coverage report to Codecov uses: codecov/codecov-action@v3 with: diff --git a/Makefile b/Makefile index bcfc5b9eb78..921e65923de 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,7 @@ install: build doc sdk doc-json mkdir -p $(DESTDIR)/etc/bash_completion.d # ocaml/xapi make -C scripts install + make -C python3 install cp -f _build/install/default/bin/xapi $(DESTDIR)$(OPTDIR)/bin/xapi scripts/install.sh 755 ocaml/quicktest/quicktest $(DESTDIR)$(OPTDIR)/debug cp -f _build/install/default/bin/quicktestbin $(DESTDIR)$(OPTDIR)/debug/quicktestbin diff --git a/pyproject.toml b/pyproject.toml index b65a36bb062..d05d028fbad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,6 +113,7 @@ inputs = [ "scripts/examples/python", "scripts/yum-plugins", "scripts/*.py", + "python3/packages/*.py", # To be added later, # when converted to Python3-compatible syntax: diff --git a/python3/Makefile b/python3/Makefile new file mode 100644 index 00000000000..480aee5dfeb --- /dev/null +++ b/python3/Makefile @@ -0,0 +1,9 @@ +include ../config.mk + +SITE3_DIR=$(shell python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") + +IDATA=install -m 644 + +install: + mkdir -p $(DESTDIR)$(SITE3_DIR) + $(IDATA) packages/observer.py $(DESTDIR)$(SITE3_DIR)/ diff --git a/python3/README.md b/python3/README.md new file mode 100644 index 00000000000..e2bf8dcc464 --- /dev/null +++ b/python3/README.md @@ -0,0 +1,12 @@ +# Python3 Scripts + +This directory is intended for scripts that only run on python3. As more scripts are +ported to python3 this directory should start to fill up. The intended structure of +the directory is as follows: + +- bin: This contains files to be installed in bin and are meant to be run by users +- libexec: This contains files to be installed in libexec and are meant to only be +run by xapi and other daemons. +- packages: This contains files to be installed in python's site-packages and are meant +to be modules and packages to be imported by other scripts or executed via python3 -m +- plugins: This contains files that are meant to be xapi plugins diff --git a/scripts/observer.py b/python3/packages/observer.py similarity index 93% rename from scripts/observer.py rename to python3/packages/observer.py index 96013361866..a2538304e19 100644 --- a/scripts/observer.py +++ b/python3/packages/observer.py @@ -1,5 +1,3 @@ -#!/usr/bin/python3 - if __name__ == '__main__': # run a program passed as parameter, with its original arguments import runpy diff --git a/scripts/Makefile b/scripts/Makefile index 8f07e91efe7..17c8e383fac 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -177,7 +177,6 @@ endif sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/' $(DESTDIR)$(SITE3_DIR)/XenAPIPlugin.py $(IDATA) examples/python/XenAPI/XenAPI.py $(DESTDIR)$(SITE3_DIR)/ $(IDATA) examples/python/inventory.py $(DESTDIR)$(SITE3_DIR)/ - $(IDATA) observer.py $(DESTDIR)$(SITE3_DIR)/ $(IPROG) examples/python/echo.py $(DESTDIR)$(PLUGINDIR)/echo $(IPROG) examples/python/shell.py $(DESTDIR)$(LIBEXECDIR)/shell.py # poweron