External Commands¶
All commands in this section rely on another tool or piece of software.
The scripts therein collectively automate use of git,
Neovim, conda, and IPython
.
g
¶
g — Programmatically work with subprocess’ and Git.¶
This module intends to build a base class through subprocesses in order to build up a trimmed-down, and more importantly safer Git object.
Subprocess and Git¶
Currently we need to move some module functions into our BaseCommand class. I don’t want it to attempt implementing too much however. But it should have a method that checks output in the way that our module function does for the git rev-parse expression that sets up the git root.
You know what would be nice? Run the following commands in one.
git branch -d foo
git branch -rd origin/foo
git push origin :foo
There’s no reason that that’s 3 commands with differing syntax.
All you need to do is check if the branch exists both locally and remotely and kill everything.
-
class
pyutil.g.
Git
(root=None, **kwargs)[source] Bases:
pyutil.shell.BaseCommand
Create a base class for working with Git in Python.
For the time being we only really need to run the
g.BaseCommand.run()
What other parameters do we need to pay attention to? State that would be useful to grab? Silencing the warnings aboutversion
is a start. So I guess learning how to properly initialize a class.-
_check_output
(self, cmd, **kwargs)[source] Checks output from a subprocess call.
-
_get_git_root
(self)[source] Show the root of a repo.
-
static
_quote
(self, cmd)[source] Which one of these two is preferable?
-
_quote_cmd
(self, cmd)[source] Maybe this should be in the parent class?
-
get_git_upstream_remote
(self)[source] Get the remote name to use for upstream branches.
- Returns
str – Uses “upstream” if it exists, “origin” otherwise
- Return type
Remote git server
-
property
version
[source] Return the version of Git we have.
-
-
class
pyutil.g.
Other
(root=None, version=None)[source] Bases:
object
Toy code always refers to other I.E. self != other. Let’s write other!
Haha just kidding. I’m testing out Git but one that doesn’t subclass anything because the parent class is having problems
-
_get_git_root
(self)[source] Show the root of a repo.
-
-
pyutil.g.
get_git_branch
()[source] Get the symbolic name for the current git branch.
nvim_profiling
¶
Automate profiling nvim.
Nvim Profiler¶
Attaching to a remote instance from the REPL¶
The below code displays how to attach to a remote neovim instance.:
>>> if not os.environ.get('NVIM_LISTEN_ADDRESS'): # we have no running nvim
>>> subprocess.run(['nvim&']) # are we allowed to do this?
>>> import pynvim
>>> vim = pynvim.attach('socket', path=os.environ.get('NVIM_LISTEN_ADDRESS'))
>>> vim.command('edit $MYVIMRC')
>>> vim_root = vim.current.buffer
Finding the initialization file to profile¶
Here’s the help documentation on how to find an init.vim
file assuming it’s placed
in the standard location I.E. ~/.config/nvim
or USERPROFILE
AppDataLocalnvim.
stdpath({what}) *stdpath()* *E6100*
Returns |standard-path| locations of various default files and directories.
{what} Type Description ~
cache String Cache directory. Arbitrary temporary
storage for plugins, etc.
config String User configuration directory. The
|init.vim| is stored here.
config_dirs List Additional configuration directories.
data String User data directory. The |shada-file|
is stored here.
data_dirs List Additional data directories.
Example:
:echo stdpath("config")
Roadmap¶
In the future this module is going to move towards implementing a command that will behave similarly to the following command run in the shell:
nvim --startuptime test.txt test.py test.txt -c"bn"
# Also we could make the base command
nvim --clean --startuptime foo.log example_module.py foo.log -c'bn'
-
class
pyutil.nvim_profiling.
Neovim
(exe=None)[source]¶ Bases:
object
Instantiate a connection to neovim if it’s running, establish the path if not.
Got to the point where I thought:
Let’s just rewrite this module.
-
pyutil.nvim_profiling.
main
(nvim_root)[source]¶ Profile nvim.
- Parameters
nvim_root (str) – The directory where nvim’s configuration files are found.
- Returns
profiling_log_file – Creates file based on the current time in ISO format profiling nvim.
- Return type
Todo
Allow the
test.py
file that we use for startup to be configured.
-
pyutil.nvim_profiling.
output_results
(output_dir)[source]¶ Checks that an directory named profiling exists.
IPython has a function in
IPython.utils
that I believe is called ensure_dir_exists. Do we provide anything that that implementation doesn’t?- Parameters
output_dir (str) – Directory to store profiling results in.
- Returns
- Return type
Bool