Skip to content

Commit 2dbeb11

Browse files
authored
Merge pull request #60 from ghost-in-moss/version/0.1.5
relase: version 0.1.5
2 parents 96d2221 + da5ac05 commit 2dbeb11

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
first release version.
77

8+
## v0.1.5
9+
10+
* `ghostos web` add `--src` option, load the directory to python path, make sure can import relative packages.
11+
* fix `.ghostos.yml` with relative path, in case share project with absolute local filepath.
12+
813
## v0.1.4
914

1015
add llm driver supporting openai azure api.

ghostos/bootstrap.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,10 @@ def find_workspace_dir() -> str:
110110

111111
class BootstrapConfig(BaseModel):
112112
workspace_dir: str = Field(
113-
default_factory=find_workspace_dir,
114-
description="ghostos workspace directory",
113+
default="app",
114+
description="ghostos relative workspace directory",
115115
)
116116
dotenv_file_path: str = Field(".env", description="ghostos workspace .env file")
117-
ghostos_dir: str = Field(
118-
default=dirname(dirname(__file__)),
119-
description="ghostos source code directory",
120-
)
121117
workspace_configs_dir: str = Field(
122118
"configs",
123119
description="ghostos workspace relative path for configs directory",
@@ -129,19 +125,34 @@ class BootstrapConfig(BaseModel):
129125

130126
__from_file__: str = ""
131127

128+
@staticmethod
129+
def abs_ghostos_dir() -> str:
130+
return dirname(dirname(__file__))
131+
132+
def abs_workspace_dir(self) -> str:
133+
from os.path import abspath, exists, isdir
134+
app_dir = abspath(self.workspace_dir)
135+
if exists(app_dir) and isdir(app_dir):
136+
return app_dir
137+
return find_workspace_dir()
138+
132139
def abs_runtime_dir(self) -> str:
133-
return join(self.workspace_dir, "runtime")
140+
workspace_dir = self.abs_workspace_dir()
141+
return join(workspace_dir, "runtime")
134142

135143
def abs_asserts_dir(self) -> str:
136-
return join(self.workspace_dir, "assets")
144+
workspace_dir = self.abs_workspace_dir()
145+
return join(workspace_dir, "assets")
137146

138147
def env_file(self) -> str:
139-
return join(self.workspace_dir, self.dotenv_file_path)
148+
workspace_dir = self.abs_workspace_dir()
149+
return join(workspace_dir, self.dotenv_file_path)
140150

141151
def env_example_file(self) -> str:
142-
return join(self.workspace_dir, ".example.env")
152+
workspace_dir = self.abs_workspace_dir()
153+
return join(workspace_dir, ".example.env")
143154

144-
def save(self, dir_path: str = None):
155+
def save(self, dir_path: str = None) -> str:
145156
from ghostos.helpers import yaml_pretty_dump
146157
if dir_path is None:
147158
filename = join(abspath(".ghostos.yml"))
@@ -150,6 +161,7 @@ def save(self, dir_path: str = None):
150161
content = yaml_pretty_dump(self.model_dump())
151162
with open(filename, "w") as f:
152163
f.write(content)
164+
return filename
153165

154166

155167
def get_bootstrap_config(local: bool = True) -> BootstrapConfig:
@@ -273,7 +285,7 @@ def default_application_providers(
273285
DefaultLoggerProvider(),
274286
# --- workspace --- #
275287
BasicWorkspaceProvider(
276-
workspace_dir=config.workspace_dir,
288+
workspace_dir=config.abs_workspace_dir(),
277289
configs_path=config.workspace_configs_dir,
278290
runtime_path=config.workspace_runtime_dir,
279291
),
@@ -327,7 +339,7 @@ def make_app_container(
327339
if bootstrap_conf is None:
328340
bootstrap_conf = get_bootstrap_config(local=True)
329341
workspace_dir = bootstrap_conf.workspace_dir
330-
if workspace_dir.startswith(bootstrap_conf.ghostos_dir):
342+
if workspace_dir.startswith(bootstrap_conf.abs_ghostos_dir()):
331343
warn(
332344
f"GhostOS workspace dir is not found, better run `ghostos init` at first."
333345
f"Currently using `{workspace_dir}` as workspace."

ghostos/scripts/cli/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ def main():
1717

1818
@main.command("web")
1919
@click.argument("python_file_or_module")
20-
def start_streamlit_web(python_file_or_module: str):
20+
@click.option("--src", "-s", default=".", show_default=True)
21+
def start_streamlit_web(python_file_or_module: str, src: str):
2122
"""
2223
turn a python file or module into a streamlit web agent
2324
"""
2425
from ghostos.scripts.cli.run_streamlit_app import start_ghost_app
2526
from ghostos.scripts.cli.utils import find_ghost_by_file_or_module
27+
import sys
28+
from os.path import abspath
29+
if src:
30+
# add source path to system so to import the source code.
31+
sys.path.append(abspath(src))
32+
2633
ghost_info, module, filename, is_temp = find_ghost_by_file_or_module(python_file_or_module)
2734
start_ghost_app(ghost_info, module.__name__, filename, is_temp)
2835

@@ -44,7 +51,11 @@ def start_web_config():
4451
"""
4552
from ghostos.scripts.cli.run_streamlit_app import start_streamlit_prototype_cli
4653
from ghostos.bootstrap import get_bootstrap_config
47-
start_streamlit_prototype_cli("run_configs.py", "", get_bootstrap_config().workspace_dir)
54+
start_streamlit_prototype_cli(
55+
"run_configs.py",
56+
"",
57+
get_bootstrap_config().abs_workspace_dir(),
58+
)
4859

4960

5061
@main.command("clear-runtime")
@@ -86,18 +97,19 @@ def init_app(path: str):
8697
))
8798

8899
conf = get_bootstrap_config(local=False)
100+
cwd = getcwd()
89101
result = Prompt.ask(
90-
f"\n>> will init ghostos workspace at `{getcwd()}`. input directory name:",
102+
f"\n>> will init ghostos workspace at `{cwd}`. input directory name:",
91103
default="app",
92104
)
93-
source_dir = join(conf.ghostos_dir, "ghostos/app")
105+
source_dir = app_stub_dir()
94106
real_workspace_dir = abspath(result)
95107
console.print("start to init ghostos workspace")
96108
copy_workspace(source_dir, real_workspace_dir)
97109
console.print("ghostos workspace copied")
98-
conf.workspace_dir = real_workspace_dir
99-
conf.save(real_workspace_dir)
100-
console.print("save .ghostos.yml")
110+
conf.workspace_dir = result
111+
saved_file = conf.save(cwd)
112+
console.print(f"save .ghostos.yml to {saved_file}")
101113
console.print(Panel(Markdown(f"""
102114
Done create workspace!
103115

ghostos/scripts/cli/run_streamlit_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_config_flag_options(workspace_dir: str) -> List[str]:
4444
def start_ghost_app(ghost_info: GhostInfo, modulename: str, filename: str, is_temp: bool):
4545
# path
4646
conf = get_bootstrap_config(local=True)
47-
workspace_dir = conf.workspace_dir
47+
workspace_dir = conf.abs_workspace_dir()
4848
args = RunGhostChatApp(
4949
modulename=modulename,
5050
filename=filename,
@@ -53,7 +53,7 @@ def start_ghost_app(ghost_info: GhostInfo, modulename: str, filename: str, is_te
5353
ghost_meta=ghost_info.ghost,
5454
context_meta=ghost_info.context,
5555
)
56-
start_streamlit_prototype_cli("run_ghost_chat.py", args.model_dump_json(), conf.workspace_dir)
56+
start_streamlit_prototype_cli("run_ghost_chat.py", args.model_dump_json(), workspace_dir)
5757

5858

5959
def start_streamlit_prototype_cli(filename: str, cli_args: str, workspace_dir: str):

ghostos/scripts/copy_workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
)
3636
parsed = parser.parse_args(sys.argv[1:])
3737
target_dir = abspath(parsed.target)
38-
copy_workspace(conf.workspace_dir, target_dir)
38+
copy_workspace(conf.abs_workspace_dir(), target_dir)
3939
print(f"Copied skeleton files to {target_dir}")
4040

4141

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ghostos"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "A framework offers an operating system simulator with a Python Code Interface for AI Agents"
55
authors = ["zhuming <thirdgerb@gmail.com>", "Nile Zhou <nilezhou123@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)