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

chore: Use python 3.10 in GH actions #224

Merged
merged 2 commits into from
Dec 2, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- uses: pre-commit/[email protected]
6 changes: 3 additions & 3 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- uses: pre-commit/[email protected]

test:
Expand All @@ -24,7 +24,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- name: Install Tox and any other packages
run: pip install tox
- name: Run Tox
Expand All @@ -38,7 +38,7 @@ jobs:
steps:
- uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- name: Display Python version
run: python --version
- name: Set up changelog date to use later
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
default_language_version:
python: python3.9
python: python3.10

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -16,23 +16,23 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/jorisroovers/gitlint
rev: v0.14.0
rev: v0.18.0
hooks:
- id: gitlint

- repo: https://github.com/adrienverge/yamllint
rev: v1.25.0
rev: v1.28.0
hooks:
- id: yamllint

- repo: https://github.com/PyCQA/pydocstyle
rev: 5.1.1
rev: 6.1.1
hooks:
- id: pydocstyle
files: ^src/.*

- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
exclude: ^docs/.*
Expand All @@ -41,24 +41,23 @@ repos:
require_serial: true

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.6.4
rev: v5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
exclude: ^docs/.*$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
rev: v0.991
hooks:
- id: mypy
exclude: ^(docs|tests)/.*$
args: ["--ignore-missing-imports"]
additional_dependencies: ["types-PyYAML", "types-python-dateutil"]

- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.7.4
rev: v3.0.0a5
hooks:
- id: pylint
additional_dependencies: ["isort[pyproject]"]
exclude: ^(docs/|tests/).*$
# disabled import-error as may be run out of environment with deps
args: ["--disable=import-error"]
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#disable=
# mrack is starting to use f style strings string-interpolation and have some
# specific classes which are adding functionality to ones they inherit from
disable=fixme,too-many-instance-attributes,no-self-use,attribute-defined-outside-init,unnecessary-pass,super-init-not-called,too-many-arguments,too-few-public-methods,logging-fstring-interpolation,
disable=fixme,too-many-instance-attributes,attribute-defined-outside-init,unnecessary-pass,super-init-not-called,too-many-arguments,too-few-public-methods,logging-fstring-interpolation,import-error

# Minimum lines number of a similarity.
min-similarity-lines=11
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'

steps:
- task: UsePythonVersion@0
Expand Down
5 changes: 3 additions & 2 deletions src/mrack/outputs/ansible_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AnsibleInventoryOutput:
files and information in DB.
"""

def __init__(self, config, db, metadata, path=None):
def __init__(self, config, db, metadata, path=None): # pylint: disable=invalid-name
"""Init the output module."""
self._config = config
self._db = db
Expand All @@ -138,6 +138,7 @@ def create_ansible_host(self, name):
dom_name = meta_domain["name"]

# Common attributes
dc_list = [f"DC={dc}" for dc in dom_name.split(".")]
host_info = {
"ansible_host": ansible_host,
"ansible_python_interpreter": python,
Expand All @@ -148,7 +149,7 @@ def create_ansible_host(self, name):
"meta_provider": db_host.provider.name,
"meta_provider_id": db_host.host_id,
"meta_ip": ip_addr,
"meta_dc_record": ",".join("DC=%s" % dc for dc in dom_name.split(".")),
"meta_dc_record": ",".join(dc_list),
}

if "restraint_id" in meta_host:
Expand Down
2 changes: 1 addition & 1 deletion src/mrack/outputs/pytest_multihost.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PytestMultihostOutput:
metadata definition.
"""

def __init__(self, config, db, metadata, path=None):
def __init__(self, config, db, metadata, path=None): # pylint: disable=invalid-name
"""Init the output module."""
self._config = config
self._db = db
Expand Down
4 changes: 2 additions & 2 deletions src/mrack/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Registry:

def __init__(self):
"""Initialize Registry."""
self._provider_cls = dict()
self._providers = dict()
self._provider_cls = {}
self._providers = {}

def register(self, name, provider_cls):
"""Register new provider."""
Expand Down
4 changes: 2 additions & 2 deletions src/mrack/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Registry:

def __init__(self):
"""Initialize transformer registry."""
self._transformer_cls = dict()
self._transformers = dict()
self._transformer_cls = {}
self._transformers = {}

def register(self, name, transformer_cls):
"""Register new tranformer class."""
Expand Down
42 changes: 26 additions & 16 deletions src/mrack/transformers/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@
logger.debug(IMPORT_ERR, import_err.name)


@cache
def cached_get_vm_owner():
"""Return ownership info for host."""
owner = os.getenv("MRACK_VM_OWNER")
logger.debug(f"MRACK_VM_OWNER: {owner}")
if not owner and gssapi:
try:
creds = gssapi.Credentials(usage="initiate")
logger.debug(f"GSSAPI credentials: {creds}")
owner = str(creds.name).split("@", maxsplit=1)[0]
except gssapi.exceptions.MissingCredentialsError:
logger.debug("No kerberos credentials discovered.")
except gssapi.exceptions.GSSError as exc:
logger.exception(exc)
return owner


@cache
def cached_get_vm_lifetime():
"""Return lifetime info for host."""
return os.getenv("MRACK_VM_LIFETIME")


class Transformer:
"""Base class for transformers."""

Expand Down Expand Up @@ -165,26 +188,13 @@ def create_host_requirements(self):
)
return reqs

@cache
def get_vm_owner(self):
"""Return ownership info for host."""
owner = os.getenv("MRACK_VM_OWNER")
logger.debug(f"MRACK_VM_OWNER: {owner}")
if not owner and gssapi:
try:
creds = gssapi.Credentials(usage="initiate")
logger.debug(f"GSSAPI credentials: {creds}")
owner = str(creds.name).split("@")[0]
except gssapi.exceptions.MissingCredentialsError:
logger.debug("No kerberos credentials discovered.")
except gssapi.exceptions.GSSError as exc:
logger.exception(exc)
return owner

@cache
return cached_get_vm_owner()

def get_vm_lifetime(self):
"""Return lifetime info for host."""
return os.getenv("MRACK_VM_LIFETIME")
return cached_get_vm_lifetime()

def validate_ownership_and_lifetime(self, host):
"""Validate if ownership and lifetime exists for host."""
Expand Down
4 changes: 2 additions & 2 deletions src/mrack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def ssh_to_host(
cmd = " ".join(cmd)

logger.debug(f"Running: {cmd}")
process = subprocess.Popen(cmd, **run_args)
std_out, std_err = process.communicate()
with subprocess.Popen(cmd, **run_args) as process:
std_out, std_err = process.communicate()

if not interactive:
for o_line in std_out.decode().splitlines():
Expand Down