Skip to content

Commit c9c0a73

Browse files
fix tests and CI for initial commit
adjusted imports so pylint isn't complaining update CI - setup code-cov, pylint and build package fix linting issues, setup pre-commit fixed executer->executor typo
1 parent 15dc084 commit c9c0a73

File tree

128 files changed

+2144
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2144
-483
lines changed

.github/workflows/build_package.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: build and release openstackquery package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release'
8+
required: true
9+
changelog:
10+
description: 'Release changelog description'
11+
required: false
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
17+
if: github.ref == 'refs/heads/main'
18+
19+
strategy:
20+
matrix:
21+
python-version: ['3.8', '3.x']
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Update version in setup.py
33+
run: |
34+
sed -i "s/version=.*,/version='${{ github.event.inputs.version }}',/" setup.py
35+
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install setuptools wheel build
40+
41+
- name: Build package
42+
run: python -m build
43+
44+
- name: Upload artifacts
45+
uses: actions/upload-artifact@v3
46+
with:
47+
name: dist-${{ matrix.python-version }}
48+
path: dist/
49+
50+
publish:
51+
needs: release
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Download all artifacts
59+
uses: actions/download-artifact@v3
60+
with:
61+
path: dist
62+
63+
- name: Generate Changelog
64+
id: changelog
65+
run: |
66+
if [ -z "${{ github.event.inputs.changelog }}" ]; then
67+
echo "changelog=Release version ${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
68+
else
69+
echo "changelog=${{ github.event.inputs.changelog }}" >> $GITHUB_OUTPUT
70+
fi
71+
72+
- name: Create Git Tag
73+
run: |
74+
git config user.name github-actions
75+
git config user.email [email protected]
76+
git add version.txt
77+
git commit -m "Bump version to ${{ github.event.inputs.version }}"
78+
git tag v${{ github.event.inputs.version }}
79+
git push origin main
80+
git push origin v${{ github.event.inputs.version }}
81+
82+
- name: Create GitHub Release
83+
uses: softprops/action-gh-release@v1
84+
with:
85+
tag_name: v${{ github.event.inputs.version }}
86+
body: ${{ steps.changelog.outputs.changelog }}
87+
files: |
88+
dist/**/*.whl
89+
dist/**/*.tar.gz
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pylint.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.8", "3.9", "3.10"]
10+
python-version: ["3.8", "3.x"]
1111
steps:
1212
- uses: actions/checkout@v4
1313
- name: Set up Python ${{ matrix.python-version }}
@@ -17,7 +17,6 @@ jobs:
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip
20-
pip install pylint
2120
pip install -r requirements.txt
2221
2322
- name: Analysing the code with pylint

.github/workflows/unittest.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@ jobs:
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121

22-
- name: Run Tests
23-
run: cd $GITHUB_WORKSPACE && ./run_tests.sh
24-
25-
- name: Run pytest with codecov
22+
- name: Install dependencies
2623
run: |
27-
pip install -r requirements.txt
28-
pytest tests/enums tests/lib --cov=lib --cov=tests/enums --cov=tests/lib --cov-report xml:coverage.xml
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
2926
30-
- name: Submit Coverage
31-
uses: codecov/codecov-action@v4
32-
with:
33-
fail_ci_if_error: true
34-
token: ${{secrets.CODECOV_TOKEN}}
27+
- name: run tests using pytest
28+
run: |
29+
cd $GITHUB_WORKSPACE && pytest

.pre-commit-config.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.2.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 22.3.0
10+
hooks:
11+
- id: black

.pylintrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[FORMAT]
2+
# Black will enforce 88 chars on Python code
3+
# this will enforce 120 chars on docs / comments
4+
max-line-length=120
5+
6+
# Disable various warnings:
7+
# C0114: Missing module string - we don't need module strings for the small repo
8+
# C0115: Missing class doc string - a lot of the actions are self explanatory
9+
# W0511: TODOs they're well....to do later
10+
# R0801: Similar lines - Imports and method signatures will flag this, such as forwarding action args
11+
# C0116: Missing method docstring - Adds too much noise
12+
# R0913: Too many arguments - same as above
13+
14+
disable=C0114,C0115,E0401,W0511,R0801,C0116,R0913

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
### Note: This is under active development
2-
### TODO: The Query Library needs to be moved out of StackStorm and into a standalone repo
3-
41
# Quick Links
52

63
User-related Docs:
@@ -59,3 +56,6 @@ It will address the following issues:
5956

6057
### 5. Easy to use syntax
6158
- sql-like syntax makes it easy to use
59+
60+
61+
# Installation

openstack_query/__init__.py openstackquery/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
import logging
3-
from .api.query_objects import (
3+
from openstackquery.api.query_objects import (
44
ServerQuery,
55
UserQuery,
66
FlavorQuery,

openstack_query/aliases.py openstackquery/aliases.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from typing import List, Callable, Any, Dict, Union
2-
from enums.props.prop_enum import PropEnum
3-
from enums.query_presets import QueryPresets
4-
52
from openstack.identity.v3.project import Project
63

4+
from openstackquery.enums.props.prop_enum import PropEnum
5+
from openstackquery.enums.query_presets import QueryPresets
6+
7+
78
PropValue = Union[str, bool, int, None]
89

910
# A type alias for a single openstack resource - i.e Server, Hypervisor etc
File renamed without changes.

openstack_query/api/query_api.py openstackquery/api/query_api.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import logging
22
from copy import deepcopy
3+
from typing import TYPE_CHECKING
34
from typing import Union, List, Optional, Dict, Tuple
45

5-
from aliases import OpenstackResourceObj, PropValue
6-
from enums.props.prop_enum import PropEnum
7-
from enums.sort_order import SortOrder
8-
from enums.query_presets import QueryPresets
9-
from exceptions.parse_query_error import ParseQueryError
10-
from structs.query_components import QueryComponents
6+
from openstackquery.aliases import OpenstackResourceObj, PropValue
7+
from openstackquery.enums.props.prop_enum import PropEnum
8+
from openstackquery.enums.sort_order import SortOrder
9+
from openstackquery.enums.query_presets import QueryPresets
10+
from openstackquery.exceptions.parse_query_error import ParseQueryError
11+
12+
if TYPE_CHECKING:
13+
from openstackquery.structs.query_components import QueryComponents
1114

1215
logger = logging.getLogger(__name__)
1316

@@ -17,9 +20,9 @@ class QueryAPI:
1720
Interface for Query Classes. This class exposes all public methods for query api.
1821
"""
1922

20-
def __init__(self, query_components: QueryComponents):
23+
def __init__(self, query_components: "QueryComponents"):
2124
self.builder = query_components.builder
22-
self.executer = query_components.executer
25+
self.executor = query_components.executor
2326
self.parser = query_components.parser
2427
self.output = query_components.output
2528
self.chainer = query_components.chainer
@@ -123,11 +126,11 @@ def run(
123126
filters = (
124127
self.builder.client_side_filters + self.builder.server_filter_fallback
125128
)
126-
self.executer.run_with_subset(
129+
self.executor.run_with_subset(
127130
subset=from_subset, client_side_filters=filters
128131
)
129132
else:
130-
self.executer.run_with_openstacksdk(
133+
self.executor.run_with_openstacksdk(
131134
cloud_account=cloud_account,
132135
client_side_filters=self.builder.client_side_filters,
133136
server_side_filters=self.builder.server_side_filters,
@@ -136,12 +139,12 @@ def run(
136139

137140
link_prop, forwarded_vals = self.chainer.forwarded_info
138141
if forwarded_vals:
139-
self.executer.apply_forwarded_results(
142+
self.executor.apply_forwarded_results(
140143
link_prop,
141144
deepcopy(forwarded_vals),
142145
)
143146

144-
self.results_container = self.executer.results_container
147+
self.results_container = self.executor.results_container
145148
return self
146149

147150
def to_objects(
@@ -152,7 +155,7 @@ def to_objects(
152155
This is either returned as a list if no groups are specified, or as a dict if they grouping was requested
153156
:param groups: a list of group keys to limit output by
154157
"""
155-
if self.executer.has_forwarded_results:
158+
if self.executor.has_forwarded_results:
156159
logger.warning(
157160
"This Query has properties from previous queries. Running to_objects WILL IGNORE THIS "
158161
"Use to_props() instead if you want to include these properties"

openstack_query/api/query_objects.py openstackquery/api/query_objects.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from typing import TYPE_CHECKING
22
from typing import Type
33

4-
from mappings.flavor_mapping import FlavorMapping
5-
from mappings.hypervisor_mapping import HypervisorMapping
6-
from mappings.image_mapping import ImageMapping
7-
from mappings.mapping_interface import MappingInterface
8-
from mappings.project_mapping import ProjectMapping
9-
from mappings.server_mapping import ServerMapping
10-
from mappings.user_mapping import UserMapping
4+
from openstackquery.mappings.flavor_mapping import FlavorMapping
5+
from openstackquery.mappings.hypervisor_mapping import HypervisorMapping
6+
from openstackquery.mappings.image_mapping import ImageMapping
7+
from openstackquery.mappings.mapping_interface import MappingInterface
8+
from openstackquery.mappings.project_mapping import ProjectMapping
9+
from openstackquery.mappings.server_mapping import ServerMapping
10+
from openstackquery.mappings.user_mapping import UserMapping
1111

1212
if TYPE_CHECKING:
13-
from api.query_api import QueryAPI
13+
from openstackquery.api.query_api import QueryAPI
1414

1515

1616
def get_common(query_mapping: Type[MappingInterface]) -> "QueryAPI":
@@ -20,8 +20,8 @@ def get_common(query_mapping: Type[MappingInterface]) -> "QueryAPI":
2020
:param query_mapping: a mapping class that defines property, runner and handler mappings
2121
"""
2222
# pylint: disable=import-outside-toplevel
23-
from api.query_api import QueryAPI
24-
from query_factory import QueryFactory
23+
from openstackquery.api.query_api import QueryAPI
24+
from openstackquery.query_factory import QueryFactory
2525

2626
return QueryAPI(QueryFactory.build_query_deps(query_mapping))
2727

File renamed without changes.

openstack_query/enums/enum_with_aliases.py openstackquery/enums/enum_with_aliases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from typing import Dict
44

5-
from exceptions.parse_query_error import ParseQueryError
5+
from openstackquery.exceptions.parse_query_error import ParseQueryError
66

77

88
class EnumWithAliases(Enum):
File renamed without changes.

openstack_query/enums/props/flavor_properties.py openstackquery/enums/props/flavor_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import auto
2-
from enums.props.prop_enum import PropEnum
3-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
2+
from openstackquery.enums.props.prop_enum import PropEnum
3+
from openstackquery.exceptions.query_property_mapping_error import (
4+
QueryPropertyMappingError,
5+
)
46

57

68
class FlavorProperties(PropEnum):

openstack_query/enums/props/hypervisor_properties.py openstackquery/enums/props/hypervisor_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from enum import auto
22
from typing import Dict, Optional
33

4-
from enums.props.prop_enum import PropEnum, PropFunc
5-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
4+
from openstackquery.enums.props.prop_enum import PropEnum, PropFunc
5+
from openstackquery.exceptions.query_property_mapping_error import (
6+
QueryPropertyMappingError,
7+
)
68

79

810
class HypervisorProperties(PropEnum):

openstack_query/enums/props/image_properties.py openstackquery/enums/props/image_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import auto
2-
from enums.props.prop_enum import PropEnum
3-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
2+
from openstackquery.enums.props.prop_enum import PropEnum
3+
from openstackquery.exceptions.query_property_mapping_error import (
4+
QueryPropertyMappingError,
5+
)
46

57

68
class ImageProperties(PropEnum):

openstack_query/enums/props/project_properties.py openstackquery/enums/props/project_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import auto
2-
from enums.props.prop_enum import PropEnum
3-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
2+
from openstackquery.enums.props.prop_enum import PropEnum
3+
from openstackquery.exceptions.query_property_mapping_error import (
4+
QueryPropertyMappingError,
5+
)
46

57

68
class ProjectProperties(PropEnum):

openstack_query/enums/props/prop_enum.py openstackquery/enums/props/prop_enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import abstractmethod
22
from typing import Callable, Any, Optional
33

4-
from enums.enum_with_aliases import EnumWithAliases
4+
from openstackquery.enums.enum_with_aliases import EnumWithAliases
55

66
PropFunc = Callable[[Any], Any]
77

openstack_query/enums/props/server_properties.py openstackquery/enums/props/server_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import auto
2-
from enums.props.prop_enum import PropEnum
3-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
2+
from openstackquery.enums.props.prop_enum import PropEnum
3+
from openstackquery.exceptions.query_property_mapping_error import (
4+
QueryPropertyMappingError,
5+
)
46

57

68
class ServerProperties(PropEnum):

openstack_query/enums/props/user_properties.py openstackquery/enums/props/user_properties.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import auto
2-
from enums.props.prop_enum import PropEnum
3-
from exceptions.query_property_mapping_error import QueryPropertyMappingError
2+
from openstackquery.enums.props.prop_enum import PropEnum
3+
from openstackquery.exceptions.query_property_mapping_error import (
4+
QueryPropertyMappingError,
5+
)
46

57

68
class UserProperties(PropEnum):

openstack_query/enums/query_output_types.py openstackquery/enums/query_output_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum, auto
2-
from exceptions.parse_query_error import ParseQueryError
2+
from openstackquery.exceptions.parse_query_error import ParseQueryError
33

44

55
# pylint: disable=too-few-public-methods

0 commit comments

Comments
 (0)