Skip to content

Commit

Permalink
Patch for python_interpreter setting
Browse files Browse the repository at this point in the history
  • Loading branch information
scuml committed Oct 18, 2020
1 parent 5424bb3 commit 5bc3ab7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ Main.sublime-menu
.mypy_cache/
poetry.lock
pyproject.toml
.env
2 changes: 0 additions & 2 deletions anaconda_lib/import_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
62 changes: 62 additions & 0 deletions anaconda_server/autoreload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
#
# Autoreloader for jsonserver for development.
# Run with:
# python3 autoreload.py python3 jsonserver.py -p<project_name> 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)
2 changes: 0 additions & 2 deletions anaconda_server/handlers/jedi_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5bc3ab7

Please sign in to comment.