Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JuliaFormatter.toml and format code #235

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
whitespace_typedefs = false
whitespace_ops_in_indices = false
whitespace_in_kwargs = false
remove_extra_newlines = true

format_docstrings = true
annotate_untyped_fields_with_any = true
join_lines_based_on_source = true

align_assignment = true
align_pair_arrow = true
align_struct_field = true
13 changes: 13 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Format suggestions
on:
pull_request:
# this argument is not required if you don't use the `suggestion-label` input
types: [opened, reopened, synchronize, labeled, unlabeled]
jobs:
code-style:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/julia-format@v3
with:
version: "1" # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1')
suggestion-label: "format-suggest" # leave this unset or empty to show suggestions for all PRs
43 changes: 27 additions & 16 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const depsfile = joinpath(@__DIR__, "deps.jl")
function find_matlab_root()
# Determine MATLAB library path and provide facilities to load libraries with this path
matlab_root = get(ENV, "MATLAB_ROOT",
get(ENV, "MATLAB_HOME", nothing))
get(ENV, "MATLAB_HOME", nothing))
if isnothing(matlab_root)
matlab_exe = Sys.which("matlab")
if !isnothing(matlab_exe)
Expand All @@ -22,7 +22,9 @@ function find_matlab_root()
end
end
elseif Sys.iswindows()
default_dir = Sys.WORD_SIZE == 32 ? "C:\\Program Files (x86)\\MATLAB" : "C:\\Program Files\\MATLAB"
default_dir =
Sys.WORD_SIZE == 32 ? "C:\\Program Files (x86)\\MATLAB" :
"C:\\Program Files\\MATLAB"
if isdir(default_dir)
dirs = readdir(default_dir)
filter!(dir -> occursin(r"^R[0-9]+[ab]$", dir), dirs)
Expand All @@ -42,7 +44,8 @@ function find_matlab_root()
end
end
end
!isnothing(matlab_root) && isdir(matlab_root) && @info("Detected MATLAB root folder at \"$matlab_root\"")
!isnothing(matlab_root) && isdir(matlab_root) &&
@info("Detected MATLAB root folder at \"$matlab_root\"")
return matlab_root
end

Expand All @@ -63,7 +66,12 @@ end

function find_matlab_cmd(matlab_root)
if Sys.iswindows()
matlab_cmd = joinpath(matlab_root, "bin", (Sys.WORD_SIZE == 32 ? "win32" : "win64"), "matlab.exe")
matlab_cmd = joinpath(
matlab_root,
"bin",
(Sys.WORD_SIZE == 32 ? "win32" : "win64"),
"matlab.exe",
)
isfile(matlab_cmd) && @info("Detected MATLAB executable at \"$matlab_cmd\"")
else
matlab_exe = joinpath(matlab_root, "bin", "matlab")
Expand All @@ -89,13 +97,14 @@ if !isnothing(matlab_root)
error("MATLAB library has changed, re-run Pkg.build(\\\"MATLAB\\\")")
end
end
"""
)
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
println(io, "const libmx_size = $libmx_size")
""",
)
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
println(io, "const libmx_size = $libmx_size")
end
elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" || get(ENV, "CI", nothing) == "true"
elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" ||
get(ENV, "CI", nothing) == "true"
# We need to be able to install and load this package without error for
# Julia's registry AutoMerge to work, so we just use dummy values.
# Similarly we want to also be able to install and load this package for CI.
Expand All @@ -109,12 +118,14 @@ elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" || get(ENV, "CI
# This file is automatically generated, do not edit.

check_deps() = nothing
"""
)
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
println(io, "const libmx_size = $libmx_size")
""",
)
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
println(io, "const libmx_size = $libmx_size")
end
else
error("MATLAB cannot be found. Set the \"MATLAB_ROOT\" environment variable to the MATLAB root directory and re-run Pkg.build(\"MATLAB\").")
error(
"MATLAB cannot be found. Set the \"MATLAB_ROOT\" environment variable to the MATLAB root directory and re-run Pkg.build(\"MATLAB\").",
)
end
242 changes: 120 additions & 122 deletions src/MATLAB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ using SparseArrays
import Base: eltype, close, size, copy, ndims, unsafe_convert

# mxarray
export MxArray, mxClassID, mxComplexity,
mxclassid, data_ptr,
classid, nrows, ncols, nelems, elsize
export MxArray,
mxClassID, mxComplexity,
mxclassid, data_ptr,
classid, nrows, ncols, nelems, elsize

export is_double, is_single,
is_int8, is_uint8, is_int16, is_uint16,
is_int32, is_uint32, is_int64, is_uint64,
is_numeric, is_complex, is_sparse, is_empty,
is_logical, is_char, is_struct, is_cell
is_int8, is_uint8, is_int16, is_uint16,
is_int32, is_uint32, is_int64, is_uint64,
is_numeric, is_complex, is_sparse, is_empty,
is_logical, is_char, is_struct, is_cell

export mxarray, mxsparse, delete,
mxcellarray, get_cell, set_cell,
mxstruct, mxstructarray, mxnfields, get_fieldname, get_field, set_field,
jvalue, jarray, jscalar, jvector, jmatrix, jsparse, jstring, jdict
mxcellarray, get_cell, set_cell,
mxstruct, mxstructarray, mxnfields, get_fieldname, get_field, set_field,
jvalue, jarray, jscalar, jvector, jmatrix, jsparse, jstring, jdict

# engine & matfile
export MSession, MatFile,
get_default_msession, restart_default_msession, close_default_msession,
eval_string, get_mvariable, get_variable, put_variable, put_variables,
variable_names, read_matfile, write_matfile,
mxcall,
@mput, @mget, @mat_str
get_default_msession, restart_default_msession, close_default_msession,
eval_string, get_mvariable, get_variable, put_variable, put_variables,
variable_names, read_matfile, write_matfile,
mxcall,
@mput, @mget, @mat_str

if Sys.iswindows()
export show_msession, hide_msession, get_msession_visiblity
Expand All @@ -37,7 +38,9 @@ const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("MATLAB is not properly installed. Please run Pkg.build(\"MATLAB\") and restart Julia.")
error(
"MATLAB is not properly installed. Please run Pkg.build(\"MATLAB\") and restart Julia.",
)
end

# exceptions
Expand Down Expand Up @@ -79,119 +82,114 @@ function __init__()

if libmx_size > 0 # non-zero size library path

# load libraries
# workaround for https://github.com/JuliaInterop/MATLAB.jl/issues/200
if Sys.iswindows()
ENV["PATH"] = string(matlab_libpath, ";", ENV["PATH"])
elseif Sys.islinux()
ENV["PATH"] = string(matlab_libpath, ":", ENV["PATH"])
end
libmx[] = Libdl.dlopen(joinpath(matlab_libpath, "libmx"), Libdl.RTLD_GLOBAL)
libmat[] = Libdl.dlopen(joinpath(matlab_libpath, "libmat"), Libdl.RTLD_GLOBAL)
libeng[] = Libdl.dlopen(joinpath(matlab_libpath, "libeng"), Libdl.RTLD_GLOBAL)

# engine functions

eng_open[] = engfunc(:engOpen)
eng_close[] = engfunc(:engClose)
eng_set_visible[] = engfunc(:engSetVisible)
eng_get_visible[] = engfunc(:engGetVisible)
eng_output_buffer[] = engfunc(:engOutputBuffer)
eng_eval_string[] = engfunc(:engEvalString)
eng_put_variable[] = engfunc(:engPutVariable)
eng_get_variable[] = engfunc(:engGetVariable)

# mxarray functions

mx_destroy_array[] = mxfunc(:mxDestroyArray)
mx_duplicate_array[] = mxfunc(:mxDuplicateArray)

# load functions to access mxarray

mx_free[] = mxfunc(:mxFree)

mx_get_classid[] = mxfunc(:mxGetClassID)
mx_get_m[] = mxfunc(:mxGetM)
mx_get_n[] = mxfunc(:mxGetN)
mx_get_nelems[] = mxfunc(:mxGetNumberOfElements)
mx_get_ndims[] = mxfunc(:mxGetNumberOfDimensions_730)
mx_get_elemsize[] = mxfunc(:mxGetElementSize)
mx_get_data[] = mxfunc(:mxGetData)
mx_get_dims[] = mxfunc(:mxGetDimensions_730)
mx_get_nfields[] = mxfunc(:mxGetNumberOfFields)
mx_get_pr[] = mxfunc(:mxGetPr)
mx_get_pi[] = mxfunc(:mxGetPi)
mx_get_ir[] = mxfunc(:mxGetIr_730)
mx_get_jc[] = mxfunc(:mxGetJc_730)

mx_is_double[] = mxfunc(:mxIsDouble)
mx_is_single[] = mxfunc(:mxIsSingle)
mx_is_int64[] = mxfunc(:mxIsInt64)
mx_is_uint64[] = mxfunc(:mxIsUint64)
mx_is_int32[] = mxfunc(:mxIsInt32)
mx_is_uint32[] = mxfunc(:mxIsUint32)
mx_is_int16[] = mxfunc(:mxIsInt16)
mx_is_uint16[] = mxfunc(:mxIsUint16)
mx_is_int8[] = mxfunc(:mxIsInt8)
mx_is_uint8[] = mxfunc(:mxIsUint8)
mx_is_char[] = mxfunc(:mxIsChar)

mx_is_numeric[] = mxfunc(:mxIsNumeric)
mx_is_logical[] = mxfunc(:mxIsLogical)
mx_is_complex[] = mxfunc(:mxIsComplex)
mx_is_sparse[] = mxfunc(:mxIsSparse)
mx_is_empty[] = mxfunc(:mxIsEmpty)
mx_is_struct[] = mxfunc(:mxIsStruct)
mx_is_cell[] = mxfunc(:mxIsCell)


# load functions to create & delete MATLAB array

mx_create_numeric_matrix[] = mxfunc(:mxCreateNumericMatrix_730)
mx_create_numeric_array[] = mxfunc(:mxCreateNumericArray_730)

mx_create_double_scalar[] = mxfunc(:mxCreateDoubleScalar)
mx_create_logical_scalar[] = mxfunc(:mxCreateLogicalScalar)

mx_create_sparse[] = mxfunc(:mxCreateSparse_730)
mx_create_sparse_logical[] = mxfunc(:mxCreateSparseLogicalMatrix_730)

mx_create_string[] = mxfunc(:mxCreateString)
mx_create_char_array[] = mxfunc(:mxCreateCharArray_730)

mx_create_cell_array[] = mxfunc(:mxCreateCellArray_730)

mx_create_struct_matrix[] = mxfunc(:mxCreateStructMatrix_730)
mx_create_struct_array[] = mxfunc(:mxCreateStructArray_730)

mx_get_cell[] = mxfunc(:mxGetCell_730)
mx_set_cell[] = mxfunc(:mxSetCell_730)

mx_get_field[] = mxfunc(:mxGetField_730)
mx_set_field[] = mxfunc(:mxSetField_730)
mx_get_field_bynum[] = mxfunc(:mxGetFieldByNumber_730)
mx_get_fieldname[] = mxfunc(:mxGetFieldNameByNumber)

mx_get_string[] = mxfunc(:mxGetString_730)


# load I/O mat functions

mat_open[] = matfunc(:matOpen)
mat_close[] = matfunc(:matClose)
mat_get_variable[] = matfunc(:matGetVariable)
mat_put_variable[] = matfunc(:matPutVariable)
mat_get_dir[] = matfunc(:matGetDir)

# load libraries
# workaround for https://github.com/JuliaInterop/MATLAB.jl/issues/200
if Sys.iswindows()
ENV["PATH"] = string(matlab_libpath, ";", ENV["PATH"])
elseif Sys.islinux()
ENV["PATH"] = string(matlab_libpath, ":", ENV["PATH"])
end
libmx[] = Libdl.dlopen(joinpath(matlab_libpath, "libmx"), Libdl.RTLD_GLOBAL)
libmat[] = Libdl.dlopen(joinpath(matlab_libpath, "libmat"), Libdl.RTLD_GLOBAL)
libeng[] = Libdl.dlopen(joinpath(matlab_libpath, "libeng"), Libdl.RTLD_GLOBAL)

# engine functions

eng_open[] = engfunc(:engOpen)
eng_close[] = engfunc(:engClose)
eng_set_visible[] = engfunc(:engSetVisible)
eng_get_visible[] = engfunc(:engGetVisible)
eng_output_buffer[] = engfunc(:engOutputBuffer)
eng_eval_string[] = engfunc(:engEvalString)
eng_put_variable[] = engfunc(:engPutVariable)
eng_get_variable[] = engfunc(:engGetVariable)

# mxarray functions

mx_destroy_array[] = mxfunc(:mxDestroyArray)
mx_duplicate_array[] = mxfunc(:mxDuplicateArray)

# load functions to access mxarray

mx_free[] = mxfunc(:mxFree)

mx_get_classid[] = mxfunc(:mxGetClassID)
mx_get_m[] = mxfunc(:mxGetM)
mx_get_n[] = mxfunc(:mxGetN)
mx_get_nelems[] = mxfunc(:mxGetNumberOfElements)
mx_get_ndims[] = mxfunc(:mxGetNumberOfDimensions_730)
mx_get_elemsize[] = mxfunc(:mxGetElementSize)
mx_get_data[] = mxfunc(:mxGetData)
mx_get_dims[] = mxfunc(:mxGetDimensions_730)
mx_get_nfields[] = mxfunc(:mxGetNumberOfFields)
mx_get_pr[] = mxfunc(:mxGetPr)
mx_get_pi[] = mxfunc(:mxGetPi)
mx_get_ir[] = mxfunc(:mxGetIr_730)
mx_get_jc[] = mxfunc(:mxGetJc_730)

mx_is_double[] = mxfunc(:mxIsDouble)
mx_is_single[] = mxfunc(:mxIsSingle)
mx_is_int64[] = mxfunc(:mxIsInt64)
mx_is_uint64[] = mxfunc(:mxIsUint64)
mx_is_int32[] = mxfunc(:mxIsInt32)
mx_is_uint32[] = mxfunc(:mxIsUint32)
mx_is_int16[] = mxfunc(:mxIsInt16)
mx_is_uint16[] = mxfunc(:mxIsUint16)
mx_is_int8[] = mxfunc(:mxIsInt8)
mx_is_uint8[] = mxfunc(:mxIsUint8)
mx_is_char[] = mxfunc(:mxIsChar)

mx_is_numeric[] = mxfunc(:mxIsNumeric)
mx_is_logical[] = mxfunc(:mxIsLogical)
mx_is_complex[] = mxfunc(:mxIsComplex)
mx_is_sparse[] = mxfunc(:mxIsSparse)
mx_is_empty[] = mxfunc(:mxIsEmpty)
mx_is_struct[] = mxfunc(:mxIsStruct)
mx_is_cell[] = mxfunc(:mxIsCell)

# load functions to create & delete MATLAB array

mx_create_numeric_matrix[] = mxfunc(:mxCreateNumericMatrix_730)
mx_create_numeric_array[] = mxfunc(:mxCreateNumericArray_730)

mx_create_double_scalar[] = mxfunc(:mxCreateDoubleScalar)
mx_create_logical_scalar[] = mxfunc(:mxCreateLogicalScalar)

mx_create_sparse[] = mxfunc(:mxCreateSparse_730)
mx_create_sparse_logical[] = mxfunc(:mxCreateSparseLogicalMatrix_730)

mx_create_string[] = mxfunc(:mxCreateString)
mx_create_char_array[] = mxfunc(:mxCreateCharArray_730)

mx_create_cell_array[] = mxfunc(:mxCreateCellArray_730)

mx_create_struct_matrix[] = mxfunc(:mxCreateStructMatrix_730)
mx_create_struct_array[] = mxfunc(:mxCreateStructArray_730)

mx_get_cell[] = mxfunc(:mxGetCell_730)
mx_set_cell[] = mxfunc(:mxSetCell_730)

mx_get_field[] = mxfunc(:mxGetField_730)
mx_set_field[] = mxfunc(:mxSetField_730)
mx_get_field_bynum[] = mxfunc(:mxGetFieldByNumber_730)
mx_get_fieldname[] = mxfunc(:mxGetFieldNameByNumber)

mx_get_string[] = mxfunc(:mxGetString_730)

# load I/O mat functions

mat_open[] = matfunc(:matOpen)
mat_close[] = matfunc(:matClose)
mat_get_variable[] = matfunc(:matGetVariable)
mat_put_variable[] = matfunc(:matPutVariable)
mat_get_dir[] = matfunc(:matGetDir)
end
end


###########################################################
#
# deprecations
#
###########################################################


end
Loading
Loading