Skip to content

Commit

Permalink
Create a new python3 directory for python3-only scripts
Browse files Browse the repository at this point in the history
This is intended as the start of a new directory structure. Splitting
the python3-only scripts into a new directory gives a simple way to
exclude them from python2 tests and coverage.

Signed-off-by: Steven Woods <[email protected]>
  • Loading branch information
snwoods committed Feb 28, 2024
1 parent 7a0d3e4 commit 0a0d55d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
41 changes: 39 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
#
Expand Down Expand Up @@ -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"]
15 changes: 14 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions python3/Makefile
Original file line number Diff line number Diff line change
@@ -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)/
12 changes: 12 additions & 0 deletions python3/README.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions scripts/observer.py → python3/packages/observer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python3

if __name__ == '__main__':
# run a program passed as parameter, with its original arguments
import runpy
Expand Down
1 change: 0 additions & 1 deletion scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a0d55d

Please sign in to comment.