diff --git a/.gitignore b/.gitignore index f8990dc04..671550675 100644 --- a/.gitignore +++ b/.gitignore @@ -76,7 +76,6 @@ ChangeLog .direnv .envrc .venv -.vscode/ guake/data/gschemas.compiled .pytest_cache/ diff --git a/.guake.json b/.guake.json new file mode 100644 index 000000000..c4a10a2e5 --- /dev/null +++ b/.guake.json @@ -0,0 +1,3 @@ +{ + "/app": "/home/xuananh/repo/guake/guake" +} \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 000000000..a5c4c7633 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9.0 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..9307e867b --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 38c46c0a6..ab6434d72 100644 --- a/Makefile +++ b/Makefile @@ -479,3 +479,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 diff --git a/README.images/gtk-inspector-1.png b/README.images/gtk-inspector-1.png new file mode 100644 index 000000000..881cf1b6c Binary files /dev/null and b/README.images/gtk-inspector-1.png differ diff --git a/README.images/gtk-inspector-2.png b/README.images/gtk-inspector-2.png new file mode 100644 index 000000000..a10c68d30 Binary files /dev/null and b/README.images/gtk-inspector-2.png differ diff --git a/README.images/gtk-inspector-3.png b/README.images/gtk-inspector-3.png new file mode 100644 index 000000000..2b8c62c3e Binary files /dev/null and b/README.images/gtk-inspector-3.png differ diff --git a/README.images/gtk-inspector-4.png b/README.images/gtk-inspector-4.png new file mode 100644 index 000000000..ffb6ba8d5 Binary files /dev/null and b/README.images/gtk-inspector-4.png differ diff --git a/README.md b/README.md new file mode 100644 index 000000000..da47a352a --- /dev/null +++ b/README.md @@ -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 + +``` \ No newline at end of file diff --git a/guake/terminal.py b/guake/terminal.py index ffe353bc9..a5152b526 100644 --- a/guake/terminal.py +++ b/guake/terminal.py @@ -258,6 +258,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 @@ -310,7 +326,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: @@ -394,6 +410,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: diff --git a/requirements-dev.txt b/requirements-dev.txt index f5b292d48..1cb2e4f40 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -15,9 +15,10 @@ astroid autopep8 black==21.8b0 colorlog -dephell fiximports>=0.1.18 -flake8 +flake8>=3.8.0,<4.0.0 +flakehell +mock>=2.0.0 pathlib2 pep8 pew @@ -29,9 +30,10 @@ pytest pytest-cov pytest-mock reno[sphinx]>=2.8.0 -scandir ; python_version < '3.5' +scandir ; python_version > '3.5' sphinx-rtd-theme sphinxcontrib-programoutput +toml twine typed-ast yapf diff --git a/requirements.txt b/requirements.txt index e0ce56468..9088bc835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,5 +10,6 @@ # `Pipfile.lock` and then regenerate `requirements*.txt`. ################################################################################ -importlib_metadata; python_version < '3.8' -typing ; python_version < '3.5' +pbr +typing ; python_version > '3.5' +wheel