Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix envision resource path #1682

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Fixed a bug with the `TripMeterSensor` that was not using a unit direction vector to calculate trip distance against current route.
- Fixed issues with Envision. The playback bar and realtime mode now work as expected.
- Fixed a bug where traffic history vehicles would not get traffic signal observations
- Fixed a bug where envision would not work in some versions of python due to nuances of `importlib.resource.path()`.

## [0.6.1]
### Added
Expand Down
46 changes: 24 additions & 22 deletions envision/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import json
import logging
import math
import os
import random
import signal
import sys
Expand Down Expand Up @@ -489,27 +490,28 @@ def get(self):
def make_app(scenario_dirs: Sequence, max_capacity_mb: float, debug: bool):
"""Create the envision web server application through composition of services."""

with pkg_resources.path(web_dist, ".") as dist_path:
return tornado.web.Application(
[
(r"/", MainHandler),
(r"/simulations", SimulationListHandler),
(r"/simulations/(?P<simulation_id>\w+)/state", StateWebSocket),
(
r"/simulations/(?P<simulation_id>\w+)/broadcast",
BroadcastWebSocket,
dict(max_capacity_mb=max_capacity_mb),
),
(
r"/assets/maps/(.*)",
MapFileHandler,
dict(scenario_dirs=scenario_dirs),
),
(r"/assets/models/(.*)", ModelFileHandler),
(r"/(.*)", tornado.web.StaticFileHandler, dict(path=str(dist_path))),
],
debug=debug,
)
dist_path = Path(os.path.dirname(web_dist.__file__)).parent
logging.debug("Creating app with resources at: `%s`", dist_path)
return tornado.web.Application(
[
(r"/", MainHandler),
(r"/simulations", SimulationListHandler),
(r"/simulations/(?P<simulation_id>\w+)/state", StateWebSocket),
(
r"/simulations/(?P<simulation_id>\w+)/broadcast",
BroadcastWebSocket,
dict(max_capacity_mb=max_capacity_mb),
),
(
r"/assets/maps/(.*)",
MapFileHandler,
dict(scenario_dirs=scenario_dirs),
),
(r"/assets/models/(.*)", ModelFileHandler),
(r"/(.*)", tornado.web.StaticFileHandler, dict(path=str(dist_path))),
],
debug=debug,
)


def on_shutdown():
Expand All @@ -527,7 +529,7 @@ def run(
"""Create and run an envision web server."""
app = make_app(scenario_dirs, max_capacity_mb, debug=debug)
app.listen(port)
logging.debug(f"Envision listening on port={port}")
logging.debug("Envision listening on port=%s", port)

ioloop = tornado.ioloop.IOLoop.current()
signal.signal(
Expand Down
140 changes: 0 additions & 140 deletions smarts/sstudio/build_scenario.py

This file was deleted.

56 changes: 28 additions & 28 deletions smarts/sstudio/scenario_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,38 +103,38 @@ def clean_scenario(scenario: str):


def _install_requirements(scenario_root, log: Optional[Callable[[Any], None]] = None):
import importlib.resources as pkg_resources
import os

requirements_txt = scenario_root / "requirements.txt"
if requirements_txt.exists():
import zoo.policies

with pkg_resources.path(zoo.policies, "") as path:
# Serve policies through the static file server, then kill after
# we've installed scenario requirements
pip_index_proc = subprocess.Popen(
["twistd", "-n", "web", "--path", path],
# Hide output to keep display simple
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
path = Path(os.path.dirname(zoo.policies.__file__)).parent
# Serve policies through the static file server, then kill after
# we've installed scenario requirements
pip_index_proc = subprocess.Popen(
["twistd", "-n", "web", "--path", path],
# Hide output to keep display simple
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)

pip_install_cmd = [
sys.executable,
"-m",
"pip",
"install",
"-r",
str(requirements_txt),
]

if log is not None:
log(
f"Installing scenario dependencies via '{' '.join(pip_install_cmd)}'"
)
pip_install_cmd = [
sys.executable,
"-m",
"pip",
"install",
"-r",
str(requirements_txt),
]

if log is not None:
log(
f"Installing scenario dependencies via '{' '.join(pip_install_cmd)}'"
)

try:
subprocess.check_call(pip_install_cmd, stdout=subprocess.DEVNULL)
finally:
pip_index_proc.terminate()
pip_index_proc.wait()
try:
subprocess.check_call(pip_install_cmd, stdout=subprocess.DEVNULL)
finally:
pip_index_proc.terminate()
pip_index_proc.wait()