summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2020-11-29 13:57:53 -0800
committerMicah Lee <micah@micahflee.com>2020-11-29 13:57:53 -0800
commitc2940a307db42edc61d42ddc0b7eb765410c8cfa (patch)
tree26d20702d4d6b9ed3139ca868413fc2a51c43d8e
parentc904bb5b5f538f7b34d982ae45e6e1fd84cc3671 (diff)
downloadonionshare-c2940a307db42edc61d42ddc0b7eb765410c8cfa.tar.gz
onionshare-c2940a307db42edc61d42ddc0b7eb765410c8cfa.zip
Write rebuild-cli in python instead of bash to work in Windows, and make the dev script available in Windows
-rw-r--r--desktop/README.md4
-rw-r--r--desktop/scripts/dev.bat3
-rwxr-xr-xdesktop/scripts/rebuild-cli.py45
-rwxr-xr-xdesktop/scripts/rebuild-cli.sh10
4 files changed, 51 insertions, 11 deletions
diff --git a/desktop/README.md b/desktop/README.md
index 5e1c11ea..97d0fd30 100644
--- a/desktop/README.md
+++ b/desktop/README.md
@@ -79,7 +79,7 @@ pip install briefcase
In order to work with the desktop app, you'll need to build a wheel of the CLI package first, and copy it into the `desktop` folder. You'll need to re-run this script each time you change the CLI code.
```sh
-./scripts/rebuild-cli.sh
+python scripts/rebuild-cli.py
```
### Running OnionShare from the source code tree
@@ -98,6 +98,8 @@ Once you have the dependencies installed, you can run it using the `dev.sh` scri
./scripts/dev.sh -v --local-only
```
+Windows uses `scripts\dev.bat` instead.
+
## Running tests
Install these packages inside your virtual environment:
diff --git a/desktop/scripts/dev.bat b/desktop/scripts/dev.bat
new file mode 100644
index 00000000..9b537a90
--- /dev/null
+++ b/desktop/scripts/dev.bat
@@ -0,0 +1,3 @@
+cd src
+python -c "import onionshare; onionshare.main()" %*
+cd .. \ No newline at end of file
diff --git a/desktop/scripts/rebuild-cli.py b/desktop/scripts/rebuild-cli.py
new file mode 100755
index 00000000..c13461bc
--- /dev/null
+++ b/desktop/scripts/rebuild-cli.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+"""
+This script builds the CLI python wheel, copies it to the desktop folder,
+and installs it in the virtual environment.
+"""
+
+import inspect
+import os
+import sys
+import glob
+import subprocess
+import shutil
+
+
+def main():
+ # Build paths
+ root_path = os.path.dirname(
+ os.path.dirname(
+ os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
+ )
+ )
+ cli_path = os.path.join(root_path, "cli")
+ desktop_path = os.path.join(root_path, "desktop")
+
+ # Delete old wheels
+ for filename in glob.glob(os.path.join(cli_path, "dist", "*.whl")):
+ os.remove(filename)
+
+ # Build new wheel
+ subprocess.call(["poetry", "install"], cwd=cli_path)
+ subprocess.call(["poetry", "build"], cwd=cli_path)
+ wheel_filename = glob.glob(os.path.join(cli_path, "dist", "*.whl"))[0]
+ wheel_basename = os.path.basename(wheel_filename)
+ shutil.copyfile(
+ wheel_filename,
+ os.path.join(desktop_path, wheel_basename),
+ )
+
+ # Reinstall the new wheel
+ subprocess.call(["pip", "uninstall", "onionshare-cli", "-y"])
+ subprocess.call(["pip", "install", os.path.join(desktop_path, wheel_basename)])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/desktop/scripts/rebuild-cli.sh b/desktop/scripts/rebuild-cli.sh
deleted file mode 100755
index 9d6a1338..00000000
--- a/desktop/scripts/rebuild-cli.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-# Build the CLI python wheel and copy it to the desktop folder
-
-SCRIPTS_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
-cd $SCRIPTS_DIR
-cd ../../cli
-poetry install
-poetry build
-cp dist/*.whl ../desktop \ No newline at end of file