diff --git a/PITCHME.md b/PITCHME.md index 023e193..25b1779 100644 --- a/PITCHME.md +++ b/PITCHME.md @@ -5,10 +5,6 @@ PSGraph is a PowerShell module that allows you to script the generation of graph ![basic graph](https://kevinmarquette.github.io/img/basic.png) --- -### Install GraphViz from the Chocolatey repo - - Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ - Find-Package graphviz | Install-Package -ForceBootstrap ### Install PSGraph from the Powershell Gallery @@ -18,6 +14,12 @@ PSGraph is a PowerShell module that allows you to script the generation of graph Import-Module PSGraph +### Install GraphViz + Install-GraphViz -Scope CurrentUser|AllUsers + # Note, a warning may be written if chocolatey is not installed. + # However, an older version of GraphViz will be used from nuget.org which should still work. + # If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz + --- ### Describe how items are connected @@ -115,4 +117,4 @@ For more information * [psgraph.readthedocs.io](http://psgraph.readthedocs.io) * [github.com/kevinmarquette/psgraph](https://github.com/kevinmarquette/psgraph) -* [kevinmarquette.github.io](https://kevinmarquette.github.io) \ No newline at end of file +* [kevinmarquette.github.io](https://kevinmarquette.github.io) diff --git a/PSGraph/PSGraph.psd1 b/PSGraph/PSGraph.psd1 index b0a734c..09515d0 100644 --- a/PSGraph/PSGraph.psd1 +++ b/PSGraph/PSGraph.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGraph.psm1' # Version number of this module. - ModuleVersion = '2.1.38' + ModuleVersion = '2.1.39' # Supported PSEditions # CompatiblePSEditions = @() @@ -108,6 +108,10 @@ # ReleaseNotes of this module ReleaseNotes = @' +2.1.39 20250318 +* add support for non-admin install on Windows. +* gracefully handle systems without Chocolatey by falling back to nuget.org's 2016 Graphviz package. + 2.1.16 20180217 * add Record command * add Row command diff --git a/PSGraph/Public/Export-PSGraph.ps1 b/PSGraph/Public/Export-PSGraph.ps1 index ec6f0c6..19fec5a 100644 --- a/PSGraph/Public/Export-PSGraph.ps1 +++ b/PSGraph/Public/Export-PSGraph.ps1 @@ -75,6 +75,7 @@ function Export-PSGraph [string[]] $GraphVizPath = ( 'C:\Program Files\NuGet\Packages\Graphviz*\dot.exe', + "$env:USERPROFILE\AppData\Local\PackageManagement\NuGet\Packages\Graphviz*\dot.exe", # The Install-GraphViz -Scope CurrentUser location. 'C:\program files*\GraphViz*\bin\dot.exe', '/usr/local/bin/dot', '/usr/bin/dot' @@ -96,7 +97,7 @@ function Export-PSGraph if ( $null -eq $graphViz ) { $GraphvizPathString = $GraphVizPath -Join " or " - throw "Could not find GraphViz installed on this system. Please run 'Install-GraphViz' to install the needed binaries and libraries. This module just a wrapper around GraphViz and is looking for it in the following paths: $($GraphvizPathString). Optionally pass a path to your dot.exe file with the GraphVizPath parameter" + throw "Could not find GraphViz installed on this system. Please run 'Install-GraphViz' to install the needed binaries and libraries. Use 'Install-GraphViz -Scope CurrentUser' to install for the current user only on Windows. This module just a wrapper around GraphViz and is looking for it in the following paths: $($GraphvizPathString). Optionally pass a path to your dot.exe file with the GraphVizPath parameter" } $useStandardInput = $false diff --git a/PSGraph/Public/Install-GraphViz.ps1 b/PSGraph/Public/Install-GraphViz.ps1 index ccf8e24..4e5ee8a 100644 --- a/PSGraph/Public/Install-GraphViz.ps1 +++ b/PSGraph/Public/Install-GraphViz.ps1 @@ -5,9 +5,16 @@ function Install-GraphViz Installs GraphViz package using online provider .Example Install-GraphViz + .PARAMETER Scope + Use -Scope CurrentUser to install as non-admin to appdata instead of program files. + Unused on *Nix systems. #> [cmdletbinding( SupportsShouldProcess = $true, ConfirmImpact = "High" )] - param() + param( + [ValidateSet('AllUsers', 'CurrentUser')] + [string] + $Scope = 'AllUsers' + ) process { @@ -24,12 +31,28 @@ function Install-GraphViz { if ( $PSCmdlet.ShouldProcess('Register Chocolatey provider and install graphviz' ) ) { - if ( -Not ( Get-PackageProvider | Where-Object ProviderName -eq 'Chocolatey' ) ) + if ( -Not ( Get-PackageSource | Where-Object ProviderName -eq 'Chocolatey' ) ) { - Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ + try { + Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ -ErrorAction 'Stop' + } catch { + # We can still install graphviz from nuget.org, though it is more outdated than the choco one. + # as of writing (March 2025) choco has 12.2.1* and nuget.org has 2.1.38.* from 2016 BUT it still works. + $nugetSource = Get-PackageSource | Where-Object { $_.Location -like 'https://api.nuget.org/v*' } + if (-not $nugetSource) { + Write-Warning 'No nuget.org feed found to fall back on. Cannot install graphviz.' + throw + } + + Write-Warning '------------------------------------------------------------' + Write-Warning $_ + Write-Warning 'Could not register a Chocolatey package provider. Will fall back to the older nuget.org Graphviz package instead.' + Write-Warning 'If you see this error, considering installing chocolatey and then re-running this command to use the latest Graphviz.' + Write-Warning '------------------------------------------------------------' + } } - Find-Package graphviz | Install-Package -Verbose -ForceBootstrap + Find-Package graphviz | Install-Package -Verbose -ForceBootstrap -Scope $Scope } } } diff --git a/docs/Quick-Start-Installation-and-Example.md b/docs/Quick-Start-Installation-and-Example.md index f66f81d..a683776 100644 --- a/docs/Quick-Start-Installation-and-Example.md +++ b/docs/Quick-Start-Installation-and-Example.md @@ -1,13 +1,14 @@ # Installing PSGraph -Make sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a hard requirement at the moment but I plan on using 5.0 features. - - # Install GraphViz from the Chocolatey repo - Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ - Find-Package graphviz | Install-Package -ForceBootstrap +Make sure you are running Powershell 5.0 (WMF 5.0) or Powershell 7+ (pwsh.exe). # Install PSGraph from the Powershell Gallery - Find-Module PSGraph | Install-Module + Find-Module PSGraph | Install-Module + # Install GraphViz + Install-GraphViz -Scope CurrentUser|AllUsers + # Note, a warning may be written if chocolatey is not installed. + # However, an older version of GraphViz will be used from nuget.org which should still work. + # If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz # Generating your first graph @@ -18,10 +19,10 @@ PSGraph has a unique syntax for defining a graph. This is because it was built s Import-Module PSGraph graph "myGraph" { - edge start,middle,end + edge start,middle,end } | Export-PSGraph -ShowGraph -This will create a new graph with three nodes linking each other. +This will create a new graph with three nodes linking each other. [![Source](images/firstGraph.png)](images/firstGraph.png) diff --git a/readme.md b/readme.md index b5e0b09..657bd8b 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ [![Build status](https://ci.appveyor.com/api/projects/status/cgo827o4f74lmf9w/branch/master?svg=true)](https://ci.appveyor.com/project/kevinmarquette/PSGraph/branch/master) [![Documentation Status](https://readthedocs.org/projects/psgraph/badge/?version=latest)](http://psgraph.readthedocs.io/en/latest/?badge=latest) - + # PSGraph @@ -19,7 +19,7 @@ PSGraph is a helper module implemented as a DSL (Domain Specific Language) for g Beta release. The core module work and documentation is fleshed out. The simple features are implemented but there are other features of the DOT language that I have not used much myself. The command names and arguments of the existing commands should be stable now. As always, more testing still needs to be done. # GraphViz and the Dot format basics -The nice thing about GraphViz is that you can define nodes and edges with a simple text file in the Dot format. The GraphViz engine handles the layout, edge routing, rendering and creates an image for you. +The nice thing about GraphViz is that you can define nodes and edges with a simple text file in the Dot format. The GraphViz engine handles the layout, edge routing, rendering and creates an image for you. Here is a sample Dot file. @@ -53,7 +53,7 @@ I tried to keep a syntax that was similar to GraphViz but offer the flexibility ## Graph or digraph This is the container that holds graph elements. Every valid GraphViz graph has one. `digraph` is just an alias of `graph` so I am going to use the shorter `graph` for the rest of the readme. - graph g { + graph g { } ## Edge @@ -70,12 +70,12 @@ If you supply two arrays, it will cross multiply them. So each item on the left graph g { edge (1,3) (2,4) } - + Because this is Powershell, we can mix in normal commands. Take this example. $folders = Get-ChildItem -Directory -Recurse graph g { - $folders | %{edge $_.Name $_.Parent} + $folders | %{edge $_.Name $_.Parent} } I also support edge attributes that are defined in the DOT specification by using a hashtable. @@ -99,8 +99,8 @@ This is the exact Dot output generated those node commands. "start" [shape="house"] "end" [shape="invhouse"] - "start"->"middle" - "middle"->"end" + "start"->"middle" + "middle"->"end" } ## Rank @@ -142,24 +142,20 @@ We can pull that all together and generate quite the data driven driven diagram. subgraph 1 -Attributes @{label='Internal'} { # Internal API servers rank $apiServers - node $apiServers + node $apiServers edge $webServers -to $apiServers - + # Database Servers rank $databaseServers node $databaseServers @{shape='octagon'} edge $apiServers -to $databaseServers - } + } } # Installing PSGraph -Make sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a hard requirement at the moment but I plan on using 5.0 features. - - # Install GraphViz from the Chocolatey repo - Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ - Find-Package graphviz | Install-Package -ForceBootstrap +Make sure you are running Powershell 5.0 (WMF 5.0) or Powershell 7+ (pwsh.exe). # Install PSGraph from the Powershell Gallery Find-Module PSGraph | Install-Module @@ -167,6 +163,12 @@ Make sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a ha # Import Module Import-Module PSGraph + # Install GraphViz + Install-GraphViz -Scope CurrentUser|AllUsers + # Note, a warning may be written if chocolatey is not installed. + # However, an older version of GraphViz will be used from nuget.org which should still work. + # If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz + For OSX, you can use brew to install graphviz. brew install graphviz @@ -181,11 +183,11 @@ I am still working out the workflow for this, but for now just do this. # Save to file Set-Content -Path $env:temp\hello.vz -Value $dot - + Export-PSGraph -Source $env:temp\hello.vz -Destination $env:temp\hello.png -ShowGraph The export can be done more in line if needed. graph g { edge hello world - } | Export-PSGraph -ShowGraph \ No newline at end of file + } | Export-PSGraph -ShowGraph