modulePackageInfo :: DynFlags
                  -> [Flag] -- ^ Haddock flags are checked as they may
                            -- contain the package name or version
                            -- provided by the user which we
                            -- prioritise
                  -> Module -> Maybe (PackageName, Data.Version.Version)
modulePackageInfo dflags flags modu =
    cmdline <|> pkgDb
  where
    cmdline = (,) <$> optPackageName flags <*> optPackageVersion flags
    pkgDb = (\pkg -> (packageName pkg, packageVersion pkg)) <$> lookupPackage dflags (moduleUnitId modu)


-------------------------------------------------------------------------------
-- * Reading and dumping interface files
-------------------------------------------------------------------------------
modulePackageInfo :: DynFlags
                  -> [Flag] -- ^ Haddock flags are checked as they may
                            -- contain the package name or version
                            -- provided by the user which we
                            -- prioritise
                  -> Module -> Maybe (PackageName, Data.Version.Version)
modulePackageInfo dflags flags modu =
    cmdline <|> pkgDb
  where
    cmdline = (,) <$> optPackageName flags <*> optPackageVersion flags
    pkgDb = (\pkg -> (packageName pkg, packageVersion pkg)) <$> lookupPackage dflags (moduleUnitId modu)


-------------------------------------------------------------------------------
-- * Reading and dumping interface files
-------------------------------------------------------------------------------
modulePackageInfo dflags flags modu =
    cmdline <|> pkgDb
  where
    cmdline = (,) <$> optPackageName flags <*> optPackageVersion flags
    pkgDb = (\pkg -> (packageName pkg, packageVersion pkg)) <$> lookupPackage dflags (moduleUnitId modu)


-------------------------------------------------------------------------------
-- * Reading and dumping interface files
-------------------------------------------------------------------------------