Skip to content

Commit c497183

Browse files
committed
xuananh
them config de debug va them method mapping cac path trong terminal voi project genetica-user-portal chinh lai config mapping path them config de chay tren local add command git add warning add feature for mapping path file config update readme rename mapping file
1 parent 0eba0bb commit c497183

File tree

12 files changed

+293
-5
lines changed

12 files changed

+293
-5
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ ChangeLog
7777
.direnv
7878
.envrc
7979
.venv
80-
.vscode/
8180

8281
guake/data/gschemas.compiled
8382
.pytest_cache/

.guake.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"quick_open_cmd": "code -g %(file_path)s:%(line_number)s",
3+
"mapping_paths": {
4+
"/app": "/home/xuananh/repo/guake/guake"
5+
}
6+
}

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.0

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Attach",
9+
"type": "python",
10+
"request": "attach",
11+
"connect": {
12+
"host": "localhost",
13+
"port": 5678
14+
}
15+
}
16+
]
17+
}

Makefile

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ reset:
4343

4444
all: clean dev style checks dists test docs
4545

46-
dev: clean-ln-venv ensure-pip pipenv-install-dev requirements ln-venv setup-githook \
46+
dev: ensure-pip pipenv-install-dev requirements ln-venv setup-githook \
4747
prepare-install install-dev-locale
4848
dev-actions: ensure-pip-system pipenv-install-dev prepare-install
4949

@@ -438,3 +438,48 @@ styles: style
438438
uninstall: uninstall-system
439439
upgrade: update
440440
wheel: wheels
441+
442+
# ============================ xuananh - local ==========================
443+
# https://guake.readthedocs.io/en/latest/contributing/dev_env.html
444+
local-install-system-dependencies:
445+
./scripts/bootstrap-dev-debian.sh run make
446+
447+
local-run: # this command run with logging INFO
448+
.venv/bin/python guake/main.py --no-startup-script
449+
450+
local-run-logging-DEBUG:
451+
.venv/bin/python guake/main.py --no-startup-script --verbose
452+
453+
local-debug:
454+
.venv/bin/python -m debugpy --listen 5678 guake/main.py --no-startup-script --verbose
455+
456+
local-install-packages:
457+
sudo apt install -y build-essential libdbus-glib-1-dev libgirepository1.0-dev \
458+
pkg-config libcairo2-dev gcc python3-dev \
459+
gettext
460+
461+
local-requirements:
462+
.venv/bin/pip install -r requirements-dev.txt
463+
.venv/bin/pip install dbus-python
464+
.venv/bin/pip install vext==0.7.6
465+
.venv/bin/pip install vext.gi==0.7.4
466+
.venv/bin/pip install gobject==0.1.0
467+
.venv/bin/pip install PyGObject==3.46.0
468+
.venv/bin/pip install debugpy dataclasses
469+
470+
# refer here on how to setup development env: https://guake.readthedocs.io/en/latest/contributing/dev_env.html#setup-development-environment
471+
local-setup-development-environment: local-install-packages local-requirements prepare-install install-dev-locale
472+
473+
git-rebase-origin-repo:
474+
git remote add origin-repo https://github.com/Guake/guake.git ||:
475+
git checkout master
476+
git pull origin-repo master
477+
git push origin master
478+
git checkout xuananh
479+
git rebase origin-repo/master
480+
481+
git-amend-push:
482+
git add .
483+
git commit --amend --no-edit
484+
git push origin -f
485+

README.images/gtk-inspector-1.png

46.7 KB
Loading

README.images/gtk-inspector-2.png

73.3 KB
Loading

README.images/gtk-inspector-3.png

233 KB
Loading

README.images/gtk-inspector-4.png

112 KB
Loading

README_xuananh.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
- [1. run on local](#1-run-on-local)
2+
- [1.1. prepare environment](#11-prepare-environment)
3+
- [1.2. debug](#12-debug)
4+
- [2. How to use "mapping path then opening in vscode feature"](#2-how-to-use-mapping-path-then-opening-in-vscode-feature)
5+
- [3. Patch current guake](#3-patch-current-guake)
6+
- [3.1. create patch](#31-create-patch)
7+
- [3.2. apply patch](#32-apply-patch)
8+
- [4. change stk css style](#4-change-stk-css-style)
9+
- [4.1. css file localtion](#41-css-file-localtion)
10+
- [4.2. using GTK Inspector for debug css](#42-using-gtk-inspector-for-debug-css)
11+
- [4.3. references](#43-references)
12+
- [5. cherry-pick and rebase into one commit](#5-cherry-pick-and-rebase-into-one-commit)
13+
- [6. install](#6-install)
14+
15+
# 1. run on local
16+
17+
## 1.1. prepare environment
18+
19+
```shell
20+
pyenv local 3.9.0
21+
venv-create
22+
23+
make local-setup-development-environment
24+
# ./scripts/bootstrap-dev-debian.sh
25+
make local-run
26+
# make local-run-logging-DEBUG
27+
```
28+
29+
## 1.2. debug
30+
31+
1. run guake with debugpy
32+
33+
```shell
34+
make local-debug
35+
```
36+
37+
2. run debug mode vscode
38+
3. set breakpoints
39+
4. reduce guake windows size, because when debug, guake terminal will stay in screen
40+
5. do something in guake terminale
41+
42+
# 2. How to use "mapping path then opening in vscode feature"
43+
44+
1. Create configs file [.guake.json](.guake.json) in the root folder
45+
46+
47+
2. cd to guake repo
48+
49+
```shell
50+
cd /home/xuananh/repo/guake/
51+
git checkout xuananh
52+
```
53+
54+
3. copy bellow log and paste to terminal
55+
56+
```shell
57+
Traceback (most recent call last):
58+
File "/app/main.py", line 190, in on_task_received
59+
strategy = strategies[type_]
60+
```
61+
62+
4. Ctrl + click to "app/main.py", it will open [guake/main.py](guake/main.py) on vscode based on setting in file [.guake.json](.guake.json)
63+
64+
# 3. Patch current guake
65+
66+
## 3.1. create patch
67+
68+
```shell
69+
git --no-pager diff --no-index --patch \
70+
--output=/home/xuananh/Dropbox/Work/Other/conf.d/guake/guake_patch.diff \
71+
terminal_origin.py \
72+
terminal_customized.py
73+
```
74+
75+
## 3.2. apply patch
76+
77+
```shell
78+
sudo patch -p1 /usr/lib/python3/dist-packages/guake/terminal.py \
79+
/home/xuananh/Dropbox/Work/Other/conf.d/guake/guake_patch.diff
80+
81+
# ------- output
82+
# patching file /usr/lib/python3/dist-packages/guake/terminal.py
83+
# Hunk #1 succeeded at 272 (offset 14 lines).
84+
# Hunk #2 succeeded at 340 (offset 14 lines).
85+
# Hunk #3 succeeded at 424 (offset 14 lines).
86+
87+
```
88+
89+
You can see that the above file is patched successfully with offset, it means that this file change quite lot from the time creating patch file.
90+
91+
In case patching fail because there is a lot of change, you should create new patch file by these steps:
92+
93+
1. create 2 new file to create patch
94+
95+
```shell
96+
cp /usr/lib/python3/dist-packages/guake/terminal.py ~/Downloads/terminal_origin.py
97+
cp /usr/lib/python3/dist-packages/guake/terminal.py ~/Downloads/terminal_customized.py
98+
```
99+
100+
2. change file `~/Downloads/terminal_origin.py` based on branch `xuananh`, then create patch file again using command in [3.1. create patch](#31-create-patch)
101+
102+
# 4. change stk css style
103+
104+
## 4.1. css file localtion
105+
106+
~/.config/gtk-3.0/gtk.css
107+
108+
## 4.2. using GTK Inspector for debug css
109+
110+
Run guake by command:
111+
112+
```shell
113+
GTK_DEBUG=interactive make local-run
114+
```
115+
116+
it will run guake and GTK Inspector :
117+
118+
![](README.images/gtk-inspector-1.png)
119+
120+
121+
do as above image to inspect element in guake, it will show as below
122+
123+
![](README.images/gtk-inspector-2.png)
124+
125+
choose another function: CSS nodes as bellow
126+
127+
![](README.images/gtk-inspector-3.png)
128+
129+
you can see above image to know how to get right css selector and set attribute for it
130+
131+
in above image, we got css selector for selected tab in guake terminal, then set its box-shadow color to highlight selected tab
132+
133+
you can test your css by switch to css tab
134+
135+
![](README.images/gtk-inspector-4.png)
136+
137+
## 4.3. references
138+
139+
https://blog.gtk.org/2017/04/05/the-gtk-inspector/
140+
141+
https://gtkthemingguide.vercel.app/#/creating_gtk_themes?id=selectors
142+
143+
# 5. cherry-pick and rebase into one commit
144+
145+
```shell
146+
# create new branch to cherry-pick
147+
git checkout -b xuananh-add-new-feature-mapping-file-path-to-open-in-vscode xuananh-backup
148+
149+
# reset new branch to the commit from that XuanAnh start add new commit
150+
git checkout master
151+
git branch -f xuananh-add-new-feature-mapping-file-path-to-open-in-vscode c3f3a60d943ece1918aad3f077118145d9f61aeb
152+
git checkout xuananh-add-new-feature-mapping-file-path-to-open-in-vscode
153+
154+
# cherry pick 11 commits from branch xuananh-backup
155+
git cherry-pick d685fe66132fc5f4c811dbae90a27bd7154e7840
156+
git cherry-pick 78f69d20cb8d5cc0bd27a15d090cbc2c98ce6a5a
157+
git cherry-pick 417fcbc82ab6420928dfaf666511855b73438040
158+
git cherry-pick f1efff96d51f921d42874e04399d7b65358aa47b
159+
git cherry-pick 2162ce10374b493374c36fc1f899e02d3a55c008
160+
git cherry-pick f0d06d0c5023991f5977e5f2b437ab4ceea653e4
161+
git cherry-pick 93cbcbe445f012e5264b303ac364665b173e7231
162+
git cherry-pick 1cb171f96f08d04577261df43abd17bedb57fdd9
163+
git cherry-pick 9a13c20707b9841812fb223628676e38146340a3
164+
git cherry-pick 0348b2988d03e8290cbf0dbd91457b61078f44b0
165+
git cherry-pick 286977fcf754168ca7e13dd0ec8fa92cec60f824
166+
167+
# create new branch to rebase
168+
git checkout -b xuananh-add-new-feature-mapping-file-path-to-open-in-vscode-rebased xuananh-add-new-feature-mapping-file-path-to-open-in-vscode
169+
170+
# rebase above 11 commits, reference on how to rebase
171+
# https://www.freecodecamp.org/news/git-squash-commits/
172+
# https://stackoverflow.com/a/21278908
173+
git rebase --interactive HEAD~11
174+
175+
# create new branch with shorter name
176+
git checkout -b xuananh xuananh-add-new-feature-mapping-file-path-to-open-in-vscode-rebased
177+
178+
```
179+
180+
# 6. install
181+
182+
https://guake.readthedocs.io/en/latest/contributing/dev_env.html#install-on-system
183+
184+
`make && sudo make install`
185+
186+
or reinstall
187+
188+
`make reinstall`

guake/terminal.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ def get_current_directory(self):
273273
directory = cwd
274274
return directory
275275

276+
def mapping_file_path(self, current_path) -> Path:
277+
"""xuananh
278+
"""
279+
import json
280+
cwd = self.get_current_directory()
281+
path_mapping_configs = json.load(open(cwd + '/.guake.json', 'r'))
282+
mapping_paths = path_mapping_configs.get("mapping_paths")
283+
default_mapping = {
284+
"/usr/local": cwd + "/.venv"
285+
}
286+
mapping_paths.update(default_mapping)
287+
for key, value in mapping_paths.items():
288+
if key in current_path:
289+
new_path = current_path.replace(key, value, 1) # NOTE: only replace the first occurenc
290+
return new_path
291+
return current_path
292+
276293
def is_file_on_local_server(self, text) -> Tuple[Optional[Path], Optional[int], Optional[int]]:
277294
"""Test if the provided text matches a file on local server
278295
@@ -323,7 +340,7 @@ def find_lineno(text, pt, lineno, py_func):
323340
if line.startswith(f"def {py_func}"):
324341
return i + 1
325342
break
326-
343+
text = self.mapping_file_path(text)
327344
pt = Path(text)
328345
log.debug("checking file existance: %r", pt)
329346
try:
@@ -409,6 +426,8 @@ def _on_ctrl_click_matcher(self, matched_string):
409426
use_quick_open = self.guake.settings.general.get_boolean("quick-open-enable")
410427
if use_quick_open:
411428
found_matcher = self._find_quick_matcher(value)
429+
else:
430+
log.warning("xuananh ============> NOTE: quick-open by vscode is not enabled, go to reference to setup quick open with vscode with syntax: code -g %(file_path)s:%(line_number)s")
412431
if not found_matcher:
413432
self.found_link = self.handleTerminalMatch(matched_string)
414433
if self.found_link:
@@ -435,10 +454,23 @@ def _find_quick_matcher(self, value):
435454
return True
436455
return False
437456

457+
def _get_custom_quick_open_cmd(self) -> str:
458+
"""xuananh
459+
"""
460+
import json
461+
cwd = self.get_current_directory()
462+
path_mapping_configs = json.load(open(cwd + '/.guake.json', 'r'))
463+
quick_open_cmd = path_mapping_configs.get("quick_open_cmd")
464+
return quick_open_cmd
465+
438466
def _execute_quick_open(self, filepath, line_number):
439467
if not filepath:
440468
return
441-
cmdline = self.guake.settings.general.get_string("quick-open-command-line")
469+
470+
cmdline = self._get_custom_quick_open_cmd()
471+
if not cmdline:
472+
cmdline = self.guake.settings.general.get_string("quick-open-command-line")
473+
442474
if not line_number:
443475
line_number = ""
444476
else:

scripts/bootstrap-dev-debian.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if [[ $DEV == "1" ]]; then
6868
dconf-editor \
6969
glade \
7070
poedit \
71-
gnome-tweak-tool
71+
gnome-tweaks
7272
fi
7373

7474
if [[ $OPT == "1" ]]; then

0 commit comments

Comments
 (0)