Skip to content

Commit

Permalink
them config de debug va them method mapping cac path trong terminal v…
Browse files Browse the repository at this point in the history
…oi 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
  • Loading branch information
PhungXuanAnh committed Jun 29, 2024
1 parent bb76160 commit 6e496be
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ ChangeLog
.direnv
.envrc
.venv
.vscode/

guake/data/gschemas.compiled
.pytest_cache/
Expand Down
3 changes: 3 additions & 0 deletions .guake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"/app": "/home/xuananh/repo/guake/guake"
}
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.0
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
]
}
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,44 @@ styles: style
uninstall: uninstall-system
upgrade: update
wheel: wheels

# ============================ xuananh - local ==========================
# https://guake.readthedocs.io/en/latest/contributing/dev_env.html
local-install-system-dependencies:
./scripts/bootstrap-dev-debian.sh run make

local-run: # this command run with logging INFO
.venv/bin/python guake/main.py --no-startup-script

local-run-logging-DEBUG:
.venv/bin/python guake/main.py --no-startup-script --verbose

local-debug:
.venv/bin/python -m debugpy --listen 5678 guake/main.py --no-startup-script --verbose

local-install-packages:
sudo apt install -y build-essential libdbus-glib-1-dev libgirepository1.0-dev \
pkg-config libcairo2-dev gcc python3-dev \
gettext

local-requirements:
.venv/bin/pip install -r requirements-dev.txt
.venv/bin/pip install dbus-python
.venv/bin/pip install vext==0.7.6
.venv/bin/pip install vext.gi==0.7.4
.venv/bin/pip install gobject==0.1.0
.venv/bin/pip install PyGObject==3.46.0
.venv/bin/pip install debugpy dataclasses

local-prepare-environment: local-install-packages local-requirements prepare-install install-dev-locale

git-sync-origin-repo:
git remote add origin-repo https://github.com/Guake/guake.git ||:
git checkout master
git fetch origin-repo
git merge origin-repo/master

git-amend-push:
git add .
git commit --amend --no-edit
git push origin -f
Binary file added README.images/gtk-inspector-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README.images/gtk-inspector-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README.images/gtk-inspector-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README.images/gtk-inspector-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
- [1. run on local](#1-run-on-local)
- [1.1. prepare environment](#11-prepare-environment)
- [1.2. debug](#12-debug)
- [2. How to use "mapping path then opening in vscode feature"](#2-how-to-use-mapping-path-then-opening-in-vscode-feature)
- [3. Patch current guake](#3-patch-current-guake)
- [3.1. create patch](#31-create-patch)
- [3.2. apply patch](#32-apply-patch)
- [4. change stk css style](#4-change-stk-css-style)
- [4.1. css file localtion](#41-css-file-localtion)
- [4.2. using GTK Inspector for debug css](#42-using-gtk-inspector-for-debug-css)
- [4.3. references](#43-references)
- [5. cherry-pick and rebase into one commit](#5-cherry-pick-and-rebase-into-one-commit)

# 1. run on local

## 1.1. prepare environment

```shell
pyenv local 3.9.0
venv-create

make local-prepare-environment
make local-run
```

## 1.2. debug

1. run guake with debugpy

```shell
make local-debug
```

2. run debug mode vscode
3. set breakpoints
4. reduce guake windows size, because when debug, guake terminal will stay in screen
5. do something in guake terminale

# 2. How to use "mapping path then opening in vscode feature"

1. Create configs file [.guake.json](.guake.json) in the root folder of repo with content:

```json
{
"/app": "/home/xuananh/repo/guake/guake"
}
```

2. cd to guake repo

```shell
cd /home/xuananh/repo/guake/
git checkout xuananh
```

3. copy bellow log and paste to terminal

```shell
Traceback (most recent call last):
File "/app/main.py", line 190, in on_task_received
strategy = strategies[type_]
```

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)

# 3. Patch current guake

## 3.1. create patch

```shell
git --no-pager diff --no-index --patch \
--output=/home/xuananh/Dropbox/Work/Other/conf.d/guake/guake_patch.diff \
terminal_origin.py \
terminal_customized.py
```

## 3.2. apply patch

```shell
sudo patch -p1 /usr/lib/python3/dist-packages/guake/terminal.py \
/home/xuananh/Dropbox/Work/Other/conf.d/guake/guake_patch.diff

# ------- output
# patching file /usr/lib/python3/dist-packages/guake/terminal.py
# Hunk #1 succeeded at 272 (offset 14 lines).
# Hunk #2 succeeded at 340 (offset 14 lines).
# Hunk #3 succeeded at 424 (offset 14 lines).

```

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.

In case patching fail because there is a lot of change, you should create new patch file by these steps:

1. create 2 new file to create patch

```shell
cp /usr/lib/python3/dist-packages/guake/terminal.py ~/Downloads/terminal_origin.py
cp /usr/lib/python3/dist-packages/guake/terminal.py ~/Downloads/terminal_customized.py
```

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)

# 4. change stk css style

## 4.1. css file localtion

~/.config/gtk-3.0/gtk.css

## 4.2. using GTK Inspector for debug css

Run guake by command:

```shell
GTK_DEBUG=interactive make local-run
```

it will run guake and GTK Inspector :

![](README.images/gtk-inspector-1.png)


do as above image to inspect element in guake, it will show as below

![](README.images/gtk-inspector-2.png)

choose another function: CSS nodes as bellow

![](README.images/gtk-inspector-3.png)

you can see above image to know how to get right css selector and set attribute for it

in above image, we got css selector for selected tab in guake terminal, then set its box-shadow color to highlight selected tab

you can test your css by switch to css tab

![](README.images/gtk-inspector-4.png)

## 4.3. references

https://blog.gtk.org/2017/04/05/the-gtk-inspector/

https://gtkthemingguide.vercel.app/#/creating_gtk_themes?id=selectors

# 5. cherry-pick and rebase into one commit

```shell
# create new branch to cherry-pick
git checkout -b xuananh-add-new-feature-mapping-file-path-to-open-in-vscode xuananh-backup

# reset new branch to the commit from that XuanAnh start add new commit
git checkout master
git branch -f xuananh-add-new-feature-mapping-file-path-to-open-in-vscode c3f3a60d943ece1918aad3f077118145d9f61aeb
git checkout xuananh-add-new-feature-mapping-file-path-to-open-in-vscode

# cherry pick 11 commits from branch xuananh-backup
git cherry-pick d685fe66132fc5f4c811dbae90a27bd7154e7840
git cherry-pick 78f69d20cb8d5cc0bd27a15d090cbc2c98ce6a5a
git cherry-pick 417fcbc82ab6420928dfaf666511855b73438040
git cherry-pick f1efff96d51f921d42874e04399d7b65358aa47b
git cherry-pick 2162ce10374b493374c36fc1f899e02d3a55c008
git cherry-pick f0d06d0c5023991f5977e5f2b437ab4ceea653e4
git cherry-pick 93cbcbe445f012e5264b303ac364665b173e7231
git cherry-pick 1cb171f96f08d04577261df43abd17bedb57fdd9
git cherry-pick 9a13c20707b9841812fb223628676e38146340a3
git cherry-pick 0348b2988d03e8290cbf0dbd91457b61078f44b0
git cherry-pick 286977fcf754168ca7e13dd0ec8fa92cec60f824

# create new branch to rebase
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

# rebase above 11 commits, reference on how to rebase
# https://www.freecodecamp.org/news/git-squash-commits/
# https://stackoverflow.com/a/21278908
git rebase --interactive HEAD~11

# create new branch with shorter name
git checkout -b xuananh xuananh-add-new-feature-mapping-file-path-to-open-in-vscode-rebased

```
20 changes: 19 additions & 1 deletion guake/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ def get_current_directory(self):
directory = cwd
return directory

def mapping_file_path(self, current_path) -> Path:
"""xuananh
"""
import json
cwd = self.get_current_directory()
mapping_paths = json.load(open(cwd + '/.guake.json', 'r'))
default_mapping = {
"/usr/local": cwd + "/.venv"
}
mapping_paths.update(default_mapping)
for key, value in mapping_paths.items():
if key in current_path:
new_path = current_path.replace(key, value, 1) # NOTE: only replace the first occurenc
return new_path
return current_path

def is_file_on_local_server(self, text) -> Tuple[Optional[Path], Optional[int], Optional[int]]:
"""Test if the provided text matches a file on local server
Expand Down Expand Up @@ -323,7 +339,7 @@ def find_lineno(text, pt, lineno, py_func):
if line.startswith(f"def {py_func}"):
return i + 1
break

text = self.mapping_file_path(text)
pt = Path(text)
log.debug("checking file existance: %r", pt)
try:
Expand Down Expand Up @@ -409,6 +425,8 @@ def _on_ctrl_click_matcher(self, matched_string):
use_quick_open = self.guake.settings.general.get_boolean("quick-open-enable")
if use_quick_open:
found_matcher = self._find_quick_matcher(value)
else:
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")
if not found_matcher:
self.found_link = self.handleTerminalMatch(matched_string)
if self.found_link:
Expand Down

0 comments on commit 6e496be

Please sign in to comment.