Skip to content

Commit 94e5e15

Browse files
feat: Add register and unregister entry points for Extensions Manager (#28)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent e622459 commit 94e5e15

File tree

6 files changed

+140
-9
lines changed

6 files changed

+140
-9
lines changed

doc/changelog.d/28.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: Add register and unregister entry points for Extensions Manager

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ Homepage = "https://www.ansys.com/products/embedded-software/ansys-scade-suite"
6969

7070
[project.entry-points."ansys.scade.registry"]
7171
srg = "ansys.scade.python_wrapper:srg"
72+
register = "ansys.scade.python_wrapper.register:register"
73+
unregister = "ansys.scade.python_wrapper.unregister:unregister"
7274

7375
[project.scripts]
74-
register_ansys_scade_python_wrapper = "ansys.scade.python_wrapper.register:main"
7576
ansys_scade_python_wrapper_swanpython = "ansys.scade.python_wrapper.swanpython:main"
77+
# backward compatibility
78+
register_ansys_scade_python_wrapper = "ansys.scade.python_wrapper.register:main"
79+
unregister_ansys_scade_python_wrapper = "ansys.scade.python_wrapper.unregister:main"
7680

7781
[tool.ruff]
7882
line-length = 99

src/ansys/scade/python_wrapper/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
except ModuleNotFoundError:
2828
import importlib_metadata
2929
from pathlib import Path
30+
import sys
3031

3132
try:
3233
__version__ = importlib_metadata.version(__name__.replace('.', '-'))
@@ -35,6 +36,20 @@
3536
__version__ = '0.0.0'
3637

3738

39+
def get_srg_name() -> str:
40+
"""
41+
Return the name of the registration file for Ansys SCADE IDE.
42+
43+
It addresses SCADE 2024 R2 and prior releases.
44+
SCADE 2025 R1 and above use the package's
45+
``ansys.scade.registry`` entry point.
46+
"""
47+
# registrations depending on Python interpreter
48+
python_version = str(sys.version_info.major) + str(sys.version_info.minor)
49+
suffix = '23r1' if python_version == '37' else '24r2'
50+
return 'python_wrapper%s.srg' % suffix
51+
52+
3853
def srg() -> str:
3954
r"""
4055
Return the path of the SCADE Studio registry file.

src/ansys/scade/python_wrapper/register.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,38 @@
3434
import os
3535
from pathlib import Path
3636
import sys
37+
from typing import Tuple
38+
39+
from ansys.scade.python_wrapper import get_srg_name
3740

3841
_APPDATA = os.getenv('APPDATA')
3942

4043

4144
def _register_srg_file(srg: Path, install: Path):
4245
# copy the srg file to Customize and patch it with the installation directory.
46+
assert _APPDATA
4347
text = srg.open().read()
4448
text = text.replace('%TARGETDIR%', install.as_posix())
4549
dst = Path(_APPDATA, 'SCADE', 'Customize', srg.name)
4650
dst.parent.mkdir(parents=True, exist_ok=True)
4751
dst.open('w').write(text)
4852

4953

50-
def _python_wrapper_config():
51-
# register the Code Generator extension registry files (SRG).
54+
def register() -> Tuple[int, str]:
55+
"""Implement the ``ansys.scade.registry/register`` entry point."""
5256
script_dir = Path(__file__).parent
53-
# registrations depending on Python interpreter
54-
python_version = str(sys.version_info.major) + str(sys.version_info.minor)
55-
suffix = '23r1' if python_version == '37' else '24r2'
56-
_register_srg_file(script_dir / ('python_wrapper%s.srg' % suffix), script_dir)
57+
_register_srg_file(script_dir / get_srg_name(), script_dir)
58+
return (0, '')
5759

5860

5961
def main():
6062
"""Implement the ``ansys.scade.python_wrapper.register`` packages's project script."""
61-
_python_wrapper_config()
63+
code, message = register()
64+
if message:
65+
print(message, file=sys.stderr if code else sys.stdout)
66+
return code
6267

6368

6469
if __name__ == '__main__':
65-
main()
70+
code = main()
71+
sys.exit(code)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""
24+
Unregisters the Code Generator extension registry files (SRG).
25+
26+
Refer to the :ref:`installation <getting_started/index:install in user mode>`
27+
steps for more information.
28+
29+
It addresses SCADE 2024 R2 and prior releases.
30+
SCADE 2025 R1 and above use the package's
31+
``ansys.scade.registry`` entry point.
32+
"""
33+
34+
import os
35+
from pathlib import Path
36+
import sys
37+
from typing import Tuple
38+
39+
from ansys.scade.python_wrapper import get_srg_name
40+
41+
_APPDATA = os.getenv('APPDATA')
42+
43+
44+
def _unregister_srg_file(name: str):
45+
"""Delete the srg file from Customize."""
46+
assert _APPDATA
47+
dst = Path(_APPDATA, 'SCADE', 'Customize', name)
48+
dst.unlink(missing_ok=True)
49+
50+
51+
def unregister() -> Tuple[int, str]:
52+
"""Implement the ``ansys.scade.registry/unregister`` entry point."""
53+
_unregister_srg_file(get_srg_name())
54+
return (0, '')
55+
56+
57+
def main():
58+
"""Implement the ``ansys.scade.python_wrapper.unregister`` packages's project script."""
59+
code, message = unregister()
60+
if message:
61+
print(message, file=sys.stderr if code else sys.stdout)
62+
return code
63+
64+
65+
if __name__ == '__main__':
66+
code = main()
67+
sys.exit(code)

tests/test_entry_points.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from pathlib import Path
24+
25+
import ansys.scade.python_wrapper as pw
26+
27+
28+
def test_srg():
29+
path = pw.srg()
30+
assert path
31+
assert Path(path).exists()
32+
33+
34+
def test_get_srg_name():
35+
name = pw.get_srg_name()
36+
assert name
37+
assert name.startswith('python_wrapper2')
38+
assert name.endswith('.srg')

0 commit comments

Comments
 (0)