Skip to content

Commit acd6701

Browse files
authored
Merge pull request #4 from riscv/resolve-issue-#3
Made logging optional in check_specs
2 parents 560264f + 6b9e65a commit acd6701

File tree

7 files changed

+66
-48
lines changed

7 files changed

+66
-48
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ script:
88
- pip install -r requirements.txt
99
- make latexpdf
1010
- cd ../
11-
- python setup.py sdist
12-
- python -m twine upload --username $pypiusername --password $pypipassword dist/*
11+
- if [ "$TRAVIS_BRANCH" = "master" ]; then python setup.py sdist; fi
12+
- if [ "$TRAVIS_BRANCH" = "master" ]; then python -m twine upload --username $pypiusername --password $pypipassword dist/*; fi
1313
before_deploy:
1414
- git tag $TAGNAME
1515
deploy:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## 1.0.2 - 2019-08-09
6+
### Changed
7+
- Log is generated only if specified(for API calls to checker.check_specs).
8+
### Fixed
9+
- link in readme now points to github instead of gitlab.
10+
511
## 1.0.0 - 2019-07-30
612
### Changed
713
- Work directory isnt deleted if the directory exists, although the files of the same name will be overwritten.

docs/source/quickstart.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Installation and Setup
3636

3737
.. code-block:: bash
3838
39-
git clone https://gitlab.com/incoresemi/riscv_config.git
39+
git clone https://github.com/riscv/riscv-config.git
4040
cd riscv_config
4141
pip3 install -r requirements.txt
4242
@@ -89,7 +89,7 @@ Example
8989

9090
.. code-block:: bash
9191
92-
git clone https://gitlab.com/incoresemi/riscv_config.git
92+
git clone https://github.com/riscv/riscv-config.git
9393
9494
cd riscv_config/
9595

riscv_config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pkgutil import extend_path
22
__path__ = extend_path(__path__, __name__)
3-
__version__ = "1.0.0"
3+
__version__ = "1.0.2"

riscv_config/checker.py

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
logger = logging.getLogger(__name__)
1313

14-
1514
def iset():
1615
'''Function to check and set defaults for all "implemented" fields which are dependent on
1716
the xlen.'''
@@ -210,23 +209,7 @@ def imp_normalise(foo):
210209
break
211210
return foo
212211

213-
214-
def errPrint(foo, space=' '):
215-
'''
216-
Function to petty print the error from cerberus.
217-
'''
218-
error = ''
219-
for key in foo.keys():
220-
error += space + str(key) + ":"
221-
if isinstance(foo[key][0], dict):
222-
error += "\n" + errPrint(foo[key][0], space + space)
223-
else:
224-
error += str(foo[key][0])
225-
error += "\n"
226-
return error.rstrip()
227-
228-
229-
def check_specs(isa_spec, platform_spec, work_dir):
212+
def check_specs(isa_spec, platform_spec, work_dir,logging=False):
230213
'''
231214
Function to perform ensure that the isa and platform specifications confirm
232215
to their schemas. The :py:mod:`Cerberus` module is used to validate that the
@@ -235,20 +218,25 @@ def check_specs(isa_spec, platform_spec, work_dir):
235218
:param isa_spec: The path to the DUT isa specification yaml file.
236219
237220
:param platform_spec: The path to the DUT platform specification yaml file.
221+
222+
:param logging: A boolean to indicate whether log is to be printed.
223+
224+
:type logging: bool
238225
239226
:type isa_spec: str
240227
241228
:type platform_spec: str
242229
243230
:raise ValidationError: It is raised when the specifications violate the
244-
schema rules.
231+
schema rules. It also contains the specific errors in each of the fields.
245232
246-
:return: A tuple with the first entry being the path to normalized isa file
247-
and the second being path to the platform spec file.
233+
:return: A tuple with the first entry being the absolute path to normalized isa file
234+
and the second being the absolute path to the platform spec file.
248235
'''
249236
global inp_yaml
250237

251-
logger.info('Input-ISA file')
238+
if logging:
239+
logger.info('Input-ISA file')
252240

253241
foo = isa_spec
254242
schema = constants.isa_schema
@@ -257,11 +245,13 @@ def check_specs(isa_spec, platform_spec, work_dir):
257245
and constraints
258246
"""
259247
# Load input YAML file
260-
logger.info('Loading input file: ' + str(foo))
248+
if logging:
249+
logger.info('Loading input file: ' + str(foo))
261250
inp_yaml = utils.load_yaml(foo)
262251

263252
# instantiate validator
264-
logger.info('Load Schema ' + str(schema))
253+
if logging:
254+
logger.info('Load Schema ' + str(schema))
265255
schema_yaml = utils.load_yaml(schema)
266256

267257
#Extract xlen
@@ -274,28 +264,30 @@ def check_specs(isa_spec, platform_spec, work_dir):
274264
normalized = validator.normalized(inp_yaml, schema_yaml)
275265

276266
# Perform Validation
277-
logger.info('Initiating Validation')
267+
if logging:
268+
logger.info('Initiating Validation')
278269
valid = validator.validate(inp_yaml)
279270

280271
# Print out errors
281272
if valid:
282-
logger.info('No Syntax errors in Input ISA Yaml. :)')
273+
if logging:
274+
logger.info('No Syntax errors in Input ISA Yaml. :)')
283275
else:
284276
error_list = validator.errors
285-
logger.error("Error in " + foo + "\n" + errPrint(error_list))
286-
raise ValidationError(
287-
"Error in ISA Yaml. Refer to logs for more details.")
277+
raise ValidationError("Error in " + foo + ".",error_list)
288278

289279
file_name = os.path.split(foo)
290280
file_name_split = file_name[1].split('.')
291281
output_filename = os.path.join(
292282
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
293283
ifile = output_filename
294284
outfile = open(output_filename, 'w')
295-
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
285+
if logging:
286+
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
296287
yaml.dump(imp_normalise(normalized), outfile)
297288

298-
logger.info('Input-Platform file')
289+
if logging:
290+
logger.info('Input-Platform file')
299291

300292
foo = platform_spec
301293
schema = constants.platform_schema
@@ -304,13 +296,15 @@ def check_specs(isa_spec, platform_spec, work_dir):
304296
and constraints
305297
"""
306298
# Load input YAML file
307-
logger.info('Loading input file: ' + str(foo))
299+
if logging:
300+
logger.info('Loading input file: ' + str(foo))
308301
inp_yaml = utils.load_yaml(foo)
309302
if inp_yaml is None:
310303
inp_yaml = {'mtime': {'implemented': False}}
311304

312305
# instantiate validator
313-
logger.info('Load Schema ' + str(schema))
306+
if logging:
307+
logger.info('Load Schema ' + str(schema))
314308
schema_yaml = utils.load_yaml(schema)
315309

316310
validator = schemaValidator(schema_yaml, xlen=xlen)
@@ -319,24 +313,25 @@ def check_specs(isa_spec, platform_spec, work_dir):
319313
normalized = validator.normalized(inp_yaml, schema_yaml)
320314

321315
# Perform Validation
322-
logger.info('Initiating Validation')
316+
if logging:
317+
logger.info('Initiating Validation')
323318
valid = validator.validate(inp_yaml)
324319

325320
# Print out errors
326321
if valid:
327-
logger.info('No Syntax errors in Input Platform Yaml. :)')
322+
if logging:
323+
logger.info('No Syntax errors in Input Platform Yaml. :)')
328324
else:
329325
error_list = validator.errors
330-
logger.error("Error in " + foo + "\n" + errPrint(error_list))
331-
raise ValidationError("Error in Platform\
332-
Yaml. Refer to logs for more details.")
326+
raise ValidationError("Error in " + foo + ".",error_list)
333327

334328
file_name = os.path.split(foo)
335329
file_name_split = file_name[1].split('.')
336330
output_filename = os.path.join(
337331
work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
338332
pfile = output_filename
339333
outfile = open(output_filename, 'w')
340-
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
334+
if logging:
335+
logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
341336
yaml.dump(imp_normalise(normalized), outfile)
342337
return (ifile, pfile)

riscv_config/errors.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
class ValidationError(Exception):
2-
pass
2+
def __init__(self,message,errors):
3+
super().__init__(message)
4+
self.message=message
5+
self.errors=errors
6+
def __errPrint__(self,foo, space=' '):
7+
'''
8+
Function to petty print the error from cerberus.
9+
'''
10+
error = ''
11+
for key in foo.keys():
12+
error += space + str(key) + ":"
13+
if isinstance(foo[key][0], dict):
14+
error += "\n" + self.__errPrint__(foo[key][0], space + space)
15+
else:
16+
error += str(foo[key][0])
17+
error += "\n"
18+
return error.rstrip()
19+
def __str__(self):
20+
return self.message+"\n"+self.__errPrint__(self.errors)

riscv_config/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import riscv_config.utils as utils
77
from riscv_config.errors import ValidationError
88

9-
109
def main():
1110
'''
1211
Entry point for riscv_config.
@@ -32,9 +31,9 @@ def main():
3231

3332
try:
3433
checker.check_specs(os.path.abspath(args.isa_spec),
35-
os.path.abspath(args.platform_spec), work_dir)
34+
os.path.abspath(args.platform_spec), work_dir, True)
3635
except ValidationError as msg:
37-
logger.error(msg)
36+
logger.error(str(msg))
3837
return 1
3938

4039

0 commit comments

Comments
 (0)