Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle one line blocks as regular blocks #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: build
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be in this pr, its unrelated to the functionality of the fix, ie. its switching ci

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. My bad. After waiting to get this one merged I created a temporal fork. Would gladly drop it when if the other changes in the PR looks good to the maintainers.


on:
push:
branches:
- master
jobs:

bump-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: |
pipenv install --dev
- name: update docs and bump version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "latest tag: $latest_tag"
new_tag=$(echo $latest_tag | awk -F. -v a="$1" -v b="$2" -v c="$3" '{printf("%d.%d.%d", $1+a, $2+b , $3+1)}')
echo "new tag: $new_tag"

## update python version
echo "__version__ = '$new_tag'" > 'hcl2/version.py'

git commit --reuse-message=HEAD@{1} hcl2/version.py || echo "No changes to commit"
git push origin
git tag $new_tag
git push origin $new_tag
publish-package:
needs: bump-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: |
pipenv install --dev
- name: create python package
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git fetch --tags
git pull
pipenv run python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- name: sleep and wait for package to refresh
run: |
sleep 2m
2 changes: 1 addition & 1 deletion bin/versionCheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IS_PULL_REQUEST=$2 # false if not a pull request,

# Makes sure travis does not check version if doing a pull request
if [ "$IS_PULL_REQUEST" != "false" ]; then
if git diff --quiet "origin/${TARGET_BRANCH}...HEAD" 'python-hcl2' "test" setup.* ./*.pip; then
if git diff --quiet "origin/${TARGET_BRANCH}...HEAD" 'bc-python-hcl2' "test" setup.* ./*.pip; then
echo "No changes found to main code or dependencies: no version change needed"
exit 0
fi
Expand Down
9 changes: 4 additions & 5 deletions hcl2/hcl2.lark
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
start : new_line_or_comment? body new_line_or_comment?
body : (attribute | block | one_line_block)*
attribute : identifier "=" expression new_line_or_comment
block : identifier (identifier | STRING_LIT)* "{" new_line_or_comment body "}" new_line_or_comment
one_line_block : identifier (identifier | STRING_LIT)* "{" (identifier "=" expression)? "}" new_line_or_comment
body : (attribute | block)*
attribute : identifier "=" expression (new_line_or_comment)?
block : identifier (identifier | STRING_LIT)* "{" (new_line_or_comment)? body "}" new_line_or_comment
new_line_and_or_comma: new_line_or_comment | "," | "," new_line_or_comment
new_line_or_comment: ( /\n/ | /#.*\n/ | /\/\/.*\n/ )+

Expand Down Expand Up @@ -66,7 +65,7 @@ index_expr_term : expr_term index
get_attr_expr_term : expr_term get_attr
attr_splat_expr_term : expr_term attr_splat
full_splat_expr_term : expr_term full_splat
index : "[" new_line_or_comment? expression new_line_or_comment? "]"
index : "[" new_line_or_comment? expression new_line_or_comment? "]" | "." DECIMAL+
?get_attr : "." identifier
?attr_splat : ".*" get_attr*
?full_splat : "[" "*" "]" (get_attr | index)*
Expand Down
3 changes: 0 additions & 3 deletions hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ def block(self, args: List) -> Dict:

return result

def one_line_block(self, args: List) -> Dict:
return self.block(args)

def attribute(self, args: List) -> Dict:
key = str(args[0])
if key.startswith('"') and key.endswith('"'):
Expand Down
4 changes: 1 addition & 3 deletions hcl2/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
"""Place of record for the package version"""
__version__ = "0.3.2"

__version__ = "0.3.0"
__git_hash__ = "GIT_HASH"
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "python-hcl2",
"name": "bc-python-hcl2",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your referencing your fork, instead of the upstream your contributing to.

"devDependencies": {
"remark-cli": "^6.0.1",
"remark-preset-lint-consistent": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_requirements():


setup(
name='python-hcl2',
name='bc-python-hcl2',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your referencing your fork, instead of the upstream your contributing to.

python_requires='>=3.6.0',
version=get_version(),
description="A parser for HCL2",
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/terraform-config-json/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
],
"terraform": [
{
"required_version": {
"0.12": {}
}
"required_version": [
"0.12"
]
},
{
"backend": [
Expand Down
18 changes: 18 additions & 0 deletions test/helpers/terraform-config-json/route_table.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
]
}
}
},
{
"aws_route": {
"tgw-dot-index": {
"count": [
"${var.tgw_name == \"\" ? 0 : var.number_of_az}"
],
"route_table_id": [
"${aws_route_table.rt[count.index].id}"
],
"destination_cidr_block": [
"10.0.0.0/8"
],
"transit_gateway_id": [
"${data.aws_ec2_transit_gateway.tgw[0].id}"
]
}
}
}
]
}
7 changes: 7 additions & 0 deletions test/helpers/terraform-config/route_table.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ resource "aws_route" "tgw" {
destination_cidr_block = "10.0.0.0/8"
transit_gateway_id = data.aws_ec2_transit_gateway.tgw[0].id
}

resource "aws_route" "tgw-dot-index" {
count = var.tgw_name == "" ? 0 : var.number_of_az
route_table_id = aws_route_table.rt[count.index].id
destination_cidr_block = "10.0.0.0/8"
transit_gateway_id = data.aws_ec2_transit_gateway.tgw.0.id
}