Verifying HyperStudy Scripts#
When writing scripts using the HyperStudy API, it is important to ensure that they are functioning correctly and efficiently. Here are some guidelines and methods to verify your scripts:
Prerequisites#
Locate the Python executable#
Windows |
|
Linux |
|
Note
Using the Python executable directly may require additional PYTHONPATH setup to ensure the HyperStudy Python libraries are located. This can be found at hwdesktop/hst/scripts/python/python3.10/win64 for Windows and hwdesktop/hst/scripts/python/python3.10/linux64 for Linux.
Note
For the rest of this document, python will be used to refer to either the Python executable or the hstpy script.
Install Required Packages#
1python -m pip install mypy==1.14.1
2python -m pip install types-psutil
3python -m pip install types-pywin32
4python -m pip install types-openpyxl
5python -m pip install types-Pillow
6python -m pip install pandas-stubs
7python -m pip install pylint==3.2.7
Run mypy#
Command Line#
1python -m mypy --pretty <script>
Specify a Configuration File#
This step is optional but can be helpful if there are a lot of settings that need to be modified.
Use the
--config-filecommand line argument.
1[mypy]
2python_version = 3.10
3explicit_package_bases = True
4strict = True
5force_union_syntax = True
6force_uppercase_builtins = True
7follow_imports_for_stubs = True
8disallow_untyped_calls = False
9warn_no_return = True
10warn_unreachable = False
11pretty = True
12
13# These are all relative to hwdesktop/hst/dev/src/py
14exclude = (?x)(
15 alt/hst/eac/cmd/hstupdate_flux\.py$
16 | alt/hst/eac/cmd/hstupdate_wbpj\.py$
17 | alt/hst/persist/.*\.py$
18 | alt/hst/eac/cmd/inspire_import\.py$
19 | alt/hst/eac/cmd/inspire_update\.py$
20 )
21
22[mypy-eds.*]
23follow_imports = silent
24
25[mypy-hwx.*]
26follow_imports = silent
27
28[mypy-hwui]
29ignore_missing_imports = True
30
31[mypy-hwuiExtensions]
32ignore_missing_imports = True
33
34[mypy-hmbatch.*]
35follow_imports = silent
36implicit_reexport = True
37
38[mypy-mdi.*]
39follow_imports = silent
40implicit_reexport = True
41
42[mypy-hw.*]
43follow_imports = silent
44
45[mypy-hm.*]
46follow_imports = silent
47
48[mypy-altair.*]
49ignore_errors = True
50follow_imports = skip
Example#
1import alt.hst.api.session as sess
2
3study = sess.getStudy()
4x = 3
5print(study.getVarname() + x)
The output should show that there is a type mismatch on line 5:
example_script.py:5 error: Unsupported operand types for + ("str" and "int") [operator]
print(study.getVarname() + x)
^
Found 1 error in 1 file (checked 1 source file)
1import alt.hst.api.session as sess
2
3study = sess.getStudy()
4x = 3
5print(study.getVarname() + str(x))
The output should show that no issues have been found:
Success: no issues found in 1 source file
Run Pylint#
Command Line#
1python -m pylint <script>
Specify a Configuration File#
use the
--rcfile=.pylintrccommand line argument.
1[MAIN]
2init-hook=
3 import sys, os;
4 sys.path.append(os.path.join(os.getenv('HW_ROOTDIR'), 'hwcommon', 'eds', 'python'));
5 sys.path.append(os.path.join(os.getenv('HW_ROOTDIR'), 'unity', 'scripts', 'python'));
6 sys.path.append(os.path.join(os.getenv('HW_ROOTDIR'), 'hw', 'python'));
7 sys.path.append(os.path.join(os.getenv('HW_FRAMEWORK'), 'scripts', 'python'));
8 sys.path.append(os.path.join(os.getenv('HW_FRAMEWORK'), 'bin', 'win64d' if os.getenv('HW_DEBUG', '0') == '1' else 'win64'));
9 from astroid import MANAGER;
10 MANAGER.astroid_cache.clear();
11
12ignore=
13 hstapi.py,
14 hwpdd.py,
15 tst_hstupdate_wbpj_01.py,
16 tst_hstupdate_wbpj_02.py,
17 hstupdate_flux.py,
18 hstupdate_wbpj.py
19
20prefer-stubs=yes
21ignore-patterns=.*persist.*
22ignore-paths=.*/alt/hst/persist/.*
23persistent=no
24load-plugins=
25jobs=10
26unsafe-load-any-extension=no
27extension-pkg-whitelist=
28 win32file
29
30[MESSAGES CONTROL]
31disable=R,C,W0237,W0614,W0718,W0719,
32 W0238
33enable=
34 bad-indentation,
35 c-extension-no-member
36fail-on=I1101
37evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
38
39[BASIC]
40good-names=i,j,k,ex,Run,_
41bad-names=foo,bar,baz,toto,tutu,tata
42name-group=
43include-naming-hint=no
44property-classes=abc.abstractproperty
45function-rgx=[a-z_][a-z0-9_]{2,30}$
46variable-rgx=[a-z_][a-z0-9_]{2,30}$
47const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
48attr-rgx=[a-z_][a-z0-9_]{2,30}$
49argument-rgx=[a-z_][a-z0-9_]{2,30}$
50class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
51inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
52class-rgx=[A-Z_][a-zA-Z0-9]+$
53module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
54method-rgx=[a-z_][a-z0-9_]{2,30}$
55no-docstring-rgx=^_
56docstring-min-length=-1
57
58[FORMAT]
59max-line-length=100
60ignore-long-lines=^\s*(# )?<?https?://\S+>?$
61single-line-if-stmt=no
62max-module-lines=1000
63indent-string=' '
64indent-after-paren=4
65expected-line-ending-format=
66
67[LOGGING]
68logging-modules=logging
69
70[SIMILARITIES]
71min-similarity-lines=4
72ignore-comments=yes
73ignore-docstrings=yes
74ignore-imports=no
75
76[TYPECHECK]
77ignore-mixin-members=yes
78ignored-modules=alt.hst.core.hstapi,numpy,PyQt4.QtCore,PyQt4.QtGui,pythoncom,win32api
79ignored-classes=optparse.Values,thread._local,_thread._local
80generated-members=alt.hst.common.hwappinfo.getAltairHome,re.match
81
82[VARIABLES]
83init-import=no
84dummy-variables-rgx=(_unused[_a-zA-Z0-9]*$)
85redefining-builtins-modules=six.moves,future.builtins
86
87[CLASSES]
88defining-attr-methods=__init__,__new__,setUp
89valid-classmethod-first-arg=cls
Example#
1import alt.hst.api.sessio as sess
2
3study = sess.getStudy()
4x = 3
5print(study.getVarname() + str(x))
The output should show that there an import error on line 1:
************* Module example_script
example_script.py(3): [E0401(import-error)] Unable to import 'alt.hst.api.sessio'
example_script.py(3): [E0611(no-name-in-module)] No name 'sessio' in module 'alt.hst.api'
----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: 0.00/10, -15.00)
1import alt.hst.api.session as sess
2
3study = sess.getStudy()
4x = 3
5print(study.getVarname() + str(x))
The output should show that no issues have been found:
----------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)