Skip to content

Commit

Permalink
🛠️ ci: Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquesebastiao committed Aug 29, 2024
1 parent d7498f3 commit 1276258
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 61 deletions.
54 changes: 41 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
on: [ push, pull_request ]
on: [push, pull_request]

name: CI
name: Test

jobs:
checks:
name: Checks
lint:
name: Code Quality
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.12 ]
check: [ ruff, blue, isort, pydocstyle, radon, mypy, bandit ]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
- name: Copy files from repo
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: '3.12'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install
- name: Run checks
- name: Run Ruff
run: poetry run task lint

- name: Run Radon
run: poetry run task radon

- name: Run MyPy
run: poetry run task mypy

security:
name: Code Security
runs-on: ubuntu-latest

steps:
- name: Copy files from repo
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Dependencies
run: |
task ${{ matrix.check }}
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install
- name: Run Bandit
run: poetry run task bandit
44 changes: 22 additions & 22 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
babel==2.14.0 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.2.2 ; python_version >= "3.11" and python_version < "4.0"
babel==2.16.0 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.7.4 ; python_version >= "3.11" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.11" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.11" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0"
ghp-import==2.1.0 ; python_version >= "3.11" and python_version < "4.0"
gitdb==4.0.11 ; python_version >= "3.11" and python_version < "4"
gitpython==3.1.43 ; python_version >= "3.11" and python_version < "4"
griffe==0.44.0 ; python_version >= "3.11" and python_version < "4.0"
idna==3.7 ; python_version >= "3.11" and python_version < "4.0"
jinja2==3.1.3 ; python_version >= "3.11" and python_version < "4.0"
markdown==3.6 ; python_version >= "3.11" and python_version < "4.0"
griffe==1.2.0 ; python_version >= "3.11" and python_version < "4.0"
idna==3.8 ; python_version >= "3.11" and python_version < "4.0"
jinja2==3.1.4 ; python_version >= "3.11" and python_version < "4.0"
markdown==3.7 ; python_version >= "3.11" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.11" and python_version < "4.0"
mergedeep==1.3.4 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-autorefs==1.0.1 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-autorefs==1.1.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-get-deps==0.2.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-git-authors-plugin==0.8.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-git-authors-plugin==0.9.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-git-committers-plugin-2==2.3.0 ; python_version >= "3.11" and python_version < "4"
mkdocs-git-revision-date-localized-plugin==1.2.5 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-git-revision-date-localized-plugin==1.2.7 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-macros-plugin==1.0.5 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-material-extensions==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-material==9.5.20 ; python_version >= "3.11" and python_version < "4.0"
mkdocs-material==9.5.33 ; python_version >= "3.11" and python_version < "4.0"
mkdocs==1.6.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocstrings-python==1.10.0 ; python_version >= "3.11" and python_version < "4.0"
mkdocstrings==0.25.0 ; python_version >= "3.11" and python_version < "4.0"
packaging==24.0 ; python_version >= "3.11" and python_version < "4.0"
paginate==0.5.6 ; python_version >= "3.11" and python_version < "4.0"
mkdocstrings-python==1.10.8 ; python_version >= "3.11" and python_version < "4.0"
mkdocstrings==0.25.2 ; python_version >= "3.11" and python_version < "4.0"
packaging==24.1 ; python_version >= "3.11" and python_version < "4.0"
paginate==0.5.7 ; python_version >= "3.11" and python_version < "4.0"
pathspec==0.12.1 ; python_version >= "3.11" and python_version < "4.0"
platformdirs==4.2.1 ; python_version >= "3.11" and python_version < "4.0"
pygments==2.17.2 ; python_version >= "3.11" and python_version < "4.0"
pymdown-extensions==10.8.1 ; python_version >= "3.11" and python_version < "4.0"
platformdirs==4.2.2 ; python_version >= "3.11" and python_version < "4.0"
pygments==2.18.0 ; python_version >= "3.11" and python_version < "4.0"
pymdown-extensions==10.9 ; python_version >= "3.11" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.11" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.11" and python_version < "4.0"
pyyaml-env-tag==0.1 ; python_version >= "3.11" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.11" and python_version < "4.0"
regex==2024.4.28 ; python_version >= "3.11" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.11" and python_version < "4.0"
pyyaml==6.0.2 ; python_version >= "3.11" and python_version < "4.0"
regex==2024.7.24 ; python_version >= "3.11" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.11" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.11" and python_version < "4.0"
smmap==5.0.1 ; python_version >= "3.11" and python_version < "4"
termcolor==2.4.0 ; python_version >= "3.11" and python_version < "4.0"
urllib3==2.2.1 ; python_version >= "3.11" and python_version < "4.0"
watchdog==4.0.0 ; python_version >= "3.11" and python_version < "4.0"
urllib3==2.2.2 ; python_version >= "3.11" and python_version < "4.0"
watchdog==5.0.0 ; python_version >= "3.11" and python_version < "4.0"
22 changes: 22 additions & 0 deletions netmikro/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ def __init__(
}
self._connection = MikrotikRouterOsSSH(**_auth)

def _cmd(self, command: str) -> str:
"""Runs a command in the router's terminal.
Args:
command (str): Command to be executed.
Returns:
str: Output of the command
Examples:
>>> router._cmd('/system identity print')
'name: Netmikro'
"""
# The `expect_string` parameter is a regex (format: [admin@mikrotik])
# necessary in case the router's identity is changed,
# there is no ReadTimeout error due to the output format changing,
# as it includes the router's identity
return self._connection.send_command(
command_string=command,
expect_string=rf'\[{self.username}@[^]]+\]',
)

def _get(self, command: str) -> str:
"""Method for returning string outputs.
Expand Down
2 changes: 1 addition & 1 deletion netmikro/modules/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def ip_port_set(self, service_name: str, port: int) -> None:
>>> router.ip_port_set('www', 8080)
"""
validate_port(port)
self.cmd(f'/ip service set {service_name} port={port}')
self._cmd(f'/ip service set {service_name} port={port}')
self.service[service_name].port = port
8 changes: 4 additions & 4 deletions netmikro/modules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def history_system_get(self) -> str:
U changed system note settings hick write
U ip service changed hick write
"""
return self.cmd('/system history print')
return self._cmd('/system history print')

def identity_set(self, new_identity: str):
"""Sets the router's identity.
Expand All @@ -218,7 +218,7 @@ def identity_set(self, new_identity: str):
>>> router.identity_set('new_identity')
"""
new_identity.strip()
self.cmd(f'/system identity set name={new_identity}')
self._cmd(f'/system identity set name={new_identity}')
self.identity = new_identity

def note_set(self, note: str, show_at_login: bool = False):
Expand All @@ -232,7 +232,7 @@ def note_set(self, note: str, show_at_login: bool = False):
>>> router.note_set('new_note', True)
"""
show_at_login_command = 'yes' if show_at_login else 'no'
self.cmd(
self._cmd(
f'/system note set note="{note}" show-at-login={show_at_login_command}'
)

Expand Down Expand Up @@ -317,7 +317,7 @@ def ntp_client_set(
raise InvalidNtpMode(f'Invalid mode: {mode}')
vrf = vrf.lower().strip()

self.cmd(
self._cmd(
f'/system ntp client set '
f'enabled={enabled_command} mode={mode} servers={servers_command} vrf={vrf}'
)
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pytest = "^8.3.2"
bandit = {extras = ["toml"], version = "^1.7.9"}
radon = {extras = ["toml"], version = "^6.0.1"}
mypy = "^1.11.2"
pydocstyle = "^6.3.0"
ruff = "^0.6.2"

[tool.poetry.group.doc.dependencies]
Expand Down Expand Up @@ -98,15 +97,11 @@ convention = "google"
mypy = "mypy -p netmikro"
radon = "radon cc ./netmikro -a -na"
bandit = "bandit -r ./netmikro"
pydocstyle = "pydocstyle ./netmikro --count --convention=google --add-ignore=D100,D104,D105,D107"
lint = "ruff check .; ruff check . --diff"
format = 'ruff format .; ruff check . --fix'
docs = "mkdocs serve"
quality = "task mypy && task radon && task pydocstyle"
doc = "mkdocs serve"
badge = "coverage-badge -o docs/assets/coverage.svg -f"
pre_test = "task lint"
test = "pytest -s -x --cov=netmikro -vv"
post_test = "coverage html"
export-requirements = "rm requirements.txt && poetry export -f requirements.txt --output requirements.txt --without-hashes"
export-requirements-doc = "poetry export -f requirements.txt --output docs/requirements.txt --without-hashes --only doc"
ready = "task lint && task quality && task bandit && pytest -s -x --cov=netmikro -vv && coverage html && task export-requirements && task export-requirements-doc && task badge"
15 changes: 0 additions & 15 deletions requirements.txt

This file was deleted.

0 comments on commit 1276258

Please sign in to comment.