Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 803fd6f

Browse files
committed
Change the build system from cmake to python.
1 parent 9781f8c commit 803fd6f

File tree

12 files changed

+195
-174
lines changed

12 files changed

+195
-174
lines changed

‎CMakeLists.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎README.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ The motivation behind this project is to be able to practice LeetCode problems o
99
- [Table of Content](#table-of-content)
1010
- [Screenshot](#screenshot)
1111
- [Build](#build)
12-
- [Building without UI](#building-without-ui)
13-
- [Building with UI](#building-with-ui)
12+
- [Windows](#windows)
13+
- [Building without UI](#building-without-ui)
14+
- [Building with UI](#building-with-ui)
15+
- [Unix](#unix)
16+
- [Building without UI](#building-without-ui-1)
17+
- [Building with UI](#building-with-ui-1)
1418
- [Run](#run)
15-
- [CLI - Windows Terminal](#cli---windows-terminal)
16-
- [CLI - Unix](#cli---unix)
17-
- [UI - Windows Terminal](#ui---windows-terminal)
18-
- [UI - Unix](#ui---unix)
19+
- [Windows](#windows-1)
20+
- [CLI](#cli)
21+
- [UI](#ui)
22+
- [CLI](#cli-1)
23+
- [UI](#ui-1)
1924
- [How To Use](#how-to-use)
2025
- [List of LeetCode Problems](#list-of-leetcode-problems)
2126
- [Usage](#usage)
@@ -29,32 +34,47 @@ The motivation behind this project is to be able to practice LeetCode problems o
2934
![Screenshot](assets/images/ui_screenshot.PNG)
3035

3136
## Build
32-
### Building without UI
37+
### Windows
38+
#### Building without UI
3339
```cmd
34-
cmake -B build -DCMAKE_INSTALL_PREFIX=install
35-
cmake --build build
36-
cmake --install build --prefix=install
40+
git clone https://github.com/mbucko/openleetcode
41+
cd openleetcode
42+
.\install --prefix=./install
3743
```
38-
### Building with UI
44+
#### Building with UI
3945
```cmd
40-
cmake -B build -DCMAKE_INSTALL_PREFIX=install -DBUILD_UI=ON
41-
cmake --build build
42-
cmake --install build --prefix=install
46+
git clone https://github.com/mbucko/openleetcode
47+
cd openleetcode
48+
.\install --prefix=./install --enable_ui
49+
```
50+
### Unix
51+
#### Building without UI
52+
```bash
53+
git clone https://github.com/mbucko/openleetcode
54+
cd openleetcode
55+
.\install.sh --prefix=./install
56+
```
57+
#### Building with UI
58+
```bash
59+
git clone https://github.com/mbucko/openleetcode
60+
cd openleetcode
61+
.\install.sh --prefix=./install --enable_ui
4362
```
4463
## Run
45-
### CLI - Windows Terminal
64+
### Windows
65+
#### CLI
4666
```cmd
4767
./problem_builds/openleetcode --language cpp --problem TwoSum
4868
```
49-
###CLI - Unix
69+
#### UI
5070
```bash
51-
./problem_builds/openleetcode.sh --language cpp --problem TwoSum
52-
```
53-
### UI - Windows Terminal
54-
```cmd
5571
./problem_builds/openleetcodeui
5672
```
57-
### UI - Unix
73+
#### CLI
74+
```bash
75+
./problem_builds/openleetcode.sh --language cpp --problem TwoSum
76+
```
77+
#### UI
5878
```bash
5979
./problem_builds/openleetcodeui.sh
6080
```

‎data/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎install.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
python "%~dp0install.py" %*

‎install.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import argparse
2+
import fnmatch
3+
import os
4+
import shutil
5+
import subprocess
6+
7+
from distutils import dir_util
8+
9+
if os.name == "nt":
10+
default_prefix = "C:\\Program Files"
11+
script_sufix = ".bat"
12+
else:
13+
default_prefix = "/usr/local"
14+
script_sufix = ".sh"
15+
16+
def installUI(src_dir, build_dir, install_dir):
17+
ui_build_dir = os.path.join(build_dir, "ui")
18+
if os.path.exists(ui_build_dir):
19+
shutil.rmtree(ui_build_dir)
20+
21+
src_dir = os.path.join(src_dir, "src", "ui")
22+
shutil.copytree(src_dir, ui_build_dir)
23+
24+
cmd_npm_install = "npm install"
25+
cmd_npx_build = f"npx electron-packager . --out={install_dir} --overwrite"
26+
27+
print(f"Installing OpenLeetCodeUI dependencies...")
28+
result = subprocess.run(cmd_npm_install,
29+
stdout=subprocess.PIPE,
30+
stderr=subprocess.STDOUT,
31+
shell=True,
32+
cwd=ui_build_dir)
33+
if result.returncode != 0:
34+
print(result.stdout.decode('utf-8'))
35+
raise RuntimeError(f"Error running the command: {cmd_npm_install}")
36+
37+
print(f"Building OpenLeetCodeUI...")
38+
result = subprocess.run(cmd_npx_build,
39+
stdout=subprocess.PIPE,
40+
stderr=subprocess.STDOUT,
41+
shell=True,
42+
cwd=ui_build_dir)
43+
if result.returncode != 0:
44+
print(result.stdout.decode('utf-8'))
45+
raise RuntimeError(f"Error running the command: {cmd_npx_build}")
46+
47+
openleetcode_ui_dir = os.path.join(
48+
install_dir,
49+
[
50+
d for d in os.listdir(install_dir)
51+
if fnmatch.fnmatch(d, "OpenLeetCodeUI-*-*")
52+
][0]
53+
)
54+
55+
new_openleetcode_ui_dir = os.path.join(install_dir, "OpenLeetCodeUI")
56+
if os.path.exists(new_openleetcode_ui_dir):
57+
shutil.rmtree(new_openleetcode_ui_dir)
58+
59+
os.rename(openleetcode_ui_dir, new_openleetcode_ui_dir)
60+
61+
if os.name == "nt":
62+
script = "openleetcodeui.bat"
63+
elif os.name == "posix":
64+
script = "openleetcodeui.sh"
65+
else:
66+
raise RuntimeError("Unsupported OS")
67+
68+
print(f"Installing OpenLeetCodeUI...")
69+
script = os.path.join(src_dir, script)
70+
if not os.path.exists(script):
71+
raise FileNotFoundError(f"No file found at {script}")
72+
shutil.copy(script, install_dir)
73+
74+
print("OpenLeetCodeUI installed at", new_openleetcode_ui_dir)
75+
76+
def installOpenLeetCode(src_dir, install_dir):
77+
print(f"Installing OpenLeetCode...")
78+
data_dir = os.path.join(src_dir, 'data')
79+
if not os.path.exists(data_dir):
80+
raise FileNotFoundError(f"No data directory found at {data_dir}")
81+
82+
dir_util.copy_tree(data_dir, install_dir)
83+
84+
schema_file = os.path.join(src_dir, "src", "schema", "results_validation_schema.json")
85+
if not os.path.exists(schema_file):
86+
raise FileNotFoundError(f"No schema file found at {schema_file}")
87+
shutil.copy(schema_file, install_dir)
88+
89+
if os.name == "nt":
90+
script = "openleetcode.bat"
91+
elif os.name == "posix":
92+
script = "openleetcode.sh"
93+
else:
94+
raise RuntimeError("Unsupported OS")
95+
96+
app_files = [
97+
"functionextractor.py",
98+
"logger.py",
99+
"openleetcode.py",
100+
"resultsvalidator.py",
101+
"testrunner.py",
102+
script
103+
]
104+
105+
for file in app_files:
106+
file = os.path.join(src_dir, "src", "app", file)
107+
if not os.path.exists(file):
108+
raise FileNotFoundError(f"No file found at {file}")
109+
shutil.copy(file, install_dir)
110+
111+
print("OpenLeetCode installed at", install_dir)
112+
113+
def main():
114+
print("OpenLeetCode Installer")
115+
116+
parser = argparse.ArgumentParser(description="Installer for OpenLeetCode")
117+
parser.add_argument("--build_dir", help="Build directory", default="build")
118+
parser.add_argument("--prefix", help="Installation prefix", default=default_prefix)
119+
parser.add_argument("--enable_ui", help="Enable UI installation", action="store_true", default=False)
120+
121+
args = parser.parse_args()
122+
123+
src_dir = os.path.dirname(os.path.abspath(__file__))
124+
build_dir = os.path.abspath(args.build_dir)
125+
if not os.path.exists(build_dir):
126+
os.makedirs(build_dir)
127+
128+
install_dir = os.path.abspath(os.path.join(args.prefix, "OpenLeetCode"))
129+
if not os.path.exists(install_dir):
130+
os.makedirs(install_dir)
131+
132+
installOpenLeetCode(src_dir, install_dir)
133+
134+
if args.enable_ui:
135+
installUI(src_dir, build_dir, install_dir)
136+
137+
print(
138+
f"Installation complete!\nYou can now run OpenLeetCode using "
139+
f"openleetcode{script_sufix}"
140+
f"{ ' or openleetcodeui' + script_sufix if args.enable_ui else ''}."
141+
)
142+
143+
if __name__ == '__main__':
144+
main()

‎install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
python3 "$(dirname "0ドル")/install.py" "$@"

‎src/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎src/app/CMakeLists.txt

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎src/schema/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /