Skip to content

Commit 554f63c

Browse files
Merge pull request #7 from BrunoSilvaAndrade/develop
Develop
2 parents b4e7fd6 + c2a7225 commit 554f63c

9 files changed

Lines changed: 72 additions & 9 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
name: Upload Python Package
1010

1111
on:
12+
push:
13+
tags:
14+
- 'v*'
1215
release:
1316
types: [published]
1417

@@ -30,6 +33,8 @@ jobs:
3033
run: |
3134
python -m pip install --upgrade pip
3235
pip install build
36+
- name: Set Release Version
37+
run: RELEASE_VERSION=${GITHUB_REF#refs/*/v}
3338
- name: Build package
3439
run: python -m build -w -s
3540
- name: Publish package
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Report Coverage
2+
3+
on:
4+
release:
5+
branches: ["master"]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install pytest coverage coveralls
25+
- name: Report coverage
26+
env:
27+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
28+
run: |
29+
coverage run --source=./ -m pytest
30+
coveralls
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Python package
4+
name: Tests
55

66
on:
77
push:

.github/workflows/version.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Bump version
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Bump version and push tag
12+
id: tag_version
13+
uses: mathieudutour/github-tag-action@v6.0
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}
16+
- name: Create a GitHub release
17+
uses: ncipollo/release-action@v1
18+
with:
19+
tag: ${{ steps.tag_version.outputs.new_tag }}
20+
name: Release ${{ steps.tag_version.outputs.new_tag }}
21+
body: ${{ steps.tag_version.outputs.changelog }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Python-config-parser
22
===
3+
---
4+
[![Tests](https://github.com/BrunoSilvaAndrade/python-config-parser/actions/workflows/tests.yml/badge.svg)](https://github.com/BrunoSilvaAndrade/python-config-parser/actions/workflows/tests.yml)
5+
[![PyPI version](https://badge.fury.io/py/python-config-parser.svg)](https://badge.fury.io/py/python-config-parser)
6+
37
This project was created to give you the possibility
48
of creating runtime configuration objects using json or yaml files.
59

parsers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
import yaml
33

44

5-
class ParseException(Exception):
5+
class ParseError(Exception):
66
pass
77

88

99
def json_parser(file_buff):
1010
try:
1111
return json.loads(file_buff)
1212
except json.JSONDecodeError as e:
13-
raise ParseException(f'Unable to decode config file using json', e)
13+
raise ParseError('Unable to decode config file using json', e)
1414

1515

1616
def yaml_parser(file_buff):
1717
try:
1818
return yaml.safe_load(file_buff)
1919
except yaml.YAMLError as e:
20-
raise ParseException(f'Unable to decode config file using yaml', e)
20+
raise ParseError('Unable to decode config file using yaml', e)

pyconfigparser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from parsers import ParseException, json_parser, yaml_parser
1+
from parsers import ParseError, json_parser, yaml_parser
22
from schema import Schema, SchemaError
33
from typing import Any
44
from os import path
@@ -78,6 +78,8 @@ def __create_new_instance(cls, schema, config_dir, file_name):
7878
try:
7979
config = cls.__validate_schema(schema, parser(file_buff))
8080
return cls.__dict_2_obj(config)
81+
except ParseError as e:
82+
raise ConfigError(e)
8183
except SchemaError as e:
8284
raise ConfigError('Schema validation error', e)
8385

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import setuptools
2+
import os
23

34
with open('README.md', 'r') as fh:
45
long_description = fh.read()
56

67
setuptools.setup(
78
name='python-config-parser',
8-
version='2.2.1',
9+
version=os.environ['RELEASE_VERSION'],
910
author='Bruno Silva de Andrade',
1011
author_email='brunojf.andrade@gmail.com',
1112
description='Project created to given the possibility of create dynamics config files',

test_configparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pyconfigparser import Config, ConfigError, ConfigFileNotFoundError, ParseException
1+
from pyconfigparser import Config, ConfigError, ConfigFileNotFoundError
22
from config.schemas import SIMPLE_SCHEMA_CONFIG, UNSUPPORTED_OBJECT_KEYS_SCHEMA
33
import unittest
44
import os
@@ -56,8 +56,8 @@ def test_config_file_with_unsupported_extension(self):
5656
self.assertRaises(ConfigError, Config.get_config, SIMPLE_SCHEMA_CONFIG, file_name='config.bad_extension')
5757

5858
def test_bad_decoder_error(self):
59-
self.assertRaises(ParseException, Config.get_config, SIMPLE_SCHEMA_CONFIG, file_name='bad_content.json')
60-
self.assertRaises(ParseException, Config.get_config, SIMPLE_SCHEMA_CONFIG, file_name='bad_content.yaml')
59+
self.assertRaises(ConfigError, Config.get_config, SIMPLE_SCHEMA_CONFIG, file_name='bad_content.json')
60+
self.assertRaises(ConfigError, Config.get_config, SIMPLE_SCHEMA_CONFIG, file_name='bad_content.yaml')
6161

6262

6363
if __name__ == '__main__':

0 commit comments

Comments
 (0)