From 5bc3ab7e35c9e0ac91a0d0428d3cc7011c547dd0 Mon Sep 17 00:00:00 2001 From: Stephen Mitchell Date: Sun, 18 Oct 2020 13:28:37 -0400 Subject: [PATCH] Patch for python_interpreter setting --- .gitignore | 1 + anaconda_lib/import_validator.py | 2 - anaconda_server/autoreload.py | 62 ++++++++++++++++++++++++ anaconda_server/handlers/jedi_handler.py | 2 - 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 anaconda_server/autoreload.py diff --git a/.gitignore b/.gitignore index 94a1fb74..f7a54a5b 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ Main.sublime-menu .mypy_cache/ poetry.lock pyproject.toml +.env diff --git a/anaconda_lib/import_validator.py b/anaconda_lib/import_validator.py index b93cb38d..5495337e 100644 --- a/anaconda_lib/import_validator.py +++ b/anaconda_lib/import_validator.py @@ -39,8 +39,6 @@ def _validate_import(self, module_line, lineno): return True jedi_project = get_default_project(self.filename) - if self.settings.get("python_interpreter", "") != "": - jedi_project._environment_path = self.settings.get("python_interpreter") error = [] error_string = 'can\'t import {0}' diff --git a/anaconda_server/autoreload.py b/anaconda_server/autoreload.py new file mode 100755 index 00000000..4b4f2aeb --- /dev/null +++ b/anaconda_server/autoreload.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# +# Autoreloader for jsonserver for development. +# Run with: +# python3 autoreload.py python3 jsonserver.py -p 9999 DEBUG +# + +import os +import sys +import subprocess +import time +from pathlib import Path + + +def file_filter(path): + return (not path.name.startswith(".")) and (path.suffix not in (".swp",) ) + + +def file_times(path): + absolute_path = path.resolve() + for file in filter(file_filter, absolute_path.iterdir()): + if file.is_dir(): + for x in file_times(file): + yield x + else: + yield os.path.getctime(file) + + +def print_stdout(process): + stdout = process.stdout + if stdout != None: + print(stdout) + stderr = process.stderr + if stderr != None: + print(stderr) + + +# We concatenate all of the arguments together, and treat that as the command to run +command = " ".join(sys.argv[1:]) + +# The path to watch +path = Path("..") + +# How often we check the filesystem for changes (in seconds) +wait = 1 + +# The process to autoreload +print("Started: ", command) +process = subprocess.Popen(command, shell=True) + +# The current maximum file modified time under the watched directory +last_mtime = max(file_times(path)) + +while True: + max_mtime = max(file_times(path)) + print_stdout(process) + if max_mtime > last_mtime: + last_mtime = max_mtime + print("Restarting process.") + process.kill() + process = subprocess.Popen(command, shell=True) + time.sleep(wait) diff --git a/anaconda_server/handlers/jedi_handler.py b/anaconda_server/handlers/jedi_handler.py index da106458..02f54c66 100644 --- a/anaconda_server/handlers/jedi_handler.py +++ b/anaconda_server/handlers/jedi_handler.py @@ -49,8 +49,6 @@ def jedi_script( """Generate an usable Jedi Script """ jedi_project = jedi.get_default_project(filename) - if self.settings.get("python_interpreter", "") != "": - jedi_project._environment_path = self.settings.get("python_interpreter") return jedi.Script( source, int(line), int(offset), filename, encoding, project=jedi_project)