Skip to content

Commit 4994a79

Browse files
authored
Use Blue style (#100)
1 parent acfadfa commit 4994a79

18 files changed

+297
-257
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style="blue"

.github/workflows/Format.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Format
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: only if it is a pull request build.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
11+
12+
jobs:
13+
format:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: julia-actions/setup-julia@latest
18+
with:
19+
version: 1
20+
- name: Format code
21+
run: |
22+
using Pkg
23+
Pkg.add(; name="JuliaFormatter", uuid="98e50ef6-434e-11e9-1051-2b60c6c9e899")
24+
using JuliaFormatter
25+
format("."; verbose=true)
26+
shell: julia --color=yes {0}
27+
- uses: reviewdog/action-suggester@v1
28+
if: github.event_name == 'pull_request'
29+
with:
30+
tool_name: JuliaFormatter
31+
fail_on_error: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Abstract types and interfaces for Markov chain Monte Carlo methods.
88
[![IntegrationTest](https://github.com/TuringLang/AbstractMCMC.jl/workflows/IntegrationTest/badge.svg?branch=master)](https://github.com/TuringLang/AbstractMCMC.jl/actions?query=workflow%3AIntegrationTest+branch%3Amaster)
99
[![Codecov](https://codecov.io/gh/TuringLang/AbstractMCMC.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/TuringLang/AbstractMCMC.jl)
1010
[![Coveralls](https://coveralls.io/repos/github/TuringLang/AbstractMCMC.jl/badge.svg?branch=master)](https://coveralls.io/github/TuringLang/AbstractMCMC.jl?branch=master)
11+
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)

docs/make.jl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@ using AbstractMCMC
22
using Documenter
33
using Random
44

5-
DocMeta.setdocmeta!(
6-
AbstractMCMC,
7-
:DocTestSetup,
8-
:(using AbstractMCMC);
9-
recursive=true,
10-
)
5+
DocMeta.setdocmeta!(AbstractMCMC, :DocTestSetup, :(using AbstractMCMC); recursive=true)
116

127
makedocs(;
138
sitename="AbstractMCMC",
149
format=Documenter.HTML(),
1510
modules=[AbstractMCMC],
16-
pages=[
17-
"Home" => "index.md",
18-
"api.md",
19-
"design.md",
20-
],
11+
pages=["Home" => "index.md", "api.md", "design.md"],
2112
strict=true,
2213
checkdocs=:exports,
2314
)
2415

25-
deploydocs(;
26-
repo="github.com/TuringLang/AbstractMCMC.jl.git", push_preview=true
27-
)
16+
deploydocs(; repo="github.com/TuringLang/AbstractMCMC.jl.git", push_preview=true)

src/AbstractMCMC.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module AbstractMCMC
22

3-
import BangBang
4-
import ConsoleProgressMonitor
5-
import LoggingExtras
6-
import ProgressLogging
7-
import StatsBase
8-
import TerminalLoggers
9-
import Transducers
10-
11-
import Distributed
12-
import Logging
13-
import Random
3+
using BangBang: BangBang
4+
using ConsoleProgressMonitor: ConsoleProgressMonitor
5+
using LoggingExtras: LoggingExtras
6+
using ProgressLogging: ProgressLogging
7+
using StatsBase: StatsBase
8+
using TerminalLoggers: TerminalLoggers
9+
using Transducers: Transducers
10+
11+
using Distributed: Distributed
12+
using Logging: Logging
13+
using Random: Random
1414

1515
# Reexport sample
1616
using StatsBase: sample
@@ -71,7 +71,6 @@ processes.
7171
"""
7272
struct MCMCDistributed <: AbstractMCMCEnsemble end
7373

74-
7574
"""
7675
MCMCSerial
7776

src/deprecations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Deprecate the old name AbstractMCMCParallel in favor of AbstractMCMCEnsemble
2-
Base.@deprecate_binding AbstractMCMCParallel AbstractMCMCEnsemble false
2+
Base.@deprecate_binding AbstractMCMCParallel AbstractMCMCEnsemble false

src/interface.jl

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,14 @@ be specified with the `chain_type` argument.
3030
By default, this method returns `samples`.
3131
"""
3232
function bundle_samples(
33-
samples,
34-
::AbstractModel,
35-
::AbstractSampler,
36-
::Any,
37-
::Type;
38-
kwargs...
33+
samples, ::AbstractModel, ::AbstractSampler, ::Any, ::Type; kwargs...
3934
)
4035
return samples
4136
end
4237

4338
function bundle_samples(
44-
samples::Vector,
45-
::AbstractModel,
46-
::AbstractSampler,
47-
::Any,
48-
::Type{Vector{T}};
49-
kwargs...
50-
) where T
39+
samples::Vector, ::AbstractModel, ::AbstractSampler, ::Any, ::Type{Vector{T}}; kwargs...
40+
) where {T}
5141
return map(samples) do sample
5242
convert(T, sample)
5343
end
@@ -74,24 +64,13 @@ sample is `sample`.
7464
7565
The method can be called with and without a predefined number `N` of samples.
7666
"""
77-
function samples(
78-
sample,
79-
::AbstractModel,
80-
::AbstractSampler,
81-
N::Integer;
82-
kwargs...
83-
)
67+
function samples(sample, ::AbstractModel, ::AbstractSampler, N::Integer; kwargs...)
8468
ts = Vector{typeof(sample)}(undef, 0)
8569
sizehint!(ts, N)
8670
return ts
8771
end
8872

89-
function samples(
90-
sample,
91-
::AbstractModel,
92-
::AbstractSampler;
93-
kwargs...
94-
)
73+
function samples(sample, ::AbstractModel, ::AbstractSampler; kwargs...)
9574
return Vector{typeof(sample)}(undef, 0)
9675
end
9776

@@ -113,35 +92,23 @@ function save!!(
11392
::AbstractModel,
11493
::AbstractSampler,
11594
N::Integer;
116-
kwargs...
95+
kwargs...,
11796
)
11897
s = BangBang.push!!(samples, sample)
11998
s !== samples && sizehint!(s, N)
12099
return s
121100
end
122101

123102
function save!!(
124-
samples,
125-
sample,
126-
iteration::Integer,
127-
::AbstractModel,
128-
::AbstractSampler;
129-
kwargs...
103+
samples, sample, iteration::Integer, ::AbstractModel, ::AbstractSampler; kwargs...
130104
)
131105
return BangBang.push!!(samples, sample)
132106
end
133107

134108
# Deprecations
135109
Base.@deprecate transitions(
136-
transition,
137-
model::AbstractModel,
138-
sampler::AbstractSampler,
139-
N::Integer;
140-
kwargs...
110+
transition, model::AbstractModel, sampler::AbstractSampler, N::Integer; kwargs...
141111
) samples(transition, model, sampler, N; kwargs...) false
142112
Base.@deprecate transitions(
143-
transition,
144-
model::AbstractModel,
145-
sampler::AbstractSampler;
146-
kwargs...
113+
transition, model::AbstractModel, sampler::AbstractSampler; kwargs...
147114
) samples(transition, model, sampler; kwargs...) false

src/logging.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
# and add a custom progress logger if the current logger does not seem to be able to handle
33
# progress logs
44
macro ifwithprogresslogger(progress, exprs...)
5-
return quote
6-
if $progress
7-
if $hasprogresslevel($Logging.current_logger())
8-
$ProgressLogging.@withprogress $(exprs...)
9-
else
10-
$with_progresslogger($Base.@__MODULE__, $Logging.current_logger()) do
5+
return esc(
6+
quote
7+
if $progress
8+
if $hasprogresslevel($Logging.current_logger())
119
$ProgressLogging.@withprogress $(exprs...)
10+
else
11+
$with_progresslogger($Base.@__MODULE__, $Logging.current_logger()) do
12+
$ProgressLogging.@withprogress $(exprs...)
13+
end
1214
end
15+
else
16+
$(exprs[end])
1317
end
14-
else
15-
$(exprs[end])
16-
end
17-
end |> esc
18+
end,
19+
)
1820
end
1921

2022
# improved checks?
@@ -31,13 +33,14 @@ function with_progresslogger(f, _module, logger)
3133
log._module !== _module || log.level != ProgressLogging.ProgressLevel
3234
end
3335

34-
Logging.with_logger(f, LoggingExtras.TeeLogger(logger1, logger2))
36+
return Logging.with_logger(f, LoggingExtras.TeeLogger(logger1, logger2))
3537
end
3638

3739
function progresslogger()
3840
# detect if code is running under IJulia since TerminalLogger does not work with IJulia
3941
# https://github.com/JuliaLang/IJulia.jl#detecting-that-code-is-running-under-ijulia
40-
if (Sys.iswindows() && VERSION < v"1.5.3") || (isdefined(Main, :IJulia) && Main.IJulia.inited)
42+
if (Sys.iswindows() && VERSION < v"1.5.3") ||
43+
(isdefined(Main, :IJulia) && Main.IJulia.inited)
4144
return ConsoleProgressMonitor.ProgressLogger()
4245
else
4346
return TerminalLoggers.TerminalLogger()

0 commit comments

Comments
 (0)