Skip to content

Commit 59664cc

Browse files
authored
Merge pull request #5896 from xapi-project/feature/py3
Python3 update feature merge
2 parents b1fbddc + 09603bd commit 59664cc

File tree

173 files changed

+5293
-8439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+5293
-8439
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
- name: Make install smoketest
4646
run: |
4747
opam exec -- make install DESTDIR=$(mktemp -d)
48-
opam exec -- make install DESTDIR=$(mktemp -d) BUILD_PY2=NO
4948
5049
- name: Check disk space
5150
run: df -h || true

.github/workflows/other.yml

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
python-version: ["2.7", "3.11"]
21+
python-version: ["3.11"]
2222
steps:
2323
- name: Checkout code
2424
uses: actions/checkout@v4
@@ -39,48 +39,11 @@ jobs:
3939

4040
- uses: pre-commit/[email protected]
4141
name: Run pre-commit checks (no spaces at end of lines, etc)
42-
if: ${{ matrix.python-version != '2.7' }}
4342
with:
4443
extra_args: --all-files --verbose --hook-stage commit
4544
env:
4645
SKIP: no-commit-to-branch
4746

48-
- name: Install dependencies only needed for python 2
49-
if: ${{ matrix.python-version == '2.7' }}
50-
run: pip install enum
51-
52-
- name: Install dependencies only needed for python 3
53-
if: ${{ matrix.python-version != '2.7' }}
54-
run: pip install opentelemetry-api opentelemetry-exporter-zipkin-json opentelemetry-sdk pandas pytype toml wrapt
55-
56-
- name: Install common dependencies for Python ${{matrix.python-version}}
57-
run: pip install future mock pytest-coverage pytest-mock
58-
59-
- name: Run Pytest for python 2 and get code coverage
60-
if: ${{ matrix.python-version == '2.7' }}
61-
run: >
62-
pytest
63-
--cov=scripts --cov=ocaml/xcp-rrdd
64-
scripts/ ocaml/xcp-rrdd -vv -rA
65-
--junitxml=.git/pytest${{matrix.python-version}}.xml
66-
--cov-report term-missing
67-
--cov-report xml:.git/coverage${{matrix.python-version}}.xml
68-
env:
69-
PYTHONDEVMODE: yes
70-
71-
- name: Run Pytest for python 3 and get code coverage
72-
if: ${{ matrix.python-version != '2.7' }}
73-
run: >
74-
pytest
75-
--cov=scripts --cov=ocaml/xcp-rrdd --cov=python3/
76-
scripts/ ocaml/xcp-rrdd python3/ -vv -rA
77-
--junitxml=.git/pytest${{matrix.python-version}}.xml
78-
--cov-report term-missing
79-
--cov-report xml:.git/coverage${{matrix.python-version}}.xml
80-
env:
81-
PYTHONDEVMODE: yes
82-
PYTHONPATH: "python3:python3/tests/stubs"
83-
8447
- name: Upload coverage report to Coveralls
8548
uses: coverallsapp/github-action@v2
8649
with:
@@ -90,7 +53,6 @@ jobs:
9053
parallel: true
9154

9255
- uses: dciborow/[email protected]
93-
if: ${{ matrix.python-version != '2.7' }}
9456
with:
9557
reporter: github-pr-review
9658
level: warning
@@ -99,8 +61,7 @@ jobs:
9961
continue-on-error: true
10062

10163
- name: Run pytype checks
102-
if: ${{ matrix.python-version != '2.7' }}
103-
run: ./pytype_reporter.py
64+
run: pip install pandas pytype toml && ./pytype_reporter.py
10465
env:
10566
PR_NUMBER: ${{ github.event.number }}
10667
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/upload-artifact@v4
3434
with:
3535
name: XenAPI
36-
path: scripts/examples/python/dist/
36+
path: python3/examples/dist/
3737

3838
build-sdks:
3939
name: Build and upload SDK artifacts

.github/workflows/setup-xapi-environment/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ runs:
2828
shell: bash
2929
run: sudo apt-get update
3030

31-
- name: Install python2
31+
- name: Install python3
3232
shell: bash
33-
run: sudo apt-get install python2
33+
run: sudo apt-get install python3
3434

3535
- name: Use disk with more space for TMPDIR and XDG_CACHE_HOME
3636
shell: bash

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ config.mk
1616
# python packaging
1717
**/__pycache__/
1818
**/*.pyc
19-
scripts/examples/python/setup.py
20-
scripts/examples/python/XenAPI.egg-info/
21-
scripts/examples/python/build/
22-
scripts/examples/python/dist/
19+
python3/examples/setup.py
20+
python3/examples/XenAPI.egg-info/
21+
python3/examples/build/
22+
python3/examples/dist/
2323

2424
# ignore file needed for building the SDK
2525
ocaml/sdk-gen/csharp/XE_SR_ERRORCODES.xml

.pre-commit-config.yaml

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# pre-commit run -av --hook-stage pre-push
1515
#
1616
default_stages: [commit, push]
17+
default_language_version:
18+
python: python3.11
1719
repos:
1820
# Recommendation for a minimal git pre-commit hook:
1921
# https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md:
@@ -29,6 +31,95 @@ repos:
2931
- id: check-executables-have-shebangs
3032
exclude: ocaml
3133

34+
35+
# Improve Python formatting incrementally:
36+
# https://dev.to/akaihola/improving-python-code-incrementally-3f7a
37+
#
38+
# darker checks if staged python changes are formatted according using
39+
# the PEP8-aligned black formatter. It also checks if the imports are sorted.
40+
#
41+
# It is a good idea to run this before committing, and it is also run in the
42+
# GitHub Workflow.
43+
#
44+
# Note: darker only checks the changes in files ending in .py!
45+
# Python scripts that don't end in .py should be renamed to have the .py extension
46+
# when moving them to python3/bin.
47+
# (remove the .py extension in the Makefile when installing the file)
48+
#
49+
- repo: https://github.com/akaihola/darker
50+
rev: 1.7.3
51+
hooks:
52+
- id: darker
53+
files: python3/
54+
name: check changes in Python3 tree using darker and isort
55+
args: [--diff, --skip-string-normalization, --isort, -tpy36]
56+
additional_dependencies: [isort]
57+
58+
#
59+
# Run pytest and diff-cover to check that the new /python3 test suite in passes.
60+
# This hook uses a local venv containing the required dependencies. When adding
61+
# new dependencies, they should be added to the additional_dependencies below.
62+
#
63+
- repo: local
64+
hooks:
65+
- id: pytest
66+
files: python3/
67+
name: check that the Python3 test suite in passes
68+
entry: env PYTHONDEVMODE=yes sh -c 'coverage run && coverage xml &&
69+
coverage html && coverage report &&
70+
diff-cover --ignore-whitespace --compare-branch=origin/feature/py3
71+
--show-uncovered --html-report .git/coverage-diff.html
72+
--fail-under 50 .git/coverage3.11.xml'
73+
require_serial: true
74+
pass_filenames: false
75+
language: python
76+
types: [python]
77+
additional_dependencies:
78+
- coverage
79+
- diff-cover
80+
- future
81+
- opentelemetry-api
82+
- opentelemetry-exporter-zipkin-json
83+
- opentelemetry-sdk
84+
- pytest-mock
85+
- mock
86+
- wrapt
87+
- XenAPI
88+
89+
90+
- repo: https://github.com/RobertCraigie/pyright-python
91+
rev: v1.1.372
92+
hooks:
93+
- id: pyright
94+
name: check that python3 tree passes pyright/VSCode check
95+
files: python3/
96+
additional_dependencies:
97+
- mock
98+
- opentelemetry-api
99+
- opentelemetry-exporter-zipkin-json
100+
- opentelemetry-sdk
101+
- pytest
102+
- pyudev
103+
- XenAPI
104+
105+
106+
# Check that pylint passes for the changes in new /python3 code.
107+
- repo: local
108+
hooks:
109+
- id: pylint
110+
files: python3/
111+
stages: [push]
112+
name: check that changes to python3 tree pass pylint
113+
entry: diff-quality --violations=pylint
114+
--ignore-whitespace --compare-branch=origin/feature/py3
115+
pass_filenames: false
116+
language: python
117+
types: [python]
118+
additional_dependencies: [diff-cover, pylint, pytest]
119+
120+
121+
# pre-push hook (it only runs if you install pre-commit as a pre-push hook):
122+
# It can be manually tested using: `pre-commit run -av --hook-stage push`
32123
# Recommendation for a minimal git pre-push hook:
33124
# While using pre-commit yields great results, it
34125
# is "not fast". Therefore only run it pre-push,
@@ -53,4 +144,12 @@ repos:
53144
# developers have such version installed, it can be configured here:
54145
# language_version: python3.11
55146
require_serial: true
56-
additional_dependencies: [pandas, pytype]
147+
additional_dependencies:
148+
- future
149+
- opentelemetry-api
150+
- opentelemetry-exporter-zipkin-json
151+
- opentelemetry-sdk
152+
- pandas
153+
- pytest
154+
- pytype
155+
files: python3/

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ test:
6868
trap "kill $${PSTREE_SLEEP_PID}" INT TERM EXIT; \
6969
timeout --foreground $(TEST_TIMEOUT2) \
7070
dune runtest --profile=$(PROFILE) --error-reporting=twice -j $(JOBS)
71-
ifneq ($(PY_TEST), NO)
7271
dune build @runtest-python --profile=$(PROFILE)
73-
endif
7472

7573
stresstest:
7674
dune build @stresstest --profile=$(PROFILE) --no-buffer -j $(JOBS)
@@ -123,7 +121,7 @@ sdk:
123121
cp -r _build/default/ocaml/sdk-gen/java/autogen/* $(XAPISDK)/java
124122
cp -r _build/default/ocaml/sdk-gen/powershell/autogen/* $(XAPISDK)/powershell
125123
cp -r _build/default/ocaml/sdk-gen/go/autogen/* $(XAPISDK)/go
126-
cp scripts/examples/python/XenAPI/XenAPI.py $(XAPISDK)/python
124+
cp python3/examples/XenAPI/XenAPI.py $(XAPISDK)/python
127125
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/csharp
128126
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/powershell
129127

@@ -138,7 +136,7 @@ sdk-build-java: sdk
138136
cd _build/install/default/xapi/sdk/java && mvn -f xen-api/pom.xml -B clean package install -Drevision=0.0
139137

140138
python:
141-
$(MAKE) -C scripts/examples/python build
139+
$(MAKE) -C python3/examples build
142140

143141
doc-json:
144142
dune exec --profile=$(PROFILE) -- ocaml/idl/json_backend/gen_json.exe -destdir $(XAPIDOC)/jekyll
@@ -239,7 +237,6 @@ install: build doc sdk doc-json
239237
install -D ./ocaml/xenopsd/scripts/block $(DESTDIR)/$(XENOPSD_LIBEXECDIR)/block
240238
install -D ./ocaml/xenopsd/scripts/xen-backend.rules $(DESTDIR)/$(ETCDIR)/udev/rules.d/xen-backend.rules
241239
install -D ./ocaml/xenopsd/scripts/tap $(DESTDIR)/$(XENOPSD_LIBEXECDIR)/tap
242-
install -D ./ocaml/xenopsd/scripts/qemu-vif-script $(DESTDIR)/$(XENOPSD_LIBEXECDIR)/qemu-vif-script
243240
install -D ./ocaml/xenopsd/scripts/setup-vif-rules $(DESTDIR)/$(XENOPSD_LIBEXECDIR)/setup-vif-rules
244241
install -D ./_build/install/default/bin/pvs-proxy-ovs-setup $(DESTDIR)/$(XENOPSD_LIBEXECDIR)/pvs-proxy-ovs-setup
245242
(cd $(DESTDIR)/$(XENOPSD_LIBEXECDIR) && ln -s pvs-proxy-ovs-setup setup-pvs-proxy-rules)

0 commit comments

Comments
 (0)