Skip to content

Commit

Permalink
Unitful -> Unitfu
Browse files Browse the repository at this point in the history
modified:   Manifest.toml
modified:   Project.toml
modified:   README.md
modified:   src/MechanicalUnits.jl
modified:   src/import_export_units.jl
modified:   src/internal_functions.jl
modified:   test/pretty-print.jl
  • Loading branch information
hustf committed Aug 11, 2020
1 parent 00296a5 commit 26bd604
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.
6 changes: 2 additions & 4 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[Unitful]]
[[Unitfu]]
deps = ["ConstructionBase", "LinearAlgebra", "Random"]
git-tree-sha1 = "d045383854a8f2166ace59063e0910590690d910"
repo-rev = "master"
repo-url = "https://github.com/hustf/Unitfu.jl"
path = "C:\\Users\\F\\.julia\\dev\\Unitfu"
uuid = "5ee08b94-2369-4f4a-b8c7-99333ba35fb0"
version = "1.3.0"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "5ee08b94-2369-4f4a-b8c7-99333ba35fb0"
Unitfu = "5ee08b94-2369-4f4a-b8c7-99333ba35fb0"

[compat]
julia = "1.3.0"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ julia> δ.([5, 6, 8]mm)
2.7411673364058977

julia> d = 6mm
ERROR: cannot assign variable Unitful.d from module Main
ERROR: cannot assign variable Unitfu.d from module Main
Stacktrace:
[1] top-level scope at none:0

Expand Down Expand Up @@ -182,14 +182,14 @@ julia> (1.0cm², 2.0mm∙m, 3.0dm⁴/m² ) .|> mm²
julia> @import_expand dyn # This unit is not exported by default

julia> typeof(dyn)
Unitful.FreeUnits{(dyn,), ᴸ ᵀ⁻²,nothing}
Unitfu.FreeUnits{(dyn,), ᴸ ᵀ⁻²,nothing}

julia> 1dyn |> μm
10kgμms⁻²
```

## Goals
This adaption of a [fork](https://github.com/hustf/Unitful.jl) of [Unitful.jl](https://github.com/PainterQubits/Unitful.jl) aims to be a tool for quick side calculations in an office computer.
This dependency of a [fork](https://github.com/hustf/Unitfu.jl) of [Unitful.jl](https://github.com/PainterQubits/Unitful.jl) aims to be a tool for quick side calculations in an office computer.

This means:
* We pick a set of units as commonly used in mechanical industry
Expand Down
34 changes: 17 additions & 17 deletions src/MechanicalUnits.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
module MechanicalUnits
using Unitful
using Unitfu
# Exported infix function / operator
export
# Import / exports for short and parseable type signatures
import Unitful: Time, Length, Mass, Temperature, Current, Luminosity, Amount
import Unitful: ᵀ , ᴸ , ᴹ , ᶿ, ᴶ , ᴺ
import Unitfu: Time, Length, Mass, Temperature, Current, Luminosity, Amount
import Unitfu: ᵀ , ᴸ , ᴹ , ᶿ, ᴶ , ᴺ
export Time, Length, Mass, Temperature, Current, Luminosity, Amount, Level
export ᵀ , ᴸ , ᴹ , ᶿ , ᴶ , ᴺ
export Quantity, DimensionlessQuantity, NoUnits, NoDims
import Unitful:
import Unitfu:
FreeUnits, AffineUnits, Affine, AffineQuantity, Unitlike, Unit, Dimension, Dimensions, Units
export FreeUnits, AffineUnits, Affine, AffineQuantity, Unitlike, Unit, Dimensions, Dimension, Units
export Level, Gain

# For importinng from Unitful, or defining more units
# For importinng from Unitfu, or defining more units
export @import_expand, @unit, @u_str

# Reexported functions from Unitful
# Reexported functions from Unitfu
export logunit, unit, absoluteunit, dimension, uconvert, ustrip, upreferred,
export uconvertp, uconvertrp, reflevel, linear

# Useful functions that are not exported by Unitful.
# Useful functions that are not exported by Unitfu.
export preferunits, convfact

# A vector of all the exported units. This is printed during precompilation.
export MECH_UNITS

import Unitful: isunitless, sortexp, showrep, abbr, prefix, power, superscript, tens, genericunit
import Unitful: promote_unit, preferunits, convfact
import Unitfu: isunitless, sortexp, showrep, abbr, prefix, power, superscript, tens, genericunit
import Unitfu: promote_unit, preferunits, convfact
# derived dimensions
import Unitful: Area, Acceleration, Force, Pressure, Density
import Unitful: Velocity
import Unitful:ForceFreeUnits, PressureFreeUnits, EnergyFreeUnits, AreaFreeUnits, DensityFreeUnits, VolumeFreeUnits
import Unitfu: Area, Acceleration, Force, Pressure, Density
import Unitfu: Velocity
import Unitfu:ForceFreeUnits, PressureFreeUnits, EnergyFreeUnits, AreaFreeUnits, DensityFreeUnits, VolumeFreeUnits
export Area, Acceleration, Force, Pressure, Density, Velocity
# Units are exported in 'import_export_units.jl'.

Expand All @@ -46,14 +46,14 @@ eval(exponents_superscripts(:ᶿ))
eval(exponents_superscripts(:ᴶ))
eval(exponents_superscripts(:ᴺ))

# Used for registering units with Unitful macros during initialisation.
const localunits = Unitful.basefactors
# Used for registering units with Unitfu macros during initialisation.
const localunits = Unitfu.basefactors

function __init__()
# This is for evaluating Unitful macros in the context of this package.
merge!(Unitful.basefactors, localunits)
# This is for evaluating Unitfu macros in the context of this package.
merge!(Unitfu.basefactors, localunits)
# This enables any units defined here to be used in the @u_str
Unitful.register(MechanicalUnits)
Unitfu.register(MechanicalUnits)
# This pre-selects some useful units for the mechanical engineering domain
preferunits(kg, mm, s, K)
Sys.iswindows() && push!(ENV, "UNITFUL_FANCY_EXPONENTS" => "true")
Expand Down
14 changes: 7 additions & 7 deletions src/import_export_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end
# U.S. units
@import_expand inch ft lb lbf
# affine units
@import_affine_from_unitful °C °F
@import_affine_from_Unitfu °C °F
abbr(::genericunit(°C)) = "°C"
abbr(::genericunit(°F)) = "°F"
# preferred capitalization units
Expand Down Expand Up @@ -123,23 +123,23 @@ end
100.0 0.1
=#

Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:ForceFreeUnits, T<:ForceFreeUnits} = kN

#= example
[10N/mm^2 100000000N/m^2]
1×2 Array{Rational{Int64}{MPa},2}:
(10//1) (100//1)
=#
Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:PressureFreeUnits, T<:PressureFreeUnits} = MPa

#= example
[10000000N*mm 1000.0J]
1×2 Array{Float64{kNm},2}:
10.0 1.0
=#
Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:EnergyFreeUnits, T<:EnergyFreeUnits} = kNm

#= example
Expand All @@ -148,7 +148,7 @@ Unitful.promote_unit(::S, ::T) where
1×2 Array{Float64{cm²},2}:
1000.0 100.0
=#
Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:AreaFreeUnits, T<:AreaFreeUnits} = cm²


Expand All @@ -157,13 +157,13 @@ Unitful.promote_unit(::S, ::T) where
1×2 Array{Float64{kg∙m^-3},2}:
1000.0 2.0
=#
Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:DensityFreeUnits, T<:DensityFreeUnits} = kg/

#= example
[1/12*100mm*40mm^3/50mm 1l]
1×2 Array{Float64{cm³},2}:
0.00666667 1000.0
=#
Unitful.promote_unit(::S, ::T) where
Unitfu.promote_unit(::S, ::T) where
{S<:VolumeFreeUnits, T<:VolumeFreeUnits} = cm³
12 changes: 6 additions & 6 deletions src/internal_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
# The below macros and functions are based on https://github.com/JuliaAstro/UnitfulAstro.jl/blob/master/src/UnitfulAstro.jl

"""
Import non-affine units from Unitful.
Import non-affine units from Unitfu.
Expand to also include exponents -4 to 4.
"""
macro import_expand(args...)
Expand All @@ -42,15 +42,15 @@ macro import_expand(args...)
sym′ = Symbol(prefix, sym)
# Some prefix+baseunit are excluded:
if sym′ exclude_import
push!(expr.args, :(import MechanicalUnits.Unitful.$sym′))
push!(expr.args, :(import MechanicalUnits.Unitfu.$sym′))
# AstroUnits don't reexport, but we do:
push!(expr.args, :(export $sym′))
push!(MECH_UNITS, sym′)
push!(expr.args, exponents_superscripts(sym′))
end
end
else
push!(expr.args, :(import MechanicalUnits.Unitful.$sym))
push!(expr.args, :(import MechanicalUnits.Unitfu.$sym))
# AstroUnits don't reexport, but we do:
push!(expr.args, :(export $sym))
push!(MECH_UNITS, sym)
Expand All @@ -59,11 +59,11 @@ macro import_expand(args...)
end
esc(expr)
end
"Import affine units from Unitful."
macro import_affine_from_unitful(args...)
"Import affine units from Unitfu."
macro import_affine_from_Unitfu(args...)
expr = Expr(:block)
for arg in args
push!(expr.args, :(import MechanicalUnits.Unitful.$arg))
push!(expr.args, :(import MechanicalUnits.Unitfu.$arg))
# AstroUnits don't reexport, but we do:
push!(expr.args, :(export $arg))
push!(MECH_UNITS, arg)
Expand Down
2 changes: 1 addition & 1 deletion test/pretty-print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
longp((1//100)kg) == "(1//100)\e[36mkg\e[39m"
end
@testset "Constructors from type signatures" begin
# Unitful now prints shorter type signatures, which
# Unitfu now prints shorter type signatures, which
# on reconstruction makes FreeUnits instead of the original.
# The shorter output is more readable.
end
Expand Down

0 comments on commit 26bd604

Please sign in to comment.