python: Move to separate file
This commit is contained in:
parent
83b38ddf61
commit
8f370c5040
5 changed files with 56 additions and 42 deletions
|
@ -50,11 +50,6 @@
|
|||
] ++ lib.optionals (config.frogeye.desktop.xorg && config.frogeye.dev.fpga) [
|
||||
yosys
|
||||
gtkwave
|
||||
|
||||
# Python
|
||||
] ++ lib.optionals config.frogeye.dev.python [
|
||||
python3Packages.ipython
|
||||
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
56
hm/dev/python.nix
Normal file
56
hm/dev/python.nix
Normal file
|
@ -0,0 +1,56 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
{
|
||||
config = lib.mkIf config.frogeye.dev.python {
|
||||
frogeye = {
|
||||
shellAliases = {
|
||||
ipython = "ipython --no-confirm-exit --pdb";
|
||||
};
|
||||
};
|
||||
home = {
|
||||
packages = with pkgs; [
|
||||
python3
|
||||
python3Packages.ipython
|
||||
];
|
||||
sessionVariables = {
|
||||
PYTHONSTARTUP = "${config.xdg.configHome}/pythonstartup.py";
|
||||
};
|
||||
};
|
||||
programs.nixvim.plugins.lsp.servers.pylsp = {
|
||||
# Python
|
||||
enable = config.frogeye.dev.python;
|
||||
settings.plugins = {
|
||||
black.enabled = true;
|
||||
flake8 = {
|
||||
enabled = true;
|
||||
maxLineLength = 88; # Compatibility with Black
|
||||
};
|
||||
isort.enabled = true;
|
||||
mccabe.enabled = true;
|
||||
pycodestyle = {
|
||||
enabled = true;
|
||||
maxLineLength = 88; # Compatibility with Black
|
||||
};
|
||||
pyflakes.enabled = true;
|
||||
pylint.enabled = true;
|
||||
pylsp_mypy = {
|
||||
enabled = true;
|
||||
overrides = [
|
||||
"--cache-dir=${config.xdg.cacheHome}/mypy"
|
||||
"--ignore-missing-imports"
|
||||
"--disallow-untyped-defs"
|
||||
"--disallow-untyped-calls"
|
||||
"--disallow-incomplete-defs"
|
||||
"--disallow-untyped-decorators"
|
||||
true
|
||||
];
|
||||
};
|
||||
# TODO Could add some, could also remove some
|
||||
};
|
||||
};
|
||||
xdg.configFile = {
|
||||
"pythonstartup.py" = {
|
||||
text = (builtins.readFile ./pythonstartup.py);
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
47
hm/dev/pythonstartup.py
Normal file
47
hm/dev/pythonstartup.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# From https://github.com/python/cpython/blob/v3.7.0b5/Lib/site.py#L436
|
||||
# Changing the history file
|
||||
def register_readline() -> None:
|
||||
import atexit
|
||||
try:
|
||||
import readline
|
||||
import rlcompleter
|
||||
except ImportError:
|
||||
return
|
||||
|
||||
# Reading the initialization (config) file may not be enough to set a
|
||||
# completion key, so we set one first and then read the file.
|
||||
readline_doc = getattr(readline, '__doc__', '')
|
||||
if readline_doc is not None and 'libedit' in readline_doc:
|
||||
readline.parse_and_bind('bind ^I rl_complete')
|
||||
else:
|
||||
readline.parse_and_bind('tab: complete')
|
||||
|
||||
try:
|
||||
readline.read_init_file()
|
||||
except OSError:
|
||||
# An OSError here could have many causes, but the most likely one
|
||||
# is that there's no .inputrc file (or .editrc file in the case of
|
||||
# Mac OS X + libedit) in the expected location. In that case, we
|
||||
# want to ignore the exception.
|
||||
pass
|
||||
|
||||
if readline.get_current_history_length() == 0:
|
||||
# If no history was loaded, default to .python_history.
|
||||
# The guard is necessary to avoid doubling history size at
|
||||
# each interpreter exit when readline was already configured
|
||||
# through a PYTHONSTARTUP hook, see:
|
||||
# http://bugs.python.org/issue5845#msg198636
|
||||
history = os.path.join(os.path.expanduser('~'),
|
||||
'.cache/python_history')
|
||||
try:
|
||||
readline.read_history_file(history)
|
||||
except OSError:
|
||||
pass
|
||||
atexit.register(readline.write_history_file, history)
|
||||
|
||||
sys.__interactivehook__ = register_readline
|
Loading…
Add table
Add a link
Reference in a new issue