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 #324 from simphony/add-the-generator
Browse files Browse the repository at this point in the history
Problem: python class generator is missing from the repository
  • Loading branch information
stefanoborini committed Oct 19, 2016
2 parents 70bb9f0 + 63ab9bc commit 8171cce
Show file tree
Hide file tree
Showing 9 changed files with 1,829 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ target/

# PyCharm IDE stuff
.idea
simphony/version.py
74 changes: 74 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,77 @@ separate repository https://github.com/simphony/simphony-framework.


.. _setuptools extras: https://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies


For Developers
==============

The data structures used in this project are based on the metadata which is defined in a separate repository called ``simphony-metadata`` located at: https://github.com/simphony/simphony-metadata.

In order to reflect latest changes to the metadata repository, one should regenerate these entities. There is a generator script available in `scripts` folder. The structure of this directory is defined below.

Directories
-----------

- scripts/ : Contain the code generator for metadata class, CUBA Enum and KEYWORDS
- tests/ : Unit test cases for the generated code
- generate.py : Code generator


Guide to generating metadata classes
------------------------------------

- Make sure the generator CLI script is installed::

$ python setup.py develop
$ simphony-meta-generate
Usage: simphony-meta-generate [OPTIONS] COMMAND [ARGS]...
Auto-generate code from simphony-metadata yaml description.
Options:
--help Show this message and exit.
Commands:
cuba_enum Create the CUBA Enum CUBA_INPUT - Path to the...
keywords Create a dictionary of CUDS keywords.
meta_class Create the Simphony Metadata classes...

- Generate Metadata classes:

You need to supply the yaml file that define the metadata schema, and the
path to the directory where the generated classes should be placed::

simphony-meta-generate meta_class yaml_files/simphony_metadata.yml $PATH_TO_DIRECTORY

- Generate CUBA module::

simphony-meta-generate cuba_enum yaml_files/cuba.yml yaml_files/simphony_metadata.yml $PATH_TO_CUBA_PY

- Generate CUBA keywords module::

simphony-meta-generate keywords yaml_files/cuba.yml $PATH_TO_KEYWORD_PY

- Make generated class comply with PEP 8

The generated code do not automatically comply with PEP 8. Auto formatters are available on PyPI.
Examples are `yapf <https://pypi.python.org/pypi/yapf>`_ and `authpep8 <https://pypi.python.org/pypi/autopep8>`_

- Here is a wrap up of the above steps, assuming the metadata files reside in ``yaml_files`` directory and that we are in the root of ``simphony-common`` repository::

# Generate CUDS classes
simphony-meta-generate meta_class yaml_files/simphony_metadata.yml simphony/cuds/meta -O
# Generate the CUBA enum
simphony-meta-generate cuba_enum yaml_files/cuba.yml yaml_files/simphony_metadata.yml simphony/core/cuba.py
# Generate the KEYWORDS enum
simphony-meta-generate keywords yaml_files/cuba.yml yaml_files/simphony_metadata.yml simphony/core/keywords.py

# Make sure `yapf` is installed for styling
pip install yapf
# Apply pep8 style
yapf --style pep8 --in-place simphony/core/{keywords.py,cuba.py}
yapf --style pep8 --in-place --recursive simphony/cuds/meta
Empty file added scripts/__init__.py
Empty file.

0 comments on commit 8171cce

Please sign in to comment.