Skip to content

Commit

Permalink
prototype approach to default packages; installing in site/
Browse files Browse the repository at this point in the history
as a demo, moves DataFmt out of Base. adds a line to default juliarc
so the functions are still available by default.
  • Loading branch information
JeffBezanson committed Sep 26, 2017
1 parent b2cbf31 commit 5cb8252
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 65 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default: $(JULIA_BUILD_MODE) # contains either "debug" or "release"
all: debug release

# sort is used to remove potential duplicates
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_man1dir))
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/site $(build_man1dir))
ifneq ($(BUILDROOT),$(JULIAHOME))
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src ui doc deps test test/perf examples examples/embedding)
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS))
Expand Down Expand Up @@ -50,6 +50,11 @@ endif

$(foreach dir,$(DIRS),$(eval $(call dir_target,$(dir))))
$(foreach link,base test,$(eval $(call symlink_target,$(link),$(build_datarootdir)/julia)))
$(eval $(call symlink_target,stdlib,$(build_datarootdir)/julia/site))

build_defaultpkgdir = $(build_datarootdir)/julia/site/$(shell echo $(VERSDIR))
$(build_defaultpkgdir): $(build_datarootdir)/julia/site/stdlib
mv $(build_datarootdir)/julia/site/stdlib $@

julia_flisp.boot.inc.phony: julia-deps
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/src julia_flisp.boot.inc.phony
Expand Down Expand Up @@ -81,7 +86,7 @@ ifndef JULIA_VAGRANT_BUILD
endif
endif

julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia/test
julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia/test $(build_defaultpkgdir)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/deps

julia-base: julia-deps $(build_sysconfdir)/julia/juliarc.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl
Expand Down
7 changes: 0 additions & 7 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1724,19 +1724,12 @@ import .LinAlg: diagm
@deprecate_binding φ MathConstants.φ
@deprecate_binding golden MathConstants.golden

# deprecate writecsv
@deprecate writecsv(io, a; opts...) writedlm(io, a, ','; opts...)

# PR #23271
function IOContext(io::IO; kws...)
depwarn("IOContext(io, k=v, ...) is deprecated, use IOContext(io, :k => v, ...) instead.", :IOContext)
IOContext(io, (k=>v for (k, v) in kws)...)
end

# deprecate readcsv
@deprecate readcsv(io; opts...) readdlm(io, ','; opts...)
@deprecate readcsv(io, T::Type; opts...) readdlm(io, ',', T; opts...)

@deprecate IOContext(io::IO, key, value) IOContext(io, key=>value)

# PR #23485
Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ export
readbytes!,
readchomp,
readdir,
readdlm,
readline,
readlines,
readuntil,
Expand All @@ -1069,7 +1068,6 @@ export
unmark,
watch_file,
write,
writedlm,
TCPSocket,
UDPSocket,

Expand Down
23 changes: 23 additions & 0 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,26 @@ function skipchars(io::IO, pred; linecomment=nothing)
end
return io
end

"""
countlines(io::IO, eol::Char='\\n')
Read `io` until the end of the stream/file and count the number of lines. To specify a file
pass the filename as the first argument. EOL markers other than `'\\n'` are supported by
passing them as the second argument.
"""
function countlines(io::IO, eol::Char='\n')
isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
aeol = UInt8(eol)
a = Vector{UInt8}(8192)
nl = 0
while !eof(io)
nb = readbytes!(io, a)
@simd for i=1:nb
@inbounds nl += a[i] == aeol
end
end
nl
end

countlines(f::AbstractString, eol::Char='\n') = open(io->countlines(io,eol), f)::Int
2 changes: 0 additions & 2 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ include("mmap.jl")
import .Mmap

# utilities - timing, help, edit
include("datafmt.jl")
using .DataFmt
include("deepcopy.jl")
include("interactiveutil.jl")
include("summarysize.jl")
Expand Down
9 changes: 1 addition & 8 deletions doc/src/stdlib/io-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Base.redirect_stdin(::Function, ::Any)
Base.readchomp
Base.truncate
Base.skipchars
Base.DataFmt.countlines
Base.countlines
Base.PipeBuffer
Base.readavailable
Base.IOContext
Expand Down Expand Up @@ -77,13 +77,6 @@ Base.readline
Base.readuntil
Base.readlines
Base.eachline
Base.DataFmt.readdlm(::Any, ::Char, ::Type, ::Char)
Base.DataFmt.readdlm(::Any, ::Char, ::Char)
Base.DataFmt.readdlm(::Any, ::Char, ::Type)
Base.DataFmt.readdlm(::Any, ::Char)
Base.DataFmt.readdlm(::Any, ::Type)
Base.DataFmt.readdlm(::Any)
Base.DataFmt.writedlm
Base.Base64.Base64EncodePipe
Base.Base64.Base64DecodePipe
Base.Base64.base64encode
Expand Down
1 change: 1 addition & 0 deletions etc/juliarc.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file should contain site-specific commands to be executed on Julia startup
# Users may store their own personal commands in the user home directory `homedir()`, in a file named `.juliarc.jl`

using DelimitedFiles
35 changes: 8 additions & 27 deletions base/datafmt.jl → stdlib/DelimitedFiles/src/DelimitedFiles.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

## file formats ##
__precompile__(true)

module DataFmt
module DelimitedFiles

import Base: _default_delims, tryparse_internal, show

export countlines, readdlm, writedlm
export readdlm, writedlm

Base.@deprecate readcsv(io; opts...) readdlm(io, ','; opts...)
Base.@deprecate readcsv(io, T::Type; opts...) readdlm(io, ',', T; opts...)
Base.@deprecate writecsv(io, a; opts...) writedlm(io, a, ','; opts...)

invalid_dlm(::Type{Char}) = reinterpret(Char, 0xfffffffe)
invalid_dlm(::Type{UInt8}) = 0xfe
Expand All @@ -15,29 +19,6 @@ invalid_dlm(::Type{UInt32}) = 0xfffffffe

const offs_chunk_size = 5000

countlines(f::AbstractString, eol::Char='\n') = open(io->countlines(io,eol), f)::Int

"""
countlines(io::IO, eol::Char='\\n')
Read `io` until the end of the stream/file and count the number of lines. To specify a file
pass the filename as the first argument. EOL markers other than `'\\n'` are supported by
passing them as the second argument.
"""
function countlines(io::IO, eol::Char='\n')
isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
aeol = UInt8(eol)
a = Vector{UInt8}(8192)
nl = 0
while !eof(io)
nb = readbytes!(io, a)
@simd for i=1:nb
@inbounds nl += a[i] == aeol
end
end
nl
end

"""
readdlm(source, T::Type; options...)
Expand Down Expand Up @@ -698,4 +679,4 @@ writedlm(io, a; opts...) = writedlm(io, a, '\t'; opts...)
show(io::IO, ::MIME"text/csv", a) = writedlm(io, a, ',')
show(io::IO, ::MIME"text/tab-separated-values", a) = writedlm(io, a, '\t')

end # module DataFmt
end # module DelimitedFiles
21 changes: 8 additions & 13 deletions test/datafmt.jl → stdlib/DelimitedFiles/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

@testset "countlines" begin
@test countlines(IOBuffer("\n")) == 1
@test countlines(IOBuffer("\n"),'\r') == 0
@test countlines(IOBuffer("\n\n\n\n\n\n\n\n\n\n")) == 10
@test countlines(IOBuffer("\n \n \n \n \n \n \n \n \n \n")) == 10
@test countlines(IOBuffer("\r\n \r\n \r\n \r\n \r\n")) == 5
file = tempname()
write(file,"Spiffy header\nspectacular first row\neven better 2nd row\nalmost done\n")
@test countlines(file) == 4
@test countlines(file,'\r') == 0
@test countlines(file,'\n') == 4
rm(file)
end
using Base.Test
using DelimitedFiles

isequaldlm(m1, m2, t) = isequal(m1, m2) && (eltype(m1) == eltype(m2) == t)

Expand Down Expand Up @@ -295,3 +284,9 @@ end

# issue #11484: useful error message for invalid readdlm filepath arguments
@test_throws ArgumentError readdlm(tempdir())

# displaying as text/csv
let d = TextDisplay(IOBuffer())
display(d, "text/csv", [3 1 4])
@test String(take!(d.io)) == "3,1,4\n"
end
2 changes: 1 addition & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function choosetests(choices = [])
"bigfloat", "sorting", "statistics", "spawn", "backtrace",
"file", "read", "mmap", "version", "resolve",
"pollfd", "mpfr", "broadcast", "complex", "socket",
"floatapprox", "datafmt", "reflection", "regex", "float16",
"floatapprox", "stdlib", "reflection", "regex", "float16",
"combinatorics", "sysinfo", "env", "rounding", "ranges", "mod2pi",
"euler", "show", "lineedit", "replcompletions", "repl",
"replutil", "sets", "test", "goto", "llvmcall", "llvmcall2", "grisu",
Expand Down
1 change: 1 addition & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
using Main.TestHelpers.OAs
using DelimitedFiles

const OAs_name = join(fullname(OAs), ".")

Expand Down
16 changes: 16 additions & 0 deletions test/read.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using DelimitedFiles

mktempdir() do dir

tasks = []
Expand Down Expand Up @@ -494,3 +496,17 @@ close(f2)
rm(f)

end # mktempdir() do dir

@testset "countlines" begin
@test countlines(IOBuffer("\n")) == 1
@test countlines(IOBuffer("\n"),'\r') == 0
@test countlines(IOBuffer("\n\n\n\n\n\n\n\n\n\n")) == 10
@test countlines(IOBuffer("\n \n \n \n \n \n \n \n \n \n")) == 10
@test countlines(IOBuffer("\r\n \r\n \r\n \r\n \r\n")) == 5
file = tempname()
write(file,"Spiffy header\nspectacular first row\neven better 2nd row\nalmost done\n")
@test countlines(file) == 4
@test countlines(file,'\r') == 0
@test countlines(file,'\n') == 4
rm(file)
end
3 changes: 0 additions & 3 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,7 @@ end
# don't use julia-specific `f` in Float32 printing (PR #18053)
@test sprint(print, 1f-7) == "1.0e-7"

# test that the REPL TextDisplay works for displaying arbitrary textual MIME types
let d = TextDisplay(IOBuffer())
display(d, "text/csv", [3 1 4])
@test String(take!(d.io)) == "3,1,4\n"
@test_throws MethodError display(d, "text/foobar", [3 1 4])
try
display(d, "text/foobar", [3 1 4])
Expand Down
1 change: 1 addition & 0 deletions test/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
srand(123)

using Base.SparseArrays.CHOLMOD
using DelimitedFiles

# based on deps/SuiteSparse-4.0.2/CHOLMOD/Demo/

Expand Down
5 changes: 5 additions & 0 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# test default packages

cd(joinpath(dirname(@__FILE__),"..","stdlib")) do
Pkg.Entry.test(convert(Vector{AbstractString}, readdir()))
end

0 comments on commit 5cb8252

Please sign in to comment.