Compare commits

..

No commits in common. "master" and "v0.2.1" have entirely different histories.

16 changed files with 160 additions and 238 deletions

View File

@ -1,20 +0,0 @@
name: Main
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.stack
key: stack-${{ hashFiles('stack.yaml.lock') }}
- name: Install GHC
run: stack setup
- name: Build dependencies
run: stack build --only-dependencies
- name: Build package
run: stack build

6
.gitignore vendored
View File

@ -1,4 +1,4 @@
Gemfile.lock
_site/
.cabal-sandbox/
.stack-work/
cabal.sandbox.config
dist/

View File

@ -1,24 +1,3 @@
# 0.4.0 (2020-02-16)
## Enhancements
- Use hpack
# 0.3.0 (2019-02-05)
## Enhancements
- Use Stack (executable) to get licenses (ec8412b)
- Use `ls dependencies` instead of `list-dependencies` (4f4d41d)
## Bugs
- Fix incorrect license if package matches a Hackage package (#23)
# 0.2.2 (2018-01-16)
- Allow http-conduit 2.3 (558fe3d)
# 0.2.1 (2017-07-24)
- Allow base 4.10 and Cabal 2.0 (7bbb360)

1
CNAME
View File

@ -1 +0,0 @@
licensor.jpvillaisaza.co

View File

@ -1,3 +0,0 @@
source "https://rubygems.org/"
gem "github-pages"

View File

@ -1,5 +1,5 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
----------------------------------------------------------------------
-- |
@ -86,11 +86,11 @@ main = do
if stack
then do
putStrLn "Found stack.yaml..."
pure Nothing
return Nothing
else
Exit.die "Error: No Cabal file found."
Just PackageDescription { license, package } -> do
Just PackageDescription{..} -> do
putStrLn $
"Package: "
<> display package
@ -98,15 +98,17 @@ main = do
<> "License: "
<> display license
<> ")"
pure (Just package)
return (Just package)
maybeDependencies <- getDependencies
maybeLicenses <- getLicenses
case (maybeDependencies, maybeLicenses) of
(Just dependencies, Just licenses) -> do
case maybeDependencies of
Nothing ->
Exit.die "Error: ..."
Just dependencies -> do
(dependenciesByLicense', failed) <-
orderPackagesByLicense quiet pid licenses dependencies
orderPackagesByLicense quiet pid dependencies
let dependenciesByLicense = fmap (Set.map display) dependenciesByLicense'
@ -127,5 +129,3 @@ main = do
unless (null failed) $ do
putStr "Failed: "
print failed
_ ->
Exit.die "Error: ..."

View File

@ -1,5 +1,10 @@
# The not so great automatic Haskell licensor
[![][1]][0]
[0]: https://circleci.com/gh/jpvillaisaza/licensor
[1]: https://circleci.com/gh/jpvillaisaza/licensor.svg?style=svg
[![][2]](https://www.stackage.org/lts/package/licensor)
[![][3]](https://www.stackage.org/nightly/package/licensor)
@ -79,7 +84,7 @@ $ cd licensor/ && stack build --exec licensor
For more information, run `licensor --help`:
```
licensor 0.4.0
licensor 0.2.0
licensor [OPTIONS]
@ -87,8 +92,6 @@ Common flags:
-? --help Display help message
-V --version Print version information
--numeric-version Print just the version number
-v --verbose Loud verbosity
-q --quiet Quiet verbosity
```
## Notes
@ -140,24 +143,27 @@ See [LICENSE.md](LICENSE.md).
### License report
Licensor (0.4.0) depends on the following libraries:
Licensor (0.2.0) depends on the following libraries:
Library | License
------------------------- | -------------------------
base | BSD3
bytestring | BSD3
Cabal | BSD3
cmdargs | BSD3
containers | BSD3
directory | BSD3
http-conduit | BSD3
process | BSD3
And the following licenses (including transitive dependencies):
License | Number of libraries
------------------------- | -------------------------
BSD3 | 20
BSD3 | 68
MIT | 7
(Tested with Licensor 0.4.0, Stack 2.1.3, and LTS Haskell 11.11.)
(Tested with Licensor 0.2.0, Stack 1.2.0, and LTS 7.0.)
## Additional resources

11
Setup.hs Normal file
View File

@ -0,0 +1,11 @@
module Main
( main
)
where
import Distribution.Simple (defaultMain)
main :: IO ()
main =
defaultMain

View File

@ -1,18 +0,0 @@
exclude:
- app/
- CHANGELOG.md
- Gemfile
- Gemfile.lock
- LICENSE.md
- licensor.cabal
- package.yaml
- src/
- package.yaml
- stack.yaml
- stack.yaml.lock
plugins:
- jekyll-readme-index
readme_index:
remove_originals: true

17
circle.yml Normal file
View File

@ -0,0 +1,17 @@
dependencies:
cache_directories:
- ~/.stack/
- .stack-work/
override:
- stack setup
- stack build --only-dependencies
pre:
- curl -sSL https://get.haskellstack.org/ | sh
test:
override:
- stack build

0
docs/index.html Normal file
View File

View File

@ -1,61 +1,68 @@
cabal-version: 1.12
name: licensor
version: 0.2.1
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: b5e0234d196e96476a6a70c11798ae1dd4fd24ca9ce1c11ea74d6b3422604fc8
build-type: Simple
cabal-version: >= 1.21
name: licensor
version: 0.4.0
synopsis: A license compatibility helper
description: A license compatibility helper.
category: Distribution
stability: Experimental
homepage: https://jpvillaisaza.co/licensor
bug-reports: https://github.com/jpvillaisaza/licensor/issues
author: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
maintainer: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
copyright: 2016 Juan Pedro Villa Isaza
license: MIT
license-file: LICENSE.md
build-type: Simple
extra-source-files:
CHANGELOG.md
README.md
license: MIT
license-file: LICENSE.md
copyright: 2016 Juan Pedro Villa Isaza
author: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
maintainer: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
stability: Experimental
homepage: https://github.com/jpvillaisaza/licensor
bug-reports: https://github.com/jpvillaisaza/licensor/issues
synopsis: A license compatibility helper
description: A license compatibility helper.
category: Distribution
tested-with: GHC == 7.10.3, GHC == 8.0.1, GHC == 8.0.2, GHC == 8.2.1
extra-source-files: CHANGELOG.md, README.md
source-repository head
type: git
location: https://github.com/jpvillaisaza/licensor
library
hs-source-dirs:
src
exposed-modules:
Licensor
other-modules:
Paths_licensor
hs-source-dirs:
src
ghc-options: -Wall
build-depends:
Cabal >=1.22 && <2.1
, base >=4.8 && <4.11
base >= 4.8 && < 4.11
, bytestring
, Cabal >= 1.22 && < 2.1
, containers
, directory
, http-conduit >= 2.1 && < 2.3
, process
default-language: Haskell2010
default-language:
Haskell2010
ghc-options:
-Wall
executable licensor
main-is: Main.hs
other-modules:
Paths_licensor
hs-source-dirs:
app
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
main-is:
Main.hs
build-depends:
Cabal >=1.22 && <2.1
, base >=4.8 && <4.11
, cmdargs >=0.10 && <0.11
base
, Cabal
, cmdargs >= 0.10 && < 0.11
, containers
, directory
, licensor
default-language: Haskell2010
default-language:
Haskell2010
ghc-options:
-Wall -threaded -rtsopts -with-rtsopts=-N
source-repository head
type: git
location: https://github.com/jpvillaisaza/licensor

View File

@ -1,49 +0,0 @@
name: licensor
version: 0.4.0
synopsis: A license compatibility helper
description: A license compatibility helper.
category: Distribution
stability: Experimental
github: jpvillaisaza/licensor
homepage: https://jpvillaisaza.co/licensor
author: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
maintainer: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
copyright: 2016 Juan Pedro Villa Isaza
license-file: LICENSE.md
extra-source-files:
- CHANGELOG.md
- README.md
dependencies:
- Cabal >= 1.22 && < 2.1
- base >= 4.8 && < 4.11
- containers
- directory
ghc-options:
- -Wall
library:
source-dirs:
src
dependencies:
- process
executable:
source-dirs:
app
main:
Main.hs
dependencies:
- cmdargs >= 0.10 && < 0.11
- licensor
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N

View File

@ -1,4 +1,6 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
----------------------------------------------------------------------
@ -14,7 +16,6 @@ module Licensor
( LiLicense(..)
, LiPackage(..)
, getDependencies
, getLicenses
, getPackage
, orderPackagesByLicense
, version
@ -24,16 +25,21 @@ module Licensor
-- base
import qualified Control.Exception as Exception
import Control.Monad (unless)
import Data.Monoid ((<>))
import Data.Version (Version)
import System.IO
-- bytestring
import qualified Data.ByteString.Lazy as ByteString
-- Cabal
import Distribution.License (License)
import Distribution.Package (PackageIdentifier(..), PackageName)
import Distribution.PackageDescription (PackageDescription, packageDescription)
import Distribution.PackageDescription.Parse (readGenericPackageDescription)
import Distribution.Simple.Utils (comparing, findPackageDesc)
import Distribution.Text (Text, display, simpleParse)
import Distribution.Verbosity (silent)
import Distribution.License
import Distribution.Package
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
import Distribution.Simple.Utils
import Distribution.Text
import Distribution.Verbosity
-- containers
import Data.Map.Strict (Map)
@ -42,13 +48,17 @@ import Data.Set (Set)
import qualified Data.Set as Set
-- directory
import System.Directory (getCurrentDirectory)
import System.Directory
-- http-conduit
--import Network.HTTP.Client.Conduit
import Network.HTTP.Simple
-- licensor
import qualified Paths_licensor
-- process
import System.Process (readProcess)
import System.Process
-- |
@ -88,7 +98,7 @@ getPackage :: IO (Maybe PackageDescription)
getPackage = do
currentDirectory <- getCurrentDirectory
fmap getPackageDescription <$> findPackageDesc currentDirectory
>>= either (const (pure Nothing)) (fmap Just)
>>= either (const (return Nothing)) (fmap Just)
-- |
@ -97,7 +107,7 @@ getPackage = do
getPackageDescription :: FilePath -> IO PackageDescription
getPackageDescription =
fmap packageDescription . readGenericPackageDescription silent
fmap packageDescription . readPackageDescription silent
-- |
@ -107,54 +117,50 @@ getPackageDescription =
getDependencies :: IO (Maybe (Set PackageIdentifier))
getDependencies = do
eitherDeps <-
Exception.try $ readProcess "stack" ["ls", "dependencies", "--separator", "-"] ""
Exception.try $ readProcess "stack" ["list-dependencies", "--separator", "-"] ""
case eitherDeps of
Left (_ :: IOError) ->
pure Nothing
return Nothing
Right deps ->
pure $ Set.fromList <$> traverse simpleParse (lines deps)
getLicenses :: IO (Maybe [(PackageName, License)])
getLicenses = do
eitherDeps <-
Exception.try $ readProcess "stack" ["ls", "dependencies", "--license"] ""
case eitherDeps of
Left (_ :: IOError) ->
pure Nothing
Right deps ->
pure $ traverse toNameLicense (lines deps)
where
toNameLicense dep =
case words dep of
[name, license] ->
(,) <$> simpleParse name <*> simpleParse license
_ ->
Nothing
return $ fmap Set.fromList $ sequence $ fmap simpleParse (lines deps)
-- |
--
--
getPackageLicense
:: Bool
-> PackageIdentifier
-> [(PackageName, License)]
-> IO (Maybe LiLicense)
getPackageLicense quiet packageIdentifier licenses = do
unless quiet (putStr $ display packageIdentifier ++ "...")
case lookup (pkgName packageIdentifier) licenses of
Just license -> do
getPackageLicense :: Bool -> PackageIdentifier -> IO (Maybe LiLicense)
getPackageLicense quiet p@PackageIdentifier{..} = do
unless quiet (putStr $ display p ++ "...")
let
url =
"GET https://hackage.haskell.org/package/"
<> display p
<> "/"
<> unPackageName pkgName
<> ".cabal"
req <- parseRequest url
eitherPd <- Exception.try $ fmap getResponseBody (httpLBS req)
case eitherPd of
Left (_ :: HttpException) ->
return Nothing
Right pd -> do
(file, handle) <- openTempFile "/tmp" "licensor"
hClose handle
ByteString.writeFile file pd
PackageDescription{license} <- getPackageDescription file
hClose handle
removeFile file
unless quiet (putStrLn $ display license)
pure $ Just (LiLicense license)
Nothing ->
pure Nothing
return $ Just (LiLicense license)
-- |
@ -164,19 +170,18 @@ getPackageLicense quiet packageIdentifier licenses = do
orderPackagesByLicense
:: Bool
-> Maybe PackageIdentifier
-> [(PackageName, License)]
-> Set PackageIdentifier
-> IO (Map LiLicense (Set PackageIdentifier), Set PackageIdentifier)
orderPackagesByLicense quiet maybeP licenses =
orderPackagesByLicense quiet maybeP =
let
cond =
maybe (const False) (==) maybeP
insertPackage package orderedPackages' = do
maybeLicense <- getPackageLicense quiet package licenses
maybeLicense <- getPackageLicense quiet package
(orderedPackages, failed) <- orderedPackages'
pure $
return $
if cond package
then
(orderedPackages, failed)

View File

@ -1 +1 @@
resolver: lts-11.11
resolver: lts-7.0

View File

@ -1,12 +0,0 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
size: 507599
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/11.yaml
sha256: 5ec0a1ff4dadde524eb529784556bcc32014422fd1e1ed91231c59f001e92ca9
original: lts-11.11