Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #350 from simphony/specify-metadata-checkout
Browse files Browse the repository at this point in the history
Specify metadata repo tag to checkout
  • Loading branch information
mehdisadeghi committed Nov 10, 2016
2 parents 7751937 + e91dd44 commit 99b125a
Show file tree
Hide file tree
Showing 90 changed files with 389 additions and 357 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[flake8]
# Exclude docs
exclude = doc/*

[build_meta]
repotag=8cf2931faa40c3ac2c202e84dd0668532deadf2e
83 changes: 59 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import contextlib
import textwrap
from subprocess import check_call
from subprocess import check_call, CalledProcessError

from setuptools import setup, find_packages
from distutils.cmd import Command
Expand All @@ -13,67 +14,101 @@
VERSION = '0.3.1.dev0'


@contextlib.contextmanager
def cd(path):
"""Change directory and returns back to cwd once the operation is done."""
prev_cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(prev_cwd)


class BuildMeta(Command):
user_options = []
user_options = [('repopath=', None,
"Directory where to look for the local "
"simphony-metadata repository clone"),
('repourl=', None, "URL to the github repo for cloning"),
('repotag=', None, "Tag to checkout before building")]

def initialize_options(self):
self.simphony_metadata_path = None
self.repopath = None
self.repourl = "https://github.com/simphony/simphony-metadata/"
self.repotag = None

def finalize_options(self):
if self.simphony_metadata_path is None:
self.simphony_metadata_path = os.path.join(
os.getcwd(),
"simphony-metadata/")
try:
if not os.path.exists(self.simphony_metadata_path):
check_call([
"git",
"clone",
"https://github.com/simphony/simphony-metadata/"])
except OSError:
print (textwrap.dedent("""
Failed to run git. Make sure it is installed in your
environment"""))
if self.repopath is None:
self.repopath = os.path.join(os.getcwd(), "simphony-metadata/")

def run(self):
try:
if not os.path.exists(self.repopath):
print("Checking out {}".format(self.repopath))
check_call(["git", "clone", self.repourl])
except OSError:
print("Failed to run git clone. "
"Make sure it is installed in your environment")
raise
except CalledProcessError:
print("Failed to run git clone.")
raise

if self.repotag is not None:
with cd(self.repopath):
try:
print("Stashing possible changes.")
check_call(["git", "stash"])
except CalledProcessError:
print("Failed to run git stash.")
raise

try:
print("Checking out {}".format(self.repotag))
check_call(["git", "checkout", self.repotag])
except CalledProcessError:
print("Failed to checkout {}".format(self.repotag))
raise

metadata_yml = os.path.join(
self.simphony_metadata_path,
self.repopath,
"yaml_files",
"simphony_metadata.yml")
cuba_yml = os.path.join(
self.simphony_metadata_path,
self.repopath,
"yaml_files",
"cuba.yml")

if not (os.path.exists(cuba_yml) and os.path.exists(metadata_yml)):
print (textwrap.dedent("""
Cannot open simphony-metadata YAML files.
Please specify an appropriate path to the simphony-metadata
git repository in setup.cfg:
[build]
simphony_metadata_path=path/to/simphony-metadata-repo/
git repository in setup.cfg.
"""))
raise
raise RuntimeError("Unrecoverable error.")

print("Building classes")
with open(metadata_yml, 'rb') as simphony_metadata:
from scripts.generate import meta_class
meta_class.callback(simphony_metadata, "simphony/cuds/meta/", True)

print("Building keywords")
with open(metadata_yml, 'rb') as simphony_metadata, \
open(cuba_yml, 'rb') as cuba, \
open("simphony/core/keywords.py", "wb") as keywords_out:

from scripts.generate import keywords
keywords.callback(cuba, simphony_metadata, keywords_out)

print("Building enums")
with open(metadata_yml, 'rb') as simphony_metadata, \
open(cuba_yml, 'rb') as cuba, \
open("simphony/core/cuba.py", "wb") as cuba_out:

from scripts.generate import cuba_enum
cuba_enum.callback(cuba, simphony_metadata, cuba_out)

print("Running yapf")
cmd_args = ["yapf", "--style", "pep8", "--in-place"]
try:
check_call(cmd_args + ["simphony/core/keywords.py"])
Expand Down

0 comments on commit 99b125a

Please sign in to comment.