Skip to content

Commit

Permalink
Starting to make the REPL support a thing - references #124
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Nov 8, 2014
1 parent 40d3b71 commit bb85521
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Paket.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{BF60
docs\tools\generate.fsx = docs\tools\generate.fsx
LICENSE.txt = LICENSE.txt
nuget\Paket.Core.nuspec = nuget\Paket.Core.nuspec
paket.dependencies = paket.dependencies
nuget\Paket.nuspec = nuget\Paket.nuspec
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
Expand Down Expand Up @@ -43,6 +42,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
docs\content\paket-restore.md = docs\content\paket-restore.md
docs\content\paket-simplify.md = docs\content\paket-simplify.md
docs\content\paket-update.md = docs\content\paket-update.md
docs\content\reference-from-repl.fsx = docs\content\reference-from-repl.fsx
docs\content\references-files.md = docs\content\references-files.md
EndProjectSection
EndProject
Expand Down
8 changes: 8 additions & 0 deletions docs/content/reference-from-repl.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#I @"..\..\bin"
#r "Paket.Core.dll"

open Paket

Dependencies.Locate(__SOURCE_DIRECTORY__)

Dependencies.Add "FAKE"
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ nuget NuGet.CommandLine
nuget FSharp.Core.Microsoft.Signed

github forki/FsUnit FsUnit.fs
github fsharp/FAKE modules/Octokit/Octokit.fsx
github fsharp/FAKE modules/Octokit/Octokit.fsx
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NUGET
remote: https://nuget.org/api/v2
specs:
DotNetZip (1.9.3)
FAKE (3.8.5)
FAKE (3.9.0)
FSharp.Compiler.Service (0.0.67)
FSharp.Core.Microsoft.Signed (3.1.1.1)
FSharp.Formatting (2.4.36)
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open System.IO
let DefaultNugetStream = "https://nuget.org/api/v2"

[<Literal>]
let DependenciesFile = "paket.dependencies"
let DependenciesFileName = "paket.dependencies"

[<Literal>]
let ReferencesFile = "paket.references"
Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -274,32 +274,32 @@ type DependenciesFile(fileName,options,packages : PackageRequirement list, remot

member this.Add(packageName,version:string) =
if this.HasPackage packageName then
traceWarnfn "%s contains package %s already. ==> Ignored" Constants.DependenciesFile packageName
traceWarnfn "%s contains package %s already. ==> Ignored" Settings.DependenciesFile packageName
this
else
tracefn "Adding %s %s to %s" packageName version Constants.DependenciesFile
tracefn "Adding %s %s to %s" packageName version Settings.DependenciesFile
this.AddAdditionionalPackage(packageName,version)

member this.Remove(packageName) =
if this.HasPackage packageName then
tracefn "Removing %s from %s" packageName Constants.DependenciesFile
tracefn "Removing %s from %s" packageName Settings.DependenciesFile
this.RemovePackage(packageName)
else
traceWarnfn "%s doesn't contain package %s. ==> Ignored" Constants.DependenciesFile packageName
traceWarnfn "%s doesn't contain package %s. ==> Ignored" Settings.DependenciesFile packageName
this

member this.UpdatePackageVersion(packageName, version) =
if this.HasPackage(packageName) then
let versionRequirement = DependenciesFileParser.parseVersionRequirement version
tracefn "Updating %s version to %s in %s" packageName version Constants.DependenciesFile
tracefn "Updating %s version to %s in %s" packageName version Settings.DependenciesFile
let packages =
this.Packages |> List.map (fun p ->
if p.Name.ToLower() = packageName.ToLower() then
{ p with VersionRequirement = versionRequirement }
else p)
DependenciesFile(this.FileName, this.Options, packages, this.RemoteFiles)
else
traceWarnfn "%s doesn't contain package %s. ==> Ignored" Constants.DependenciesFile packageName
traceWarnfn "%s doesn't contain package %s. ==> Ignored" Settings.DependenciesFile packageName
this

override __.ToString() =
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/FindOutdated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Paket.Logging
/// Finds all outdated packages.
let FindOutdated(strict,includingPrereleases) =
//TODO: Anything we need to do for source files here?
let loadedFile = DependenciesFile.ReadFromFile Constants.DependenciesFile
let loadedFile = DependenciesFile.ReadFromFile Settings.DependenciesFile
let dependenciesFile =
let newPackages =
loadedFile.Packages
Expand Down
15 changes: 15 additions & 0 deletions src/Paket.Core/Interactive.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Paket

open System.IO

/// Paket API which is optimized for REPL use.
type Dependencies private () =
/// Tries to locate the paket.dependencies file in one the given folder or a parent folder.
static member Locate(path) =
Settings.DependenciesFile <- Settings.findDependenciesFileInPath true (DirectoryInfo path)

/// Adds the given package without version requirements to the dependencies file.
static member Add(package) = Dependencies.Add(package,"")

/// Adds the given package with the given version to the dependencies file.
static member Add(package,version) = AddProcess.Add(package, version, false, false, false, false)
16 changes: 8 additions & 8 deletions src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,28 @@ let private convertNugetsToDepFile(nugetPackagesConfigs, nugetConfig) =
let latestVersions = allVersions |> Seq.map (fun (name,versions) -> name, versions |> Seq.max |> string) |> Seq.toList

let existingDepFile =
if File.Exists Constants.DependenciesFile
then Some(DependenciesFile.ReadFromFile(Constants.DependenciesFile))
if File.Exists Settings.DependenciesFile
then Some(DependenciesFile.ReadFromFile(Settings.DependenciesFile))
else None

let confictingPackages, packagesToAdd =
match existingDepFile with
| Some depFile -> latestVersions |> List.partition (fun (name,_) -> depFile.HasPackage name)
| None -> [], latestVersions

for (name, _) in confictingPackages do traceWarnfn "Package %s is already defined in %s" name Constants.DependenciesFile
for (name, _) in confictingPackages do traceWarnfn "Package %s is already defined in %s" name Settings.DependenciesFile

let nugetPackageRequirement (name: string, v: string, sources : list<PackageSource>) =
{Requirements.PackageRequirement.Name = name
Requirements.PackageRequirement.VersionRequirement = VersionRequirement(VersionRange.Specific(SemVer.Parse v), PreReleaseStatus.No)
Requirements.PackageRequirement.ResolverStrategy = Max
Requirements.PackageRequirement.Sources = sources
Requirements.PackageRequirement.Parent = Requirements.PackageRequirementSource.DependenciesFile(Constants.DependenciesFile)}
Requirements.PackageRequirement.Parent = Requirements.PackageRequirementSource.DependenciesFile(Settings.DependenciesFile)}

match existingDepFile with
| None ->
let packages = packagesToAdd |> List.map (fun (name,v) -> nugetPackageRequirement(name,v,nugetConfig.PackageSources))
DependenciesFile(Constants.DependenciesFile, InstallOptions.Default, packages, []).Save()
DependenciesFile(Settings.DependenciesFile, InstallOptions.Default, packages, []).Save()
| Some depFile ->
if not (packagesToAdd |> List.isEmpty)
then (packagesToAdd |> List.fold (fun (d : DependenciesFile) (name,version) -> d.Add(name,version)) depFile).Save()
Expand Down Expand Up @@ -153,7 +153,7 @@ let private convertNugetToRefFile(nugetPackagesConfig) =

/// Converts all projects from NuGet to Paket
let ConvertFromNuget(force, installAfter, initAutoRestore) =
if File.Exists Constants.DependenciesFile && not force then failwithf "%s already exists, use --force to overwrite" Constants.DependenciesFile
if File.Exists Settings.DependenciesFile && not force then failwithf "%s already exists, use --force to overwrite" Settings.DependenciesFile

let nugetPackagesConfigs = FindAllFiles(".", "packages.config") |> Seq.map Nuget.ReadPackagesConfig
let nugetConfig = readNugetConfig()
Expand All @@ -174,7 +174,7 @@ let ConvertFromNuget(force, installAfter, initAutoRestore) =
let solution = SolutionFile(slnFile.FullName)
solution.RemoveNugetEntries()
let relativePath = createRelativePath solution.FileName Environment.CurrentDirectory
solution.AddPaketFolder(Path.Combine(relativePath, Constants.DependenciesFile),
solution.AddPaketFolder(Path.Combine(relativePath, Settings.DependenciesFile),
if installAfter then Some(Path.Combine(relativePath, "paket.lock")) else None)
solution.Save()

Expand All @@ -196,7 +196,7 @@ let ConvertFromNuget(force, installAfter, initAutoRestore) =
if File.Exists nugetExe then
traceWarnfn "Removing NuGet.exe and adding Nuget.CommandLine as dependency instead. Please check all paths."
removeFile nugetExe
let depFile = DependenciesFile.ReadFromFile(Constants.DependenciesFile)
let depFile = DependenciesFile.ReadFromFile(Settings.DependenciesFile)
if not <| depFile.HasPackage("NuGet.CommandLine") then
depFile.Add("NuGet.CommandLine", "").Save()

Expand Down
2 changes: 2 additions & 0 deletions src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="VersionRange.fs" />
<Compile Include="Constants.fs" />
<Compile Include="Logging.fs" />
<Compile Include="Settings.fs" />
<Compile Include="Xml.fs" />
<Compile Include="Utils.fs" />
<Compile Include="PackageSources.fs" />
Expand Down Expand Up @@ -101,6 +102,7 @@
<Compile Include="NugetConvert.fs" />
<Compile Include="FindOutdated.fs" />
<Compile Include="BindingRedirects.fs" />
<Compile Include="Interactive.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ let internal restore(sources, force, lockFile:LockFile, packages:Set<string>) =
Async.Parallel(sourceFileDownloads,packageDownloads)

let Restore(force,referencesFileNames) =
let lockFileName = DependenciesFile.FindLockfile Constants.DependenciesFile
let lockFileName = DependenciesFile.FindLockfile Settings.DependenciesFile

let sources, lockFile =
if not lockFileName.Exists then
failwithf "paket.lock doesn't exist."
else
let sources =
Constants.DependenciesFile
Settings.DependenciesFile
|> File.ReadAllLines
|> PackageSourceParser.getSources
sources, LockFile.LoadFrom(lockFileName.FullName)
Expand Down
21 changes: 21 additions & 0 deletions src/Paket.Core/Settings.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Paket.Settings

open System
open System.IO
open Paket.Logging

let rec internal findDependenciesFileInPath withError (dir:DirectoryInfo) =
let path = Path.Combine(dir.FullName,Constants.DependenciesFileName)
if File.Exists(path) then
path
else
let parent = dir.Parent
if parent = null then
if withError then
failwithf "Could not find %s" Constants.DependenciesFileName
else
Constants.DependenciesFileName
else
findDependenciesFileInPath withError parent

let mutable DependenciesFile = findDependenciesFileInPath false (DirectoryInfo Environment.CurrentDirectory)
6 changes: 3 additions & 3 deletions src/Paket.Core/Simplifier.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ let Analyze(allPackages : list<ResolvedPackage>, depFile : DependenciesFile, ref
DependenciesFile(depFile.FileName, depFile.Options, simplifiedDeps, depFile.RemoteFiles), refFiles'

let Simplify (interactive) =
if not <| File.Exists(Constants.DependenciesFile) then
failwithf "%s file not found." Constants.DependenciesFile
let depFile = DependenciesFile.ReadFromFile(Constants.DependenciesFile)
if not <| File.Exists(Settings.DependenciesFile) then
failwithf "%s file not found." Settings.DependenciesFile
let depFile = DependenciesFile.ReadFromFile(Settings.DependenciesFile)
let lockFilePath = depFile.FindLockfile()
if not <| File.Exists(lockFilePath.FullName) then
failwith "lock file not found. Create lock file by running paket install."
Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Core/UpdateProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ open System.IO

/// Update command
let Update(forceResolution, force, hard) =
let lockFileName = DependenciesFile.FindLockfile Constants.DependenciesFile
let lockFileName = DependenciesFile.FindLockfile Settings.DependenciesFile

let sources, lockFile =
if forceResolution || not lockFileName.Exists then
let dependenciesFile = DependenciesFile.ReadFromFile Constants.DependenciesFile
let dependenciesFile = DependenciesFile.ReadFromFile Settings.DependenciesFile
let resolution = dependenciesFile.Resolve(force)
let lockFile =
LockFile
Expand All @@ -20,7 +20,7 @@ let Update(forceResolution, force, hard) =
dependenciesFile.Sources, lockFile
else
let sources =
Constants.DependenciesFile
Settings.DependenciesFile
|> File.ReadAllLines
|> PackageSourceParser.getSources
sources, LockFile.LoadFrom(lockFileName.FullName)
Expand All @@ -39,7 +39,7 @@ let private fixOldDependencies (oldLockFile:LockFile) (dependenciesFile:Dependen
dependenciesFile

let updateWithModifiedDependenciesFile(dependenciesFile:DependenciesFile,packageName:string, force) =
let lockFileName = DependenciesFile.FindLockfile Constants.DependenciesFile
let lockFileName = DependenciesFile.FindLockfile Settings.DependenciesFile

if not lockFileName.Exists then
let resolution = dependenciesFile.Resolve(force)
Expand All @@ -62,12 +62,12 @@ let updateWithModifiedDependenciesFile(dependenciesFile:DependenciesFile,package

/// Update a single package command
let UpdatePackage(packageName : string, newVersion, force, hard) =
let lockFileName = DependenciesFile.FindLockfile Constants.DependenciesFile
let lockFileName = DependenciesFile.FindLockfile Settings.DependenciesFile
if not lockFileName.Exists then Update(true, force, hard) else

let sources, lockFile =
let dependenciesFile =
let depFile = DependenciesFile.ReadFromFile Constants.DependenciesFile
let depFile = DependenciesFile.ReadFromFile Settings.DependenciesFile
match newVersion with
| Some newVersion ->
let depFile = depFile.UpdatePackageVersion(packageName, newVersion)
Expand Down
3 changes: 2 additions & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<OutputPath>..\..\bin</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>..\..\bin\Paket.xml</DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<StartArguments>update -f</StartArguments>
<StartWorkingDirectory>D:\code\paketkopie</StartWorkingDirectory>
</PropertyGroup>
Expand Down

0 comments on commit bb85521

Please sign in to comment.