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

Remove broken relpath macro #697

Merged
merged 1 commit into from
Oct 19, 2019
Merged
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
49 changes: 1 addition & 48 deletions src/Utils/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export @block_id,
convert_partition

# Usability
export @filename_to_png,
@relpath
export @filename_to_png

# internal conversion
export template_direction_symbols,
Expand Down Expand Up @@ -289,52 +288,6 @@ function source_path(default::Union{AbstractString, Nothing}="")
end
end

"""
@relpath(name)

Returns the path of the current code file.

### Input

- `name` -- file name

### Output

A string.

### Notes

This macro is handy, e.g., when calling a function that uses a file relative to
its own location.

For example, suppose that the folder `/home/projects/P1` contains the script `s.jl`
which loads the data `x.dat` and performs some calculations with it:

```julia
# file /home/projects/P1/s.jl
d = open(@relpath "x.dat")
# do stuff with d
```
In this example, the macro `@relpath "s.jl"` evaluates to the string
`/home/projects/P1/x.dat`. The script `s.jl` can be evaluated from the command line
from any folder, e.g. suppose that the path working directory is `/home/projects`,
then one can do `julia -e 'include("P1/s.jl")'` without having to change `s.jl`.
"""
macro relpath(name::String)
return quote
f = source_path()
if f == nothing
pathdir = ""
else
pathdir = join(split(f, "/")[1:end-1], "/")
end
if !isempty(pathdir)
pathdir = pathdir * "/"
end
pathdir * $name
end
end

"""
convert_partition(partition::AbstractVector{<:AbstractVector{Int}})::Union{
Vector{Int}, Vector{UnitRange{Int}}, Vector{Union{UnitRange{Int}, Int}}}
Expand Down