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

Issue #340 : Remote links for single file: HTTP (fsnip, etc.) and Gist #353

Merged
merged 3 commits into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Even more importantly: If two packages reference conflicting versions of a packa
Paket on the other hand maintains this information on a consistent and stable basis within the [`paket.lock` file][7] in the solution root.
This file, together with the [`paket.dependencies` file][8] enables you to determine exactly what's happening with your dependencies.

Paket also enables you to [reference files directly from GitHub][9] repositories.
Paket also enables you to [reference files directly from GitHub (and Gist)][9] repositories or any http-resource.

For more reasons see the [FAQ][10].

Expand Down
7 changes: 6 additions & 1 deletion docs/content/dependencies-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ To give you an overview, consider the following `paket.dependencies` file:
nuget DotNetZip >= 1.9
nuget SourceLink.Fake
github forki/FsUnit FsUnit.fs
gist Thorium/1972349 timestamp.fs
http http://www.fssnip.net/1n decrypt.fs

The file specifies that Paket's NuGet dependencies should be downloaded from [nuget.org](http://www.nuget.org) and that we need:

Expand All @@ -19,6 +21,8 @@ The file specifies that Paket's NuGet dependencies should be downloaded from [nu
* [DotNetZip](http://dotnetzip.codeplex.com/) with version which is at [least 1.9](http://fsprojects.github.io/Paket/nuget-dependencies.html#Greater-than-or-equal-version-constraint)
* [SourceLink.Fake](https://github.com/ctaggart/SourceLink) in the latest version
* [FSUnit.fs](https://github.com/forki/FsUnit) from GitHub.
* Gist number [1972349](https://gist.github.com/Thorium/1972349) from GitHub Gist.
* External HTTP-resource, e.g. [1n](http://www.fssnip.net/1n) from [FSSnip](http://www.fssnip.net/) -site.

Paket uses this definition to compute a concrete dependency resolution, which also includes indirect dependencies. The resulting dependency graph is then persisted to the [`paket.lock` file](lock-file.html).

Expand All @@ -29,7 +33,8 @@ Only direct dependencies should be listed and you can use the [`paket simplify`
Paket supports the following source types:

* [NuGet](nuget-dependencies.html)
* [GitHub](github-dependencies.html)
* [GitHub and Gist](github-dependencies.html)
* HTTP (any single file from any site without version control)

## Strict references

Expand Down
21 changes: 19 additions & 2 deletions docs/content/github-dependencies.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitHub dependencies

Paket allows one to automatically manage the linking of files from [github.com](http://www.github.com) into your projects.
Paket allows one to automatically manage the linking of files from [github.com](http://www.github.com) or [gist.github.com](https://gist.github.com/) into your projects.

## Referencing a single file

Expand Down Expand Up @@ -89,4 +89,21 @@ This generates the following [`paket.lock` file](lock-file.html):
modules/Octokit/Octokit.fsx (a25c2f256a99242c1106b5a3478aae6bb68c7a93)
Octokit (>= 0)

As you can see Paket also resolved the Octokit dependency.
As you can see Paket also resolved the Octokit dependency.

## Gist

Gist works the same way. You can fetch single files or multi-file-gists as well:

gist Thorium/1972308 gistfile1.fs
gist Thorium/6088882

If you run the [`paket update` command](paket-update.html), it will add a new section to your [`paket.lock` file](lock-file.html):

GIST
remote: Thorium/1972308
specs:
gistfile1.fs
remote: Thorium/6088882
specs:
FULLPROJECT
58 changes: 44 additions & 14 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,41 @@ module DependenciesFileParser =
|> List.rev
|> List.toArray


let private ``parse git source`` trimmed origin originTxt =
let parts = parseDependencyLine trimmed
let getParts (projectSpec:string) =
match projectSpec.Split [|':'; '/'|] with
| [| owner; project |] -> owner, project, None
| [| owner; project; commit |] -> owner, project, Some commit
| _ -> failwithf "invalid %s specification:%s %s" originTxt Environment.NewLine trimmed
match parts with
| [| _; projectSpec; fileSpec |] -> origin, getParts projectSpec, fileSpec
| [| _; projectSpec; |] -> origin, getParts projectSpec, RemoteDownload.FullProjectSourceFileName
| _ -> failwithf "invalid %s specification:%s %s" originTxt Environment.NewLine trimmed

let private ``parse http source`` trimmed =
let parts = parseDependencyLine trimmed
let getParts (projectSpec:string) fileSpec =
let ``project spec`` =
match projectSpec.EndsWith("/") with
| false -> projectSpec
| true -> projectSpec.Substring(0, projectSpec.Length-1)
let splitted = ``project spec``.Split [|':'; '/'|]
let fileName = match String.IsNullOrEmpty(fileSpec) with
| true -> (splitted |> Seq.last) + ".fs"
| false -> fileSpec
match splitted |> Seq.truncate 6 |> Seq.toArray with
//SourceFile(origin(url), (owner,project, commit), path)
| [| protocol; x; y; domain |] -> HttpLink(``project spec``), (domain, domain, None), fileName
| [| protocol; x; y; domain; project |] -> HttpLink(``project spec``), (domain,project, None), fileName
| [| protocol; x; y; owner; project; details |] -> HttpLink(``project spec``), (owner,project+"/"+details, None), fileName
| _ -> failwithf "invalid http-reference specification:%s %s" Environment.NewLine trimmed
match parts with
| [| _; projectSpec; |] -> getParts projectSpec String.Empty
| [| _; projectSpec; fileSpec |] -> getParts projectSpec fileSpec
| _ -> failwithf "invalid http-reference specification:%s %s" Environment.NewLine trimmed

let private (|Remote|Package|Blank|ReferencesMode|OmitContent|SourceFile|) (line:string) =
match line.Trim() with
| _ when String.IsNullOrWhiteSpace line -> Blank
Expand All @@ -112,17 +147,12 @@ module DependenciesFileParser =
| _ -> failwithf "could not retrieve nuget package from %s" trimmed
| trimmed when trimmed.StartsWith "references" -> ReferencesMode(trimmed.Replace("references","").Trim() = "strict")
| trimmed when trimmed.StartsWith "content" -> OmitContent(trimmed.Replace("content","").Trim() = "none")
| trimmed when trimmed.StartsWith "gist" ->
SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GistLink "gist")
| trimmed when trimmed.StartsWith "github" ->
let parts = parseDependencyLine trimmed
let getParts (projectSpec:string) =
match projectSpec.Split [|':'; '/'|] with
| [| owner; project |] -> owner, project, None
| [| owner; project; commit |] -> owner, project, Some commit
| _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed
match parts with
| [| _; projectSpec; fileSpec |] -> SourceFile(getParts projectSpec, fileSpec)
| [| _; projectSpec; |] -> SourceFile(getParts projectSpec, GitHub.FullProjectSourceFileName)
| _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed
SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GitHubLink "github")
| trimmed when trimmed.StartsWith "http" ->
SourceFile(``parse http source`` trimmed)
| _ -> Blank

let parseDependenciesFile fileName (lines:string seq) =
Expand All @@ -142,8 +172,8 @@ module DependenciesFileParser =
ResolverStrategy = parseResolverStrategy version
Parent = DependenciesFile fileName
VersionRequirement = parseVersionRequirement(version.Trim '!') } :: packages, sourceFiles
| SourceFile((owner,project, commit), path) ->
lineNo, options, sources, packages, { Owner = owner; Project = project; Commit = commit; Name = path } :: sourceFiles
| SourceFile(origin, (owner,project, commit), path) ->
lineNo, options, sources, packages, { Owner = owner; Project = project; Commit = commit; Name = path; Origin = origin} :: sourceFiles

with
| exn -> failwithf "Error in paket.dependencies line %d%s %s" lineNo Environment.NewLine exn.Message)
Expand Down Expand Up @@ -199,12 +229,12 @@ type DependenciesFile(fileName,options,packages : PackageRequirement list, remot
member __.FileName = fileName
member __.Sources = sources
member this.Resolve(force) =
let getSha1 owner repo branch = GitHub.getSHA1OfBranch owner repo branch |> Async.RunSynchronously
let getSha1 origin owner repo branch = RemoteDownload.getSHA1OfBranch origin owner repo branch |> Async.RunSynchronously
this.Resolve(getSha1,Nuget.GetVersions,Nuget.GetPackageDetails force)

member __.Resolve(getSha1,getVersionF, getPackageDetailsF) =
let resolveSourceFile(file:ResolvedSourceFile) : PackageRequirement list =
GitHub.downloadDependenciesFile(Path.GetDirectoryName fileName, file)
RemoteDownload.downloadDependenciesFile(Path.GetDirectoryName fileName, file)
|> Async.RunSynchronously
|> DependenciesFile.FromCode
|> fun df -> df.Packages
Expand Down
101 changes: 0 additions & 101 deletions src/Paket.Core/GitHub.fs

This file was deleted.

14 changes: 8 additions & 6 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let CreateInstallModel(root, sources, force, package) =
let createModel(root, sources,force, lockFile:LockFile) =
let sourceFileDownloads =
lockFile.SourceFiles
|> Seq.map (fun file -> GitHub.DownloadSourceFile(root, file))
|> Seq.map (fun file -> RemoteDownload.DownloadSourceFile(root, file))
|> Async.Parallel

let packageDownloads =
Expand Down Expand Up @@ -116,14 +116,16 @@ let Install(sources,force, hard, lockFile:LockFile) =

removeCopiedFiles project

let getGitHubFilePath name =
let getSingleRemoteFilePath name =
printf "\nFilename %s " name
lockFile.SourceFiles |> List.iter (fun i -> printf "\n %s %s " i.Name i.FilePath)
(lockFile.SourceFiles |> List.find (fun f -> Path.GetFileName(f.Name) = name)).FilePath

let gitHubFileItems =
referenceFile.GitHubFiles
let gitRemoteItems =
referenceFile.RemoteFiles
|> List.map (fun file ->
{ BuildAction = project.DetermineBuildAction file.Name
Include = createRelativePath project.FileName (getGitHubFilePath file.Name)
Include = createRelativePath project.FileName (getSingleRemoteFilePath file.Name)
Link = Some(if file.Link = "." then Path.GetFileName(file.Name)
else Path.Combine(file.Link, Path.GetFileName(file.Name))) })

Expand All @@ -135,6 +137,6 @@ let Install(sources,force, hard, lockFile:LockFile) =
Include = createRelativePath project.FileName file.FullName
Link = None })

project.UpdateFileItems(gitHubFileItems @ nuGetFileItems, hard)
project.UpdateFileItems(gitRemoteItems @ nuGetFileItems, hard)

project.Save()
Loading