-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from emsig/dev_julia
Dev julia
- Loading branch information
Showing
6 changed files
with
238 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: julia-deploy | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
release: | ||
types: | ||
- published | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
# test: | ||
deploy: | ||
name: Deploy to package-julia | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 100 | ||
persist-credentials: false | ||
- name: Fetch git tags | ||
run: git fetch origin 'refs/tags/*:refs/tags/*' | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: '1.6' | ||
- name: Install dependencies | ||
run: julia -e 'import Pkg; Pkg.add("DataStructures"); Pkg.add("JSON")' | ||
- name: Create package | ||
run: | | ||
cd packages | ||
julia create_julia.jl | ||
- name: Deploy to packages-julia branch | ||
uses: s0/git-publish-subdir-action@develop | ||
if: success() | ||
env: | ||
REPO: self | ||
BRANCH: package-julia | ||
FOLDER: packages/julia | ||
MESSAGE: "@JuliaRegistrator register branch=package-julia" | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
packages/python/ | ||
__pycache__ | ||
packages/julia/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
using DataStructures | ||
import JSON | ||
|
||
# Create package directories | ||
mkpath("julia/src") | ||
mkpath("julia/test") | ||
|
||
# Copy library to Julia package | ||
cp(abspath("../lib"),abspath("julia/src/lib"),force=true) | ||
|
||
# Copy README and LICENSE | ||
cp("../README.md", "julia/README.md",force=true) | ||
cp("../LICENSE", "julia/LICENSE",force=true) | ||
|
||
# Get current version number in git: | ||
version = split(read(`git describe --tags`,String),"-")[1][2:end] | ||
|
||
# Create Project.toml | ||
iop = open(abspath("julia/Project.toml"), "w") | ||
println(iop,"name = \"LibDLF\"") | ||
println(iop,"uuid = \"f0c3f387-4ff6-435f-9d63-77e28b8d1347\"") | ||
println(iop,"authors = [\"The emsig community <[email protected]> \"]") | ||
println(iop,"version = \"$version\"") #kwk debug: how to get version in github build? | ||
println(iop,"\n[deps]") | ||
println(iop,"DelimitedFiles = \"8bb1440f-4735-579b-a4ab-409b98df4dab\"") | ||
println(iop,"\n[extras]") | ||
println(iop,"Test = \"8dfed614-e22c-5e08-85e1-65c5234f0b40\"") | ||
println(iop,"\n[targets]") | ||
println(iop,"test = [\"Test\"]") | ||
close(iop) | ||
|
||
# Read in .json file listing all filters | ||
filters = JSON.parsefile(abspath("julia/src/lib/filters.json"), | ||
dicttype=DataStructures.OrderedDict) | ||
|
||
# Create Julia module | ||
iol = open(abspath("julia/src/LibDLF.jl"), "w") | ||
|
||
# Module name | ||
println(iol,"module LibDLF\n") | ||
|
||
# Create LibDLF.jl files | ||
for type in filters.keys | ||
|
||
stype = titlecase(type) | ||
|
||
# Include sub module file in parent | ||
println(iol, "include(\"$stype.jl\")") | ||
|
||
# Create sub module file for filter type | ||
iot = open(abspath("julia/src/$stype.jl"), "w") | ||
|
||
println(iot, "module $stype\n") | ||
|
||
# Add used modules | ||
println(iot, "using DelimitedFiles") | ||
|
||
# Add library path variable: | ||
println(iot, "\nlibpath = @__DIR__") | ||
|
||
# Add cache: | ||
println(iot, "\ncache = Dict() # local cache for any filters already loaded") | ||
|
||
# Add filter functions: | ||
for filt in filters[type] | ||
|
||
# Get and write header as docstring: | ||
iof = open(abspath("julia/src/" * filt["file"]), "r") | ||
|
||
# Title | ||
println(iot, "\n\"\"\"") | ||
|
||
sname = filt["name"] | ||
println(iot, "\t $sname()\n") | ||
|
||
println(iot, readline(iof)[2:end]) | ||
|
||
# Get vals and preformat if sin & cos | ||
vals = replace(filt["values"], "," => ", ") | ||
# println(typeof(vals)) | ||
if type == "fourier" | ||
vals = replace(vals, "cos" => "fcos") | ||
vals = replace(vals, "sin" => "fsin") | ||
end | ||
|
||
# Rest of header | ||
for line in eachline(iof) | ||
|
||
# Do not copy the title-underline; just newline | ||
if contains(line, "========") | ||
println(iot, "") | ||
|
||
# Empty lines: only remove comment | ||
elseif line == "#\n" | ||
println(iot, "") | ||
|
||
# The license is the last thing of the header | ||
elseif contains(line, "This file is part of libdlf") | ||
|
||
# Add returned vals | ||
println(iot, "# Returns\n") | ||
println(iot, "base, $vals :: Array{Float64,1}") | ||
println(iot, "Filter base and its values.\n") | ||
|
||
# Example | ||
println(iot, "# Example\n") | ||
println(iot, "```julia") | ||
println(iot, "base, $vals = LibDLF.$stype.$sname()") | ||
println(iot, "```") | ||
|
||
# Finish header | ||
println(iot, "\n\"\"\"") | ||
|
||
# Stop header loop | ||
break | ||
|
||
# Print entire line | ||
else | ||
println(iot, line[2:end]) | ||
|
||
end | ||
|
||
end | ||
|
||
println(iot, "function $sname()") | ||
|
||
println(iot,"\tif !haskey(cache,\"$sname\") # read and add to cache") | ||
sfile = filt["file"] | ||
println(iot,"\t\tsfile = joinpath(libpath,\"$sfile\")") | ||
println(iot, "\t\tdat = readdlm(sfile,comments=true)") | ||
println(iot,"\t\tcache[\"$sname\"]= tuple([dat[:,c] for c in 1:size(dat,2)]...)") | ||
println(iot, "\tend") | ||
println(iot, "\treturn cache[\"$sname\"]") | ||
println(iot, "end") | ||
|
||
# Close file | ||
close(iof) | ||
|
||
end | ||
|
||
# Close filter type sub module: | ||
println(iot, "\nend") | ||
close(iot) | ||
end | ||
|
||
# Close LibDLF module: | ||
println(iol,"\nend") | ||
close(iol) | ||
|
||
# Create testing routine | ||
ior = open(abspath("julia/test/runtests.jl"), "w") | ||
println(ior,"using LibDLF") | ||
println(ior,"using Test\n") | ||
println(ior,"# insert code for @testset blocks and @test unit tests ") | ||
close(ior) |