Skip to content

Commit

Permalink
cleanup: some changes for better windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Sep 19, 2024
1 parent b5aad15 commit 1c3ee0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
PYTHON_FILES=lib/src/prelude.py bin/src/invoke.py build.py

build:
./build.py build

install:
./build.py install

format:
uv run ruff format lib/src/prelude.py
uv run ruff format bin/src/invoke.py
uv run ruff format build.py
uv run ruff format $(PYTHON_FILES)

check:
uv run ruff check lib/src/prelude.py
uv run ruff check bin/src/invoke.py
uv run ruff check build.py
uv run ruff check $(PYTHON_FILES)

clean:
rm -rf bin/target lib/target
Expand Down
2 changes: 1 addition & 1 deletion bin/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn find_deps() -> PathBuf {

directories::BaseDirs::new()
.unwrap()
.data_local_dir()
.data_dir()
.join("extism-py")
}

Expand Down
23 changes: 15 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def bin_dir() -> Path:
if system in ["linux", "darwin"]:
return home / ".local" / "bin"
elif system == "windows":
return Path(os.getenv("APPDATA")) / "Python" / "Scripts"
return Path(os.getenv("USERHOME"))
else:
raise OSError(f"Unsupported OS {system}")

Expand All @@ -42,6 +42,13 @@ def data_dir() -> Path:
raise OSError(f"Unsupported OS {system}")


def exe_file() -> str:
if system == "windows":
return "extism-py.exe"
else:
return "extism-py"


def run_subprocess(command, cwd=None, quiet=False):
try:
logging.info(f"Running command: {' '.join(command)} in {cwd or '.'}")
Expand Down Expand Up @@ -78,7 +85,7 @@ def do_build(args):
check_rust_installed()
run_subprocess(["cargo", "build", "--release"], cwd="./lib", quiet=args.quiet)
run_subprocess(["cargo", "build", "--release"], cwd="./bin", quiet=args.quiet)
shutil.copy2(Path("./bin/target/release/extism-py"), Path("./extism-py"))
shutil.copy2(Path("./bin/target/release") / exe_file(), Path(".") / exe_file())
logging.info("Build completed successfully.")


Expand All @@ -89,16 +96,16 @@ def do_install(args):
bin_dir.mkdir(parents=True, exist_ok=True)
data_dir.mkdir(parents=True, exist_ok=True)

dest_path = bin_dir / "extism-py"
dest_path = bin_dir / exe_file()
logging.info(f"Copying binary to {dest_path}")
shutil.copy2(Path("./bin/target/release/extism-py"), dest_path)
shutil.copy2(Path("./bin/target/release") / exe_file(), dest_path)

logging.info(f"Copying data files to {data_dir}")
shutil.copytree(
Path("./lib/target/wasm32-wasi/wasi-deps/usr"), data_dir, dirs_exist_ok=True
)

logging.info(f"extism-py installed to {bin_dir}")
logging.info(f"{exe_file()} installed to {bin_dir}")
logging.info(f"Data files installed to {data_dir}")
logging.info("Installation completed successfully.")

Expand All @@ -107,15 +114,15 @@ def do_clean(args):
logging.info("Cleaning build artifacts...")
shutil.rmtree("./lib/target", ignore_errors=True)
shutil.rmtree("./bin/target", ignore_errors=True)
if Path("./extism-py").exists():
Path("./extism-py").unlink()
if (Path(".") / exe_file()).exists():
(Path(".") / exe_file()).unlink()
logging.info("Clean completed successfully.")


def get_version():
try:
result = subprocess.run(
["extism-py", "--version"], capture_output=True, text=True, check=True
[exe_file(), "--version"], capture_output=True, text=True, check=True
)
return result.stdout.strip()
except subprocess.CalledProcessError:
Expand Down

0 comments on commit 1c3ee0f

Please sign in to comment.