-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #881 from scuml/python_interpreter_patch
Python interpreter patch
- Loading branch information
Showing
4 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,4 @@ Main.sublime-menu | |
.mypy_cache/ | ||
poetry.lock | ||
pyproject.toml | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters