Created
September 28, 2020 22:32
-
-
Save ri5h/27318cd5ecc7c38919a508fd3e00a72f to your computer and use it in GitHub Desktop.
Read composer.json and composer.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Which directory have composer.json and composer.lock | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--path', help='Relative directory that contains the composer files') | |
cdir = parser.parse_args().path | |
# Reads composer.json for constraints | |
reqPack = {} | |
with open(cdir +'/composer.json') as json_file: | |
data = json.loads(json.dumps(json.load(json_file))) | |
for package in data['require']: | |
packageStr = str(package) | |
if package == 'php': | |
continue | |
if package.startswith('ext-'): | |
continue | |
reqPack[packageStr] = str(data['require'][package]) | |
# Reads composer.lock for installed versions | |
inPack = {} | |
with open(cdir + '/composer.lock') as json_file: | |
lockdata = json.loads(json.dumps(json.load(json_file))) | |
for package in lockdata['packages']: | |
for key in package: | |
if str(key) == 'name' and str(package[key]) in reqPack: | |
inPack[str(package['name'])] = str(package['version']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment