Skip to content

Commit 9a00194

Browse files
authored
Add installer for examples (#101)
* add function copy_examples * add using Pkg * fix help command * suppress the error message * menu works now * add comment * improve install_examples() * update README.md * update index.md * update NEWS.md --------- Co-authored-by: Uwe Fechner <[email protected]>
1 parent 72f9032 commit 9a00194

File tree

5 files changed

+82
-11
lines changed

5 files changed

+82
-11
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
### Added
3+
- added the function `install_examples()` which allows to easily install the examples without using `git`
4+
15
## VortexStepMethod v1.1.0 2025-03-04
26
### Added
37
- Dynamically deform the KiteWing by twisting the left side and right side, and deforming the trailing edges using deform! #19

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ julia -e 'using Pkg; Pkg.add("TestEnv"); Pkg.add("ControlPlots")'
2525

2626
Before installing this software it is suggested to create a new project, for example like this:
2727
```bash
28-
mkdir test
29-
cd test
28+
mkdir vsm
29+
cd vsm
3030
julia --project=.
3131
```
3232
Then add VortexStepMethod from Julia's package manager, by typing:
@@ -38,8 +38,14 @@ at the Julia prompt. You can run the unit tests with the command:
3838
```julia
3939
pkg"test VortexStepMethod"
4040
```
41+
To run the examples, type:
42+
```julia
43+
using VortexStepMethod
44+
VortexStepMethod.install_examples()
45+
include("examples/menu.jl")
46+
```
4147

42-
## Running the examples
48+
## Running the examples as developer
4349
If you have git installed, check out this repo because it makes it easier to understand the code:
4450
```bash
4551
mkdir repos

docs/src/index.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ julia -e 'using Pkg; Pkg.add("TestEnv"); Pkg.add("ControlPlots")'
2626

2727
Before installing this software it is suggested to create a new project, for example like this:
2828
```bash
29-
mkdir test
30-
cd test
29+
mkdir vsm
30+
cd vsm
3131
julia --project=.
3232
```
3333
Then add VortexStepMethod from Julia's package manager, by typing:
@@ -39,8 +39,14 @@ at the Julia prompt. You can run the unit tests with the command:
3939
```julia
4040
pkg"test VortexStepMethod"
4141
```
42+
To run the examples, type:
43+
```julia
44+
using VortexStepMethod
45+
VortexStepMethod.install_examples()
46+
include("examples/menu.jl")
47+
```
4248

43-
## Running the examples
49+
## Running the examples as developer
4450
If you have git installed, check out this repo because it makes it easier to understand the code:
4551
```bash
4652
mkdir repos

examples/menu.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ using REPL.TerminalMenus
44

55
url = "https://albatross-kite-transport.github.io/VortexStepMethod.jl/dev"
66

7-
help_command = if Sys.iswindows()
8-
"run(`cmd /c start $url`)"
9-
else
10-
"run(`xdg-open $url`)"
7+
function help()
8+
if Sys.iswindows()
9+
run(`cmd /c start $url`)
10+
else
11+
io = IOBuffer()
12+
run(pipeline(`xdg-open $url`, stderr = io))
13+
# ignore any error messages
14+
out_data = String(take!(io))
15+
end
16+
nothing
1117
end
1218

1319
options = ["rectangular_wing = include(\"rectangular_wing.jl\")",
1420
"ram_air_kite = include(\"ram_air_kite.jl\")",
1521
"stall_model = include(\"stall_model.jl\")",
1622
"bench = include(\"bench.jl\")",
1723
"cleanup = include(\"cleanup.jl\")",
18-
"help = $help_command",
24+
"help_me = help()",
1925
"quit"]
2026

2127
function example_menu()

src/VortexStepMethod.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using Interpolations: Extrapolation
1414
using Parameters
1515
using Serialization
1616
using SharedArrays
17+
using Pkg
1718

1819
# Export public interface
1920
export Wing, Section, KiteWing
@@ -169,6 +170,54 @@ function menu()
169170
Main.include("examples/menu.jl")
170171
end
171172

173+
"""
174+
copy_examples()
175+
176+
Copy all example scripts to the folder "examples"
177+
(it will be created if it doesn't exist).
178+
"""
179+
function copy_examples()
180+
PATH = "examples"
181+
if ! isdir(PATH)
182+
mkdir(PATH)
183+
end
184+
src_path = joinpath(dirname(pathof(@__MODULE__)), "..", PATH)
185+
copy_files("examples", readdir(src_path))
186+
end
187+
188+
function install_examples(add_packages=true)
189+
copy_examples()
190+
if add_packages
191+
if ! ("ControlPlots" keys(Pkg.project().dependencies))
192+
Pkg.add("ControlPlots")
193+
end
194+
if ! ("LaTeXStrings" keys(Pkg.project().dependencies))
195+
Pkg.add("LaTeXStrings")
196+
end
197+
if ! ("Xfoil" keys(Pkg.project().dependencies))
198+
Pkg.add("Xfoil")
199+
end
200+
if ! ("CSV" keys(Pkg.project().dependencies))
201+
Pkg.add("CSV")
202+
end
203+
if ! ("DataFrames" keys(Pkg.project().dependencies))
204+
Pkg.add("DataFrames")
205+
end
206+
end
207+
end
208+
209+
function copy_files(relpath, files)
210+
if ! isdir(relpath)
211+
mkdir(relpath)
212+
end
213+
src_path = joinpath(dirname(pathof(@__MODULE__)), "..", relpath)
214+
for file in files
215+
cp(joinpath(src_path, file), joinpath(relpath, file), force=true)
216+
chmod(joinpath(relpath, file), 0o774)
217+
end
218+
files
219+
end
220+
172221
# Include core functionality
173222
include("wing_geometry.jl")
174223
include("kite_geometry.jl")

0 commit comments

Comments
 (0)