Skip to content

Commit

Permalink
Fix deprecations to make Julia v0.7 tests pass (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojukka5 committed Aug 11, 2018
1 parent cafa5a5 commit 9294ded
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 92 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
- julia: 0.7
- julia: 1.0
- julia: nightly
before_script:
- julia --color=yes -e 'Pkg.clone("https://github.com/JuliaFEM/PkgTestSuite.jl.git")'
- julia --color=yes -e 'using Pkg; Pkg.clone("https://github.com/JuliaFEM/PkgTestSuite.jl.git")'
- julia --color=yes -e 'using PkgTestSuite; init()'
script:
- julia --color=yes -e 'using PkgTestSuite; test()'
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
julia 0.7
Nullables
2 changes: 2 additions & 0 deletions src/AbaqusReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module AbaqusReader

using Nullables

include("parse_mesh.jl")
include("keyword_register.jl")
include("parse_model.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/abaqus_download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function abaqus_download(model_name, env=ENV; dryrun=false)
`ABAQUS_DOWNLOAD_URL`")
end
url = joinpath(env["ABAQUS_DOWNLOAD_URL"], model_name)
info("Downloading model $model_name to $fn")
@info("Downloading model $model_name to $fn")
dryrun || download(url, fn)
return fn
end
31 changes: 18 additions & 13 deletions src/parse_mesh.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

import Base.parse

# Define element type and number of nodes in element
element_has_nodes(::Type{Val{:C3D4}}) = 4
element_has_type( ::Type{Val{:C3D4}}) = :Tet4
Expand Down Expand Up @@ -42,7 +44,8 @@ end
"""Match words from both sides of '=' character
"""
function matchset(definition)
matchall(r"([\w\_\-]+[ ]*=[ ]*[\w\_\-]+)", definition)
regexp = r"([\w\_\-]+[ ]*=[ ]*[\w\_\-]+)"
collect(m.match for m = eachmatch(regexp, definition))
end

"""Parse string to get set type and name
Expand All @@ -61,8 +64,9 @@ end
"""Parse all the numbers from string
"""
function parse_numbers(line, type_)
m = matchall(r"[0-9]+", line)
map(x-> parse(type_, x), m)
regexp = r"[0-9]+"
matches = collect((m.match for m = eachmatch(regexp, line)))
map(x-> Base.parse(type_, x), matches)
end

"""Add set to model, if set exists
Expand All @@ -71,7 +75,7 @@ function add_set!(model, definition, model_key, abaqus_key, ids)
has_set_def = parse_definition(definition)
if length(has_set_def) != 0
set_name = has_set_def[abaqus_key]
info("Adding $abaqus_key: $set_name")
@info("Adding $abaqus_key: $set_name")
model[model_key][set_name] = ids
end
end
Expand All @@ -84,15 +88,15 @@ function parse_section(model, lines, ::Symbol, idx_start, idx_end, ::Type{Val{:N
definition = lines[idx_start]
for line in lines[idx_start + 1: idx_end]
if !(empty_or_comment_line(line))
m = matchall(r"[-0-9.eE+]+", line)
m = collect((m.match for m = eachmatch(r"[-0-9.eE+]+", line)))
node_id = parse(Int, m[1])
coords = float(m[2:end])
coords = parse.(Float64, m[2:end])
model["nodes"][node_id] = coords
push!(ids, node_id)
nnodes += 1
end
end
info("$nnodes nodes found")
@info("$nnodes nodes found")
add_set!(model, definition, "node_sets", "nset", ids)
end

Expand Down Expand Up @@ -133,7 +137,7 @@ function parse_section(model, lines, ::Symbol, idx_start, idx_end, ::Type{Val{:E
eltype_sym = Symbol(element_type)
eltype_nodes = element_has_nodes(Val{eltype_sym})
element_type = element_has_type(Val{eltype_sym})
info("Parsing elements. Type: $(element_type)")
@info("Parsing elements. Type: $(element_type)")
list_iterator = consumeList(lines, idx_start+1, idx_end)
line = list_iterator()
while line != nothing
Expand Down Expand Up @@ -161,12 +165,13 @@ end
function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:NSET}},
Type{Val{:ELSET}}})
data = Integer[]
set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)", :ELSET => r"ELSET=([\w\-\_]+)" )
set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)",
:ELSET => r"ELSET=([\w\-\_]+)" )
selected_set = key == :NSET ? "node_sets" : "element_sets"
definition = lines[idx_start]
regex_string = set_regex_string[key]
set_name = regex_match(regex_string, definition, 1)
info("Creating $(lowercase(string(key))) $set_name")
@info("Creating $(lowercase(string(key))) $set_name")

if endswith(strip(definition), "GENERATE")
line = lines[idx_start + 1]
Expand Down Expand Up @@ -202,7 +207,7 @@ function parse_section(model, lines, ::Symbol, idx_start, idx_end, ::Type{Val{:S
element_side = Symbol(m[:element_side])
push!(data, (element_id, element_side))
end
model["surface_types"][set_name] = set_type
model["surface_types"][set_name] = Symbol(set_type)
model["surface_sets"][set_name] = data
return
end
Expand Down Expand Up @@ -246,10 +251,10 @@ function parse_abaqus(fid::IOStream)
keyword = strip(regex_match(r"\s*([\w ]+)", keyword_line, 1))
k_sym = Symbol(keyword)
args = Tuple{Dict, Vector{Int}, Symbol, Int, Int, Type{Val{k_sym}}}
if method_exists(parse_section, args)
if hasmethod(parse_section, args)
parse_section(model, lines, k_sym, idx_start, idx_end-1, Val{k_sym})
else
warn("Unknown section: '$(keyword)'")
@warn("Unknown section: '$(keyword)'")
end
idx_start = idx_end
end
Expand Down
43 changes: 22 additions & 21 deletions src/parse_model.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

import Base.parse
import Base: getindex, length

### Model definitions for ABAQUS data model
Expand Down Expand Up @@ -29,8 +30,8 @@ function Mesh(d::Dict{String, Dict})
end

mutable struct Model
path :: AbstractString
name :: AbstractString
path :: String
name :: String
mesh :: Mesh
materials :: Dict{Symbol, AbstractMaterial}
properties :: Vector{AbstractProperty}
Expand Down Expand Up @@ -75,24 +76,24 @@ end
### Utility functions to parse ABAQUS .inp file to data model

mutable struct Keyword
name :: AbstractString
options :: Vector{Union{AbstractString, Pair}}
name :: String
options :: Vector{Union{String, Pair}}
end

mutable struct AbaqusReaderState
section :: Nullable{Keyword}
material :: Nullable{AbstractMaterial}
property :: Nullable{AbstractProperty}
step :: Nullable{AbstractStep}
data :: Vector{AbstractString}
data :: Vector{String}
end

function get_data(state::AbaqusReaderState)
data = []
for row in state.data
row = strip(row, [' ', ','])
col = split(row, ',')
col = map(parse, col)
col = map(Meta.parse, col)
push!(data, col)
end
return data
Expand All @@ -102,7 +103,7 @@ function get_options(state::AbaqusReaderState)
return Dict(get(state.section).options)
end

function get_option(state::AbaqusReaderState, what::AbstractString)
function get_option(state::AbaqusReaderState, what::String)
return get_options(state)[what]
end

Expand All @@ -120,14 +121,14 @@ end

function parse_keyword(line; uppercase_keyword=true)
args = split(line, ",")
args = map(strip, args)
args = map(String, map(strip, args))
keyword_name = strip(args[1], '*')
if uppercase_keyword
keyword_name = uppercase(keyword_name)
end
keyword = Keyword(keyword_name, [])
for option in args[2:end]
pair = split(option, "=")
pair = map(String, split(option, "="))
if uppercase_keyword
pair[1] = uppercase(pair[1])
end
Expand Down Expand Up @@ -159,12 +160,12 @@ function maybe_close_section!(model, state)
global close_section!
isnull(state.section) && return
section_name = get(state.section).name
info("Close section: $section_name")
@info("Close section: $section_name")
args = Tuple{Model, AbaqusReaderState, Type{Val{Symbol(section_name)}}}
if method_exists(close_section!, args)
if hasmethod(close_section!, args)
close_section!(model, state, Val{Symbol(section_name)})
else
warn("no close_section! found for $section_name")
@warn("no close_section! found for $section_name")
end
state.section = nothing
end
Expand All @@ -173,12 +174,12 @@ function maybe_open_section!(model, state)
global open_section!
section_name = get(state.section).name
section_options = get(state.section).options
info("New section: $section_name with options $section_options")
@info("New section: $section_name with options $section_options")
args = Tuple{Model, AbaqusReaderState, Type{Val{Symbol(section_name)}}}
if method_exists(open_section!, args)
if hasmethod(open_section!, args)
open_section!(model, state, Val{Symbol(section_name)})
else
warn("no open_section! found for $section_name")
@warn("no open_section! found for $section_name")
end
end

Expand All @@ -191,11 +192,11 @@ end

function process_line!(model, state, line::String)
if isnull(state.section)
info("section = nothing! line = $line")
@info("section = nothing! line = $line")
return
end
if is_keyword(line)
warn("missing keyword? line = $line")
@warn("missing keyword? line = $line")
# close section, this is probably keyword and collecting data should stop.
maybe_close_section!(model, state)
return
Expand Down Expand Up @@ -268,8 +269,8 @@ const OUTPUT_REQUESTS = Union{NODE_PRINT, EL_PRINT, SECTION_PRINT}
## Properties

function open_section!(model, state, ::SOLID_SECTION)
element_set = get_option(state, "ELSET")
material_name = get_option(state, "MATERIAL")
element_set = Symbol(get_option(state, "ELSET"))
material_name = Symbol(get_option(state, "MATERIAL"))
property = SolidSection(element_set, material_name)
state.property = property
push!(model.properties, property)
Expand Down Expand Up @@ -337,10 +338,10 @@ end

function close_section!(model, state, ::OUTPUT_REQUESTS)
name = model.name
kind, target = map(parse, split(get(state.section).name, " "))
kind, target = map(Meta.parse, split(get(state.section).name, " "))
data = get_data(state)
options = get_options(state)
request = OutputRequest(kind, data, options, target)
request = OutputRequest(Symbol(kind), data, options, Symbol(target))
step_ = get(state.step)
push!(step_.output_requests, request)
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

using AbaqusReader
using Base.Test
using Test

@testset "AbaqusReader.jl" begin
include("test_parse_mesh.jl")
Expand Down
2 changes: 0 additions & 2 deletions test/test_create_surface_elements.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

using Base.Test

using AbaqusReader: create_surface_element, create_surface_elements

@testset "create surface element from voluminal element surface" begin
Expand Down
3 changes: 1 addition & 2 deletions test/test_download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

using AbaqusReader
using Base.Test

@testset "test abaqus_download" begin
ENV_ = similar(ENV)
ENV_ = empty(ENV)
fn = tempname()
touch(fn)
model_name = basename(fn)
Expand Down
3 changes: 1 addition & 2 deletions test/test_parse_mesh.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

using Base.Test

using AbaqusReader: element_has_type, element_has_nodes, parse_abaqus,
parse_section, abaqus_read_mesh

Expand Down Expand Up @@ -39,6 +37,7 @@ end
@test model["elements"][2]== [204, 199, 175, 130, 207, 208, 209, 3, 4, 176]
end


@testset "parse cube_tet4.inp mesh" begin
fn = joinpath(datadir, "cube_tet4.inp")
mesh = open(parse_abaqus, fn)
Expand Down
2 changes: 0 additions & 2 deletions test/test_parse_model.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE

using Base.Test

using AbaqusReader: abaqus_read_model
using AbaqusReader: parse_keyword

Expand Down

0 comments on commit 9294ded

Please sign in to comment.