Skip to content
Snippets Groups Projects
Commit e60bd0fb authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Finished generation of meta.yaml files. Next step is to automate conda build.

parent 32415143
No related branches found
No related tags found
No related merge requests found
import setuptools, importlib, subprocess, os, re
from Setupdata import Setupdata
def generate_metafile(setup_dict):
# Go through each entry in setup_data and pick out what info is needed
# Write to a file (support/conda/{name}/meta.yaml with all given data
for field, value in setup_dict.items():
def write_metafile(metadata, filename):
try:
os.makedirs(filename[:-10])
except FileExistsError:
pass
# package:
# name:
# version:
# build:
# entry points:
# - 1
# script: {{ PYTHON }} setup.py install
# source:
# path:
# requirements:
# build = run:
# test:
# source files:
# requires:
# commands
# about:
# license = license family:
# summary:
pass
with open(filename, 'w') as f:
f.write(metadata)
def generate_metafile(setup_dict, path):
metadata = (
'{{% set name = "{name}" %}}\n'
'{{% set version = "{version}" %}}\n'
'\n'
'package:\n'
' name: "{{{{ name|lower }}}}"\n'
' version: "{{{{ version }}}}"\n'
'\n'
'build:\n'
).format(
name=setup_dict["name"],
version=setup_dict["version"]
)
if 'entry_points' in setup_dict.keys():
metadata += ' entry_points:\n'
for ep in setup_dict['entry_points']:
metadata += ' - {}\n'.format(ep)
metadata += (' script: {{{{PYTHON}}}} setup.py install\n'
'\n'
'source:\n'
' path: {}\n'.format(path))
metadata += '\n'
if 'install_requires' in setup_dict.keys():
metadata += 'requirements:\n'
build_reqs = ' build:\n'
run_reqs = ' run:\n'
for req in setup_dict['install_requires'].split(', '):
build_reqs += ' - {}\n'.format(req)
run_reqs += ' - {}\n'.format(req)
metadata += build_reqs
metadata += run_reqs
if 'tests_require' in setup_dict.keys():
metadata += ('test:\n'
' source_files:\n'
' - test/\n'
' requires:\n')
for req in setup_dict['tests_require'].split(', '):
metadata += ' - {}\n'.format(req)
metadata += (' commands:\n'
' - pytest -vv --log-level=DEBUG --showlocals\n')
metadata += ('\n'
'about:\n'
' license: "{0}"\n'
' license_family: "{0}"\n'
' summary: "{1}"'.format(setup_dict['license'], setup_dict['description']))
return metadata
def data_to_dict(setup_data):
data_dict = {}
r_entry = r"([a-z-_]+): "
r_id = r"[a-zA-Z0-9-_]"
r_ep = r"{{(?:{0}+):\s*(?P<values>(?:{0}+\s*=\s*[a-zA-Z0-9-_.]+:{0}+(?:,\s*)?)*)}}".format(r_id)
r_ep = r"{{(?:[a-zA-Z0-9-_.]+):\s*(?P<values>(?:{0}+\s*=\s*[a-zA-Z0-9-_.]+:{0}+(?:,\s*)?)*)}}".format(r_id)
for d in setup_data:
result = re.match(r_entry, d)
......@@ -45,10 +85,17 @@ def data_to_dict(setup_data):
value = re.match(r_ep, value).group('values')
value = re.split(',\s*', value)
data_dict[field] = value
print("{}: {}".format(field, value))
# print("{}: {}".format(field, value))
return data_dict
def get_outputs(names):
outputs = []
for name in names:
outputs.append("support/conda/{}/meta.yaml".format(name))
return outputs
def get_dirs():
find = subprocess.run(['find', '.', '-name', 'setup.py'], stdout=subprocess.PIPE)
dirs = find.stdout.decode('utf-8').split('\n')
......@@ -65,7 +112,12 @@ def get_names(dirs):
names = []
for d in dirs:
if d != '':
names.append(d.split('/')[-1])
name = d.split('/')[-1]
if name == "archive":
# Case with ./services/archive having special dir structure
name = "services"
names.append(name)
return names
......@@ -79,23 +131,23 @@ class Recipe:
def __init__(self, buildout, name, options):
self.dirs = get_dirs()
self.names = get_names(self.dirs)
# print(self.dirs)
# TODO: Make list of outputs = support/conda/{name}/meta.yaml
options['created'] = ""
self.outputs = get_outputs(self.names)
self.options = options
# TODO: Keep track of path in setup_dict
def install(self):
self.options.created(self.options['created'])
root = os.getcwd()
for d in self.dirs:
for i, d in enumerate(self.dirs):
if d != '':
os.chdir(d)
proc = subprocess.run(['python3', 'parse_setup.py'], stdout=subprocess.PIPE)
os.chdir(root)
setup_data = (proc.stdout.decode('utf-8')).split('\n')
data_dict = data_to_dict(setup_data)
generate_metafile(data_dict)
metadata = generate_metafile(data_dict, d)
write_metafile(metadata, self.outputs[i])
self.options.created(self.outputs[i])
return self.options.created()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment