From Newsgroup: gnu.emacs.help
Axel Reichert <
mail@axel-reichert.de> writes:
Cecil Westerhof <Cecil@decebal.nl> writes:
When I do:
(setq pip-version (shell-command-to-string "pip3 --version"))
pip-version contains:
"pip 22.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9) >> "
How do I get the fourth word with the characters after the last /
removed? (/usr/local/lib/python3.9/dist-packages/)
(file-name-directory (nth 3 (split-string pip-version)))
See
https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/List-Elements.html
The Emacs Lisp documentation is great, but for non-Lispers it might be a rough ride initially.
https://www.gnu.org/software/emacs/manual/eintr.html
will get you started. Have fun learning an old, but great language!
Created this function:
;; check used characters
(defun dcbl-get-pip-info (&optional package blocking-package)
(setq pip "pip"
lastpart ".dist-info/METADATA")
(setq pip-version-information (split-string (shell-command-to-string
"pip --version"))
pip-command (nth 0 pip-version-information)
pip-version (nth 1 pip-version-information)
pip-path (file-name-directory
(nth 3 pip-version-information)))
(if (not package)
(if (not blocking-package)
(find-file-read-only (concat pip-path pip-command "-" pip-version
lastpart))
(error "When package is nil blocking-package should also be nil"))
(setq package-version (nth 3 (split-string (shell-command-to-string
"pip show requests"))))
(find-file-read-only (concat pip-path package "-" package-version
lastpart))
(if blocking-package
(search-forward blocking-package))
))
I wanted to know why a blocking-package blocked a package from being
installed, but then thought it is also interesting to get information
about the package and pip. So I also created the other two.
If the code can be optimised I do not mind to hear that.
I still have to check that package and blocking-package do not contain
wrong characters. But I think I will manage that.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn:
http://www.linkedin.com/in/cecilwesterhof
--- Synchronet 3.21d-Linux NewsLink 1.2