Skip to content

Commit

Permalink
Add ancestors of packages to packages in setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AiOO committed Mar 7, 2017
1 parent c724fea commit 421c37a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Nirum/Targets/Python.hs
Expand Up @@ -31,6 +31,7 @@ module Nirum.Targets.Python ( Code
, insertStandardImport
, insertThirdPartyImports
, runCodeGen
, spreadModulePaths
, stringLiteral
, toAttributeName
, toClassName
Expand Down Expand Up @@ -840,6 +841,13 @@ compileModule pythonVersion' source =
, ((3, 5), require "typing" "typing" $ standardImports context)
]

spreadModulePaths :: [ModulePath] -> [Code]
spreadModulePaths modulePaths = pathsToPackageNames $ map ancestors modulePaths
where
pathsToPackageNames :: [S.Set ModulePath] -> [Code]
pathsToPackageNames modulePaths' = S.toAscList $ S.map toImportPath $
S.unions modulePaths'

compilePackageMetadata :: Package' -> InstallRequires -> Code
compilePackageMetadata package@Package { metadata = metadata' }
(InstallRequires deps optDeps) =
Expand Down Expand Up @@ -919,7 +927,7 @@ setup(
| Author { email = Just e } <- authors metadata'
]
pPackages :: Code
pPackages = strings $ map toImportPath $ MS.keys $ modules package
pPackages = strings $ spreadModulePaths $ MS.keys $ modules package
pInstallRequires :: Code
pInstallRequires = strings $ S.toList deps
pPolyfillRequires :: Code
Expand Down
12 changes: 11 additions & 1 deletion test/Nirum/Targets/PythonSpec.hs
Expand Up @@ -36,11 +36,12 @@ import Nirum.Constructs.TypeExpression ( TypeExpression ( ListModifier
, TypeIdentifier
)
)
import Nirum.Package (Package, resolveBoundModule)
import Nirum.Package (Package(modules), resolveBoundModule)
import Nirum.Package.Metadata ( Author (Author, email, name, uri)
, Metadata (Metadata, authors, target, version)
, Target (compilePackage)
)
import qualified Nirum.Package.ModuleSet as MS
import Nirum.PackageSpec (createPackage)
import qualified Nirum.Targets.Python as PY
import Nirum.Targets.Python ( Source (Source)
Expand Down Expand Up @@ -349,6 +350,15 @@ spec = parallel $ forM_ versions $ \ (ver, typing) -> do
(3, 4) "ipaddress"
(req4 `unionInstallRequires` req5) `shouldBe` req6
(req5 `unionInstallRequires` req4) `shouldBe` req6
describe "Add ancestors of packages" $ do
let (Source pkg _) = makeDummySource $ Module [] Nothing
modulePaths = MS.keys $ modules pkg
specify "spreadModulePaths" $
PY.spreadModulePaths modulePaths `shouldBe` [ "foo"
, "foo.bar"
, "qux"
]


{-# ANN module ("HLint: ignore Functor law" :: String) #-}
{-# ANN module ("HLint: ignore Monad law, left identity" :: String) #-}
Expand Down

0 comments on commit 421c37a

Please sign in to comment.