Skip to content

Commit

Permalink
fix tests and CI for initial commit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anish-mudaraddi committed Nov 29, 2024
1 parent 15dc084 commit c9c0a73
Show file tree
Hide file tree
Showing 128 changed files with 2,144 additions and 483 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: build and release openstackquery package

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
changelog:
description: 'Release changelog description'
required: false

jobs:
release:
runs-on: ubuntu-latest

if: github.ref == 'refs/heads/main'

strategy:
matrix:
python-version: ['3.8', '3.x']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Update version in setup.py
run: |
sed -i "s/version=.*,/version='${{ github.event.inputs.version }}',/" setup.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build
- name: Build package
run: python -m build

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist-${{ matrix.python-version }}
path: dist/

publish:
needs: release
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: dist

- name: Generate Changelog
id: changelog
run: |
if [ -z "${{ github.event.inputs.changelog }}" ]; then
echo "changelog=Release version ${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "changelog=${{ github.event.inputs.changelog }}" >> $GITHUB_OUTPUT
fi
- name: Create Git Tag
run: |
git config user.name github-actions
git config user.email [email protected]
git add version.txt
git commit -m "Bump version to ${{ github.event.inputs.version }}"
git tag v${{ github.event.inputs.version }}
git push origin main
git push origin v${{ github.event.inputs.version }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ github.event.inputs.version }}
body: ${{ steps.changelog.outputs.changelog }}
files: |
dist/**/*.whl
dist/**/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.x"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -17,7 +17,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Run Tests
run: cd $GITHUB_WORKSPACE && ./run_tests.sh

- name: Run pytest with codecov
- name: Install dependencies
run: |
pip install -r requirements.txt
pytest tests/enums tests/lib --cov=lib --cov=tests/enums --cov=tests/lib --cov-report xml:coverage.xml
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Submit Coverage
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{secrets.CODECOV_TOKEN}}
- name: run tests using pytest
run: |
cd $GITHUB_WORKSPACE && pytest
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
14 changes: 14 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[FORMAT]
# Black will enforce 88 chars on Python code
# this will enforce 120 chars on docs / comments
max-line-length=120

# Disable various warnings:
# C0114: Missing module string - we don't need module strings for the small repo
# C0115: Missing class doc string - a lot of the actions are self explanatory
# W0511: TODOs they're well....to do later
# R0801: Similar lines - Imports and method signatures will flag this, such as forwarding action args
# C0116: Missing method docstring - Adds too much noise
# R0913: Too many arguments - same as above

disable=C0114,C0115,E0401,W0511,R0801,C0116,R0913
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
### Note: This is under active development
### TODO: The Query Library needs to be moved out of StackStorm and into a standalone repo

# Quick Links

User-related Docs:
Expand Down Expand Up @@ -59,3 +56,6 @@ It will address the following issues:

### 5. Easy to use syntax
- sql-like syntax makes it easy to use


# Installation
2 changes: 1 addition & 1 deletion openstack_query/__init__.py → openstackquery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import logging
from .api.query_objects import (
from openstackquery.api.query_objects import (
ServerQuery,
UserQuery,
FlavorQuery,
Expand Down
7 changes: 4 additions & 3 deletions openstack_query/aliases.py → openstackquery/aliases.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Callable, Any, Dict, Union
from enums.props.prop_enum import PropEnum
from enums.query_presets import QueryPresets

from openstack.identity.v3.project import Project

from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.enums.query_presets import QueryPresets


PropValue = Union[str, bool, int, None]

# A type alias for a single openstack resource - i.e Server, Hypervisor etc
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import logging
from copy import deepcopy
from typing import TYPE_CHECKING
from typing import Union, List, Optional, Dict, Tuple

from aliases import OpenstackResourceObj, PropValue
from enums.props.prop_enum import PropEnum
from enums.sort_order import SortOrder
from enums.query_presets import QueryPresets
from exceptions.parse_query_error import ParseQueryError
from structs.query_components import QueryComponents
from openstackquery.aliases import OpenstackResourceObj, PropValue
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.enums.sort_order import SortOrder
from openstackquery.enums.query_presets import QueryPresets
from openstackquery.exceptions.parse_query_error import ParseQueryError

if TYPE_CHECKING:
from openstackquery.structs.query_components import QueryComponents

logger = logging.getLogger(__name__)

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

def __init__(self, query_components: QueryComponents):
def __init__(self, query_components: "QueryComponents"):
self.builder = query_components.builder
self.executer = query_components.executer
self.executor = query_components.executor
self.parser = query_components.parser
self.output = query_components.output
self.chainer = query_components.chainer
Expand Down Expand Up @@ -123,11 +126,11 @@ def run(
filters = (
self.builder.client_side_filters + self.builder.server_filter_fallback
)
self.executer.run_with_subset(
self.executor.run_with_subset(
subset=from_subset, client_side_filters=filters
)
else:
self.executer.run_with_openstacksdk(
self.executor.run_with_openstacksdk(
cloud_account=cloud_account,
client_side_filters=self.builder.client_side_filters,
server_side_filters=self.builder.server_side_filters,
Expand All @@ -136,12 +139,12 @@ def run(

link_prop, forwarded_vals = self.chainer.forwarded_info
if forwarded_vals:
self.executer.apply_forwarded_results(
self.executor.apply_forwarded_results(
link_prop,
deepcopy(forwarded_vals),
)

self.results_container = self.executer.results_container
self.results_container = self.executor.results_container
return self

def to_objects(
Expand All @@ -152,7 +155,7 @@ def to_objects(
This is either returned as a list if no groups are specified, or as a dict if they grouping was requested
:param groups: a list of group keys to limit output by
"""
if self.executer.has_forwarded_results:
if self.executor.has_forwarded_results:
logger.warning(
"This Query has properties from previous queries. Running to_objects WILL IGNORE THIS "
"Use to_props() instead if you want to include these properties"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import TYPE_CHECKING
from typing import Type

from mappings.flavor_mapping import FlavorMapping
from mappings.hypervisor_mapping import HypervisorMapping
from mappings.image_mapping import ImageMapping
from mappings.mapping_interface import MappingInterface
from mappings.project_mapping import ProjectMapping
from mappings.server_mapping import ServerMapping
from mappings.user_mapping import UserMapping
from openstackquery.mappings.flavor_mapping import FlavorMapping
from openstackquery.mappings.hypervisor_mapping import HypervisorMapping
from openstackquery.mappings.image_mapping import ImageMapping
from openstackquery.mappings.mapping_interface import MappingInterface
from openstackquery.mappings.project_mapping import ProjectMapping
from openstackquery.mappings.server_mapping import ServerMapping
from openstackquery.mappings.user_mapping import UserMapping

if TYPE_CHECKING:
from api.query_api import QueryAPI
from openstackquery.api.query_api import QueryAPI


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

return QueryAPI(QueryFactory.build_query_deps(query_mapping))

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Dict

from exceptions.parse_query_error import ParseQueryError
from openstackquery.exceptions.parse_query_error import ParseQueryError


class EnumWithAliases(Enum):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import auto
from enums.props.prop_enum import PropEnum
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class FlavorProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from enum import auto
from typing import Dict, Optional

from enums.props.prop_enum import PropEnum, PropFunc
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum, PropFunc
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class HypervisorProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import auto
from enums.props.prop_enum import PropEnum
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class ImageProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import auto
from enums.props.prop_enum import PropEnum
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class ProjectProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import abstractmethod
from typing import Callable, Any, Optional

from enums.enum_with_aliases import EnumWithAliases
from openstackquery.enums.enum_with_aliases import EnumWithAliases

PropFunc = Callable[[Any], Any]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import auto
from enums.props.prop_enum import PropEnum
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class ServerProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import auto
from enums.props.prop_enum import PropEnum
from exceptions.query_property_mapping_error import QueryPropertyMappingError
from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)


class UserProperties(PropEnum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, auto
from exceptions.parse_query_error import ParseQueryError
from openstackquery.exceptions.parse_query_error import ParseQueryError


# pylint: disable=too-few-public-methods
Expand Down
Loading

0 comments on commit c9c0a73

Please sign in to comment.