Skip to content

Commit

Permalink
fix: robyn dev loading bug (#743)
Browse files Browse the repository at this point in the history
* fix: robyn dev loading bug

* fix bug

* fix types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
sansyrox and pre-commit-ci[bot] authored Jan 23, 2024
1 parent afe1745 commit 1b64c9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions robyn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def start_dev_server(config: Config, file_path: Optional[str] = None):
if file_path is None:
return

directory_path = Path.cwd()
absolute_file_path = (directory_path / file_path).resolve()
absolute_file_path = (Path.cwd() / file_path).resolve()
directory_path = absolute_file_path.parent

if config.dev and not os.environ.get("IS_RELOADER_RUNNING", False):
setup_reloader(str(directory_path), str(absolute_file_path))
Expand Down
13 changes: 6 additions & 7 deletions robyn/reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys
import time
from typing import List

from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
Expand All @@ -29,7 +30,7 @@ def compile_rust_files(directory_path: str):
else:
print("Compiled rust file : %s", rust_file)

return True
return rust_files


def create_rust_file(file_name: str):
Expand All @@ -51,12 +52,9 @@ def create_rust_file(file_name: str):
print("Created rust file : %s", rust_file)


def clean_rust_build(directory_path: str, file_path: str):
rust_binaries = glob.glob(os.path.join(directory_path, "**/*.so"), recursive=True)

def clean_rust_binaries(rust_binaries: List[str]):
for file in rust_binaries:
print("Cleaning rust file : %s", file)

os.remove(file)


Expand Down Expand Up @@ -97,6 +95,7 @@ def __init__(self, file_path: str, directory_path: str) -> None:
self.file_path = file_path
self.directory_path = directory_path
self.process = None # Keep track of the subprocess
self.built_rust_binaries = [] # Keep track of the built rust binaries

self.last_reload = time.time() # Keep track of the last reload. EventHandler is initialized with the process.

Expand All @@ -113,8 +112,8 @@ def reload(self):
print(f"Reloading {self.file_path}...")
arguments = [arg for arg in sys.argv[1:] if not arg.startswith("--dev")]

clean_rust_build(self.directory_path, self.file_path)
compile_rust_files(self.directory_path)
clean_rust_binaries(self.built_rust_binaries)
self.built_rust_binaries = compile_rust_files(self.directory_path)

self.process = subprocess.Popen(
[sys.executable, *arguments],
Expand Down

0 comments on commit 1b64c9e

Please sign in to comment.