GMSPythonCheck.gms : Consistency check for GMSPython

Description

This model performs simple checks on the GMSPython
distribution shipped with GAMS regarding the number of
distributed files as well as the total disk size.

Contributor: Clemens Westphal, April 2020


Category : GAMS Data Utilities library


Main file : GMSPythonCheck.gms   includes :  GMSPythonCheck.gms

$title 'Consistency check for GMSPython' (GMSPYTHONCHECK,SEQ=140)

$ontext
This model performs simple checks on the GMSPython
distribution shipped with GAMS regarding the number of
distributed files as well as the total disk size.

Contributor: Clemens Westphal, April 2020
$offtext

$ifi %system.buildcode% == AIX $exit No GMSPython on this platform
$ifi %system.buildcode% == SOX $exit No GMSPython on this platform
$ifi %system.buildcode% == VS8 $exit No GMSPython on this platform

$onEmbeddedCode Python:
import sys
import os
def calcSize(path):
    total = 0
    for r, d, files in os.walk(path):
        if '__pycache__' in d:
            d.remove('__pycache__')
        for f in files:
            f = os.path.join(r, f)
            if not os.path.islink(f): # skip symlinks since os.path.getsize() returns the size of the file behind the link
                total += os.path.getsize(f)
    return total
$offEmbeddedCode

$onEmbeddedCode Python:
platform = sys.platform
gmsPyDir = r'%gams.sysdir%GMSPython'
if os.path.isdir(gmsPyDir):
    if platform == 'win32':
        expectedFiles = 646
        expectedSize = 22000000
    elif platform == 'linux':
        expectedFiles = 722
        expectedSize = 50000000
    elif platform == 'darwin':
        expectedFiles = 732
        expectedSize = 32000000
    
    SizeLB = expectedSize*0.8
    SizeUB = expectedSize*1.2
    
    files = []
    for r, d, f in os.walk(gmsPyDir):
        if '__pycache__' in d:
            d.remove('__pycache__')
        files.append(f)
    files = [f for l in files for f in l]
    
    numberFiles = len(files)
    size = calcSize(gmsPyDir)
    
    if numberFiles != expectedFiles:
        raise Exception("Expected number of files to be ", expectedFiles, " but found ", numberFiles)
    if size < SizeLB or size > SizeUB:
        raise Exception("Expected size of GMSPython to be between ", SizeLB, " and ", SizeUB, " but got ", size)

thirdPartyDir = os.path.join(r'%gams.sysdir%apifiles', 'Python', 'thirdparty')
if os.path.isdir(thirdPartyDir):
    if platform == 'win32':
        expectedFiles = 1435
        expectedSize = 62000000
    elif platform == 'linux':
        expectedFiles = 1436
        expectedSize = 72000000
    elif platform == 'darwin':
        expectedFiles = 1436
        expectedSize = 109000000
    
    SizeLB = expectedSize*0.8
    SizeUB = expectedSize*1.2
    
    files = []
    for r, d, f in os.walk(thirdPartyDir):
        if '__pycache__' in d:
            d.remove('__pycache__')
        files.append(f)
    files = [f for l in files for f in l]
    
    numberFiles = len(files)
    size = calcSize(thirdPartyDir)
    
    if numberFiles != expectedFiles:
        raise Exception("Expected number of files in 'thirdparty' directory to be ", expectedFiles, " but found ", numberFiles)
    if size < SizeLB or size > SizeUB:
        raise Exception("Expected size of 'thirdparty' directory to be between ", SizeLB, " and ", SizeUB, " but got ", size)
$offEmbeddedCode