Skip to content

Commit

Permalink
Merge pull request #154 from OkieOth/ignore_xref
Browse files Browse the repository at this point in the history
add 'ignoreXref' switch, add tests and bump version
  • Loading branch information
OkieOth committed Mar 1, 2024
2 parents 2d9c927 + 9c3aee0 commit 4d8a599
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 112 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/__tests.yml

This file was deleted.

32 changes: 30 additions & 2 deletions .github/workflows/yacg_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,33 @@ on:
branches: [ master ]

jobs:
call-workflow-test:
uses: OkieOth/yacg/.github/workflows/__tests.yml
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: '3.10'
- name: Install virtualenv
run: |
pip install virtualenv
pip install flake8
- name: Install dependencies
run: |
[[ -d venv ]] || virtualenv venv
source venv/bin/activate
- name: Install dependencies
run: |
[[ -d venv ]] || virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --exclude venv --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --exclude venv --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics --per-file-ignores='yacg/model/*.py:E501 E303 W391'
- name: Run and stuff from command line
run: |
bin/runGithubActions.sh
5 changes: 2 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"name": "Python: Aktuelle Datei",
Expand All @@ -21,10 +22,8 @@
"--model",
"resources/models/json/yacg_config_schema.json",
"resources/models/json/yacg_model_schema.json",
"--output",
"stdout",
"--template",
"plantuml"
"plantuml=stdout"
],
"console": "integratedTerminal"
},
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 6.3.0
* introcude switch `ignoreXref` to exclude pure x-ref types from loading

# 6.2.0
* enable http/s sources for templates
* enable http/s sources for models
Expand Down
2 changes: 2 additions & 0 deletions bin/runGithubActions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ else
echo "flake8-2 is done"
fi

source venv/bin/activate

if ! python -m unittest discover tests "test_*.py"; then
echo "There are problems in the tests"
popd > /dev/null
Expand Down
14 changes: 14 additions & 0 deletions tests/builder/test_json_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ def testSchemaWithExternalRef(self):
self._checkUpType(2, 'AnotherType', 2, modelTypes, [])
self._checkUpType(3, 'DemoEnum', 0, modelTypes, [])

def testSchemaWithExternalRef_ignoreXref(self):
modelFile = 'tests/resources/models/json/examples/schema_with_external_ref_2.json'
modelFileExists = os.path.isfile(modelFile)
self.assertTrue('model file exists: ' + modelFile, modelFileExists)
model = config.Model()
model.schema = modelFile
modelTypes = getModelFromJson(model, [], False, False)
self.assertIsNotNone(modelTypes)
self.assertEqual(7, len(modelTypes))

modelTypes2 = getModelFromJson(model, [], False, True)
self.assertIsNotNone(modelTypes2)
self.assertEqual(5, len(modelTypes2))

def testSchemaWithHttpRef(self):
modelFile = 'tests/resources/models/json/examples/schema_with_http_ref.json'
modelFileExists = os.path.isfile(modelFile)
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.4
6.3.0
19 changes: 12 additions & 7 deletions yacg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import yacg.util.protocol_funcs as protocolFuncs
from yacg.util.fileUtils import getFileExt

# # needed dependency for remote debugging: pip install debugpy
# import debugpy
# debugpy.listen(('0.0.0.0', 5678))


description = """Yet another code generation.
Program takes one or more models, a bunch of templates and generates
source code from it
Expand All @@ -44,6 +49,7 @@
parser.add_argument('--vars', nargs='+', help='variables that are passed to the processing')
parser.add_argument('--usedFilesOnly', help='import models but only print the used files to stdout', action='store_true')
parser.add_argument('--flattenInheritance', help='flatten included types so that inheritance', action='store_true')
parser.add_argument('--ignoreXref', help='skip loading types that are referenced with `x-ref`', action='store_true')
parser.add_argument('--noLogs', help='do not print logs', action='store_true')
parser.add_argument('--protocolFile', help='where the metadata of the used models for this specifig gen job are stored')
parser.add_argument('--skipCodeGenIfVersionUnchanged', help='when the model versions are unchanged, then the codegen is skipped', action='store_true') # noqa: E501
Expand All @@ -60,25 +66,24 @@
parser.add_argument('--delExistingStoredTemplates', help='set to false to skip download of http located templates if they exist locally', action='store_true') # noqa: E501


def readModels(configJob, flattenInheritance):
def readModels(configJob, flattenInheritance, ignoreXref):
"""reads all desired models and build the model object tree from it"""

loadedTypes = []
yamlExtensions = set(['.yaml', '.yml'])
for model in configJob.models:
fileExt = getFileExt(model.schema)
if fileExt.lower() in yamlExtensions:
loadedTypes = getModelFromYaml(model, loadedTypes)
loadedTypes = getModelFromYaml(model, loadedTypes, False, ignoreXref)
else:
loadedTypes = getModelFromJson(model, loadedTypes)
loadedTypes = getModelFromJson(model, loadedTypes, False, ignoreXref)
return _postProcessLoadedModels(loadedTypes, flattenInheritance)


def _postProcessLoadedModels(loadedTypes, flattenInheritance):
if flattenInheritance:
loadedTypes = modelFuncs.flattenTypes(loadedTypes)
loadedTypes = modelFuncs.processYacgTags(loadedTypes)
return loadedTypes
return modelFuncs.processYacgTags(loadedTypes)


def _getVars(args):
Expand Down Expand Up @@ -424,7 +429,7 @@ def __doCodeGen(codeGenerationJobs, args):
allSkipped = True
jobIndex = 1
for job in codeGenerationJobs:
allLoadedTypes = readModels(job, args.flattenInheritance)
allLoadedTypes = readModels(job, args.flattenInheritance, args.ignoreXref)
modelMetaData = protocolFuncs.getModelMetaData(allLoadedTypes, job.models[0].schema)
jobName = job.name if job.name else "UNKNOWN_JOB_{}".format(jobIndex)
jobsMetaData[jobName] = modelMetaData
Expand Down Expand Up @@ -478,7 +483,7 @@ def __printUsedFiles(codeGenerationJobs, args):

usedFiles = []
for job in codeGenerationJobs:
loadedTypes = readModels(job, args.flattenInheritance)
loadedTypes = readModels(job, args.flattenInheritance, args.ignoreXref)
for type in loadedTypes:
if isinstance(type, EnumType) or isinstance(type, ComplexType):
if type.source is not None:
Expand Down
Loading

0 comments on commit 4d8a599

Please sign in to comment.