-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
511: Code refactoring r=MatthieuDartiailh a=MatthieuDartiailh This is a HUGE pull request. That was not my intention at first but everything ended up this way and there is no clean way to sub divide it. Here is a list of what this PR addresses: - Code quality changes: - use black to format the whole codebase (the initial change is in a single commit allowing to filter it if necessary) - use isort to format imports - use flake8 to lint the code - add type annotations and use mypy to type check the code - configure CIs to validate that all the above is done consistently - add pre-config to ease the use of those tools for developer - use Numpy style doctrsing for all docstrings - Usability changes: - declare VISA attributes on resources rather than magically monkeypatch, should greatly improve the discoverability of those (in particular for serial resources this is important) - use more enums to clarify valid inputs for a number of low level functions - introduce event classes to wrap event. This provides a nicer interface to access events attributes - BREAKING CHANGE: wrap handlers to avoid passing raw ctypes values back (except for user_handle where this cannot be avoided). This is on by default but can be disabled using an environment variable or a global variable. - provide a `wrap_handler` method on resources allowing to get directly a resource and event object rather than low-level VISA object. - document the way to use events in pyvisa using either the queue mechanism or the handler mechanism. This is a very large change set but given the number of static analysis tools now running and the fact that when run using the Keysight testing tools the coverage now reaches 93% we should avoid breakages. However I would be happy to see people testing this before I merge. Pinging @hognala, @KOLANICH, @hgrecco @jenshnielsen I know that QCoDeS uses mypy and I would be happy to know if this helps or if I got part of the typing wrong. Co-authored-by: MatthieuDartiailh <marul@laposte.net> Co-authored-by: mdartiailh <m.dartiailh@gmail.com>
- Loading branch information
Showing
74 changed files
with
15,054 additions
and
7,562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: Continuous Integration | ||
on: | ||
schedule: | ||
- cron: '0 0 * * 2' | ||
push: | ||
branches: | ||
- master | ||
- staging | ||
- trying | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- .github/workflows/ci.yml | ||
- pyvisa/* | ||
- pyproject.toml | ||
- setup.cfg | ||
- setup.py | ||
|
||
jobs: | ||
formatting: | ||
name: Check code formatting | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install tools | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 black isort mypy | ||
- name: Isort | ||
run: | | ||
isort pyvisa -rc -c; | ||
- name: Black | ||
run: | | ||
black pyvisa --check; | ||
- name: Flake8 | ||
run: | | ||
flake8 pyvisa; | ||
- name: Mypy | ||
run: | | ||
mypy pyvisa; | ||
tests: | ||
name: Unit tests | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
python-version: [3.6, 3.7, 3.8] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
- name: Install project | ||
run: | | ||
pip install -e . | ||
- name: Test with pytest | ||
run: | | ||
pip install pytest-cov | ||
pytest pyvisa/testsuite --cov pyvisa --cov-report xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
flags: unittests | ||
name: codecov-umbrella | ||
yml: ./codecov.yml | ||
fail_ci_if_error: true | ||
|
||
# Added to summarize the matrix (otherwise we would need to list every single | ||
# job in bors.toml) | ||
tests-result: | ||
name: Tests result | ||
if: always() | ||
needs: | ||
- tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Mark the job as a success | ||
if: needs.tests.result == 'success' | ||
run: exit 0 | ||
- name: Mark the job as a failure | ||
if: needs.tests.result != 'success' | ||
run: exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Documentation building | ||
on: | ||
schedule: | ||
- cron: '0 0 * * 2' | ||
push: | ||
branches: | ||
- master | ||
- staging | ||
- trying | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- .github/workflows/docs.yml | ||
- pyvisa/* | ||
- docs/* | ||
- setup.py | ||
|
||
jobs: | ||
docs: | ||
name: Docs building | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
- name: Install project | ||
run: | | ||
python setup.py develop | ||
- name: Install graphviz | ||
uses: kamiazya/setup-graphviz@v1 | ||
- name: Install doc building tools | ||
run: | | ||
pip install sphinx sphinx_rtd_theme | ||
- name: Build documentation | ||
run: | | ||
mkdir docs_output; | ||
sphinx-build docs/source docs_output -W -b html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v4.3.21 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/psf/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.7 | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.3.0 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: '' # Use the sha / tag you want to point at | ||
hooks: | ||
- id: mypy | ||
additional_dependencies: [numpy, typing_extensions] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
status = ["Check code formatting", "Tests result", "Docs building"] | ||
delete-merged-branches = true | ||
timeout_sec = 600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
black | ||
flake8 | ||
mypy | ||
isort | ||
sphinx | ||
sphinx-rtd-theme |
Oops, something went wrong.