Skip to content

Commit e33c1ca

Browse files
committed
install pycharm debugger for cicd
1 parent a79b5cc commit e33c1ca

File tree

6 files changed

+74
-7
lines changed

6 files changed

+74
-7
lines changed

.github/workflows/pyright.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
run: |
4949
pip list
5050
pip install -r ckan/requirements.txt -r ckan/dev-requirements.txt ckan/.
51+
pip install -e".[pycharm2025]"
5152
pip install -e".[test]"
5253
5354
- name: Install node deps

.github/workflows/pytest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
# Install any extra requirements your extension has here (dev requirements, other extensions etc)
5252
run: |
5353
apt install git
54+
pip install -e ".[pycharm2025]"
5455
pip install -e ".[test]"
5556
# .[test] will install base dependencies as well as the test optional group
5657

@@ -66,7 +67,7 @@ jobs:
6667
- name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} Run tests
6768
continue-on-error: ${{ matrix.experimental }}
6869
run: |
69-
pytest --ckan-ini=test.ini --cov=ckanext.selfinfo ckanext/selfinfo --cov-branch --cov-report=xml --junit-xml=./results/junit_results.xml -o junit_family=legacy
70+
pytest --ckan-ini=test.ini --cov=ckanext.pycharm_debugger ckanext/pycharm_debugger --cov-branch --cov-report=xml --junit-xml=./results/junit_results.xml -o junit_family=legacy
7071
7172
- name: Generate Test results artifacts
7273
continue-on-error: ${{ matrix.experimental }}

ckanext/pycharm_debugger/config_declaration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 1
22
groups:
3-
- annotation: selfinfo configuration
3+
- annotation: pycharm debugger configuration
44
options:
55
- key: debug.remote.egg_dir
66
type: str
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys
2+
import types
3+
import pytest
4+
import logging
5+
from unittest import mock
6+
7+
from ckanext.pycharm_debugger import PycharmDebugger
8+
9+
10+
@pytest.mark.parametrize("debug_enabled, import_success", [
11+
(True, True), # Debug enabled and pydevd_pycharm is available
12+
(True, False), # Debug enabled and pydevd_pycharm is missing
13+
(False, False), # Debug disabled, pydevd_pycharm should not be imported
14+
])
15+
def test_update_config(monkeypatch, debug_enabled, import_success, caplog):
16+
caplog.set_level(logging.INFO)
17+
18+
# Create dummy config
19+
config = {
20+
'debug.remote': str(debug_enabled),
21+
'debug.remote.egg_dir': '/dummy/dir',
22+
'debug.remote.egg_file': 'dummy.egg',
23+
'debug.remote.host.ip': '127.0.0.1',
24+
'debug.remote.host.port': '1234',
25+
'debug.remote.stdout_to_server': 'True',
26+
'debug.remote.stderr_to_server': 'True',
27+
'debug.remote.suspend': 'True',
28+
}
29+
30+
# Monkeypatch sys.path to ensure we can track the append
31+
sys_path_original = list(sys.path)
32+
monkeypatch.setattr(sys, 'path', list(sys_path_original)) # isolate mutation
33+
34+
# Mock pydevd_pycharm or simulate ImportError
35+
if debug_enabled:
36+
if import_success:
37+
mock_pydevd = types.SimpleNamespace(
38+
settrace=mock.Mock()
39+
)
40+
monkeypatch.setitem(sys.modules, 'pydevd_pycharm', mock_pydevd)
41+
else:
42+
sys.modules.pop('pydevd_pycharm', None)
43+
monkeypatch.setitem(sys.modules, 'pydevd_pycharm', None)
44+
45+
# Instantiate and call
46+
plugin = PycharmDebugger()
47+
plugin.update_config(config)
48+
49+
if debug_enabled:
50+
if import_success:
51+
assert "Initiating remote debugging session" in caplog.text
52+
assert sys.path[-1] == '/dummy/dir/dummy.egg'
53+
sys.modules['pydevd_pycharm'].settrace.assert_called_once_with(
54+
'127.0.0.1', port=1234, stdoutToServer=True,
55+
stderrToServer=True, suspend=True
56+
)
57+
else:
58+
assert "pydevd_pycharm is missing" in caplog.text or \
59+
"Failed to connect to debug server" in caplog.text
60+
else:
61+
assert "PyCharm Debugger not enabled" in caplog.text
62+
assert '/dummy/dir/dummy.egg' in sys.path
63+
64+
# Reset sys.path
65+
sys.path = sys_path_original

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use = config:../ckan/test-core.ini
88

99
# Insert any custom config settings to be used when running your extension's
1010
# tests here. These will override the one defined in CKAN core's test-core.ini
11-
ckan.plugins = selfinfo
11+
ckan.plugins = pycharm_debugger
1212

1313

1414
# Logging configuration
@@ -36,10 +36,10 @@ handlers = console
3636
qualname = ckanext
3737
propagate = 0
3838

39-
[logger_ckanext_selfinfo]
39+
[logger_ckanext_pycharm_debugger]
4040
level = DEBUG
4141
handlers = console
42-
qualname = ckanext.selfinfo
42+
qualname = ckanext.pycharmdebugger
4343
propagate = 0
4444

4545
[logger_sqlalchemy]

0 commit comments

Comments
 (0)