Skip to content

Commit 30e5bf8

Browse files
authored
Merge pull request #1 from Virtomize/ftaubert/pylint
Create pylint.yml
2 parents 3431346 + b7e9952 commit 30e5bf8

9 files changed

Lines changed: 82 additions & 32 deletions

File tree

.github/workflows/pylint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10"]
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
- name: Analysing the code with pylint
22+
run: |
23+
pylint $(git ls-files '*.py')

BUILD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Build
22
To build this package:
33
1) run `python setup.py sdist bdist_wheel`
4-
2) get a pypi token from our [PyPi](pypi.org) account
4+
2) get a pypi token from our [PyPi](http://pypi.org) account
55
3) Add the token to `$HOME/.pypirc` under `[pypi]` (follow instructions from the pypi webpage)
66
4) run `python -m twine upload --repository pypi dist/*`
7-
(run `python -m twine upload --repository testpypi dist/*` to publish a tests to [Test.PyPi](test.pypi.org))
7+
(run `python -m twine upload --repository testpypi dist/*` to publish a tests to [Test.PyPi](http://test.pypi.org))

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ $ git push origin example-branch
100100
### 7. Open the Pull Request
101101

102102
From within GitHub, by opening a new Pull Request will present you with a template that should be filled out.
103-
Please fill out all details, feel free to skip not nessesary parts or if you're not sure what to fill in.
103+
Please fill out all details, feel free to skip not necessary parts or if you're not sure what to fill in.
104104

105-
Once opened, the Pull Request is opend and will be reviewed.
105+
Once opened, the Pull Request is opened and will be reviewed.
106106

107107
### 8. Updates and discussion
108108

109109
While reviewing you will probably get some feedback or requests for changes to your Pull Request. This is normal and a necessary part of the process to evaluate the changes and there correctness.
110110

111-
To make changes to an existsing Pull Request, make the changes to your local branch.
111+
To make changes to an existing Pull Request, make the changes to your local branch.
112112
Add a new commit including those changes and push them to your fork.
113113
The Pull Requests will be automatically updated by GitHub.
114114

example.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
#import src.uiipythonapi as uii
1+
""" Example for the usage of the UII python API package """
22
import uiipythonapi as uii
33

44
api = uii.Client("token here")
55
packageList, err = api.read_package_list("debian", "10", "x86_64")
66
print("Number of known packages for Debian 10: " + str(len(packageList)))
77

8-
def dhcp_network(domain: str = "", ipnet: str = "", gateway: str = "", dns: str = "", nointernet: bool = False):
8+
9+
def dhcp_network():
10+
""" Example of how to define a dynamic network """
911
return {
1012
"dhcp": True,
11-
# "domain": domain,
12-
# "ipnet": ipnet,
13-
# "gateway": gateway,
14-
# "dns": dns,
1513
"nointernet": False,
1614
}
1715

18-
def static_network(domain: str = "", ipnet: str = "", gateway: str = "", dns: str = "", nointernet: bool = False):
16+
17+
def static_network(domain: str = "",
18+
ip_net: str = "",
19+
gateway: str = "",
20+
dns: str = "",
21+
no_internet: bool = False):
22+
""" Example of how to define a static network """
1923
return {
2024
"dhcp": False,
2125
"domain": domain,
22-
"ipnet": ipnet,
26+
"ipnet": ip_net,
2327
"gateway": gateway,
2428
"dns": dns,
25-
"nointernet": nointernet,
29+
"nointernet": no_internet,
2630
}
2731

28-
err = api.build("debian10.iso", "debian", "10", "x86_64", "horst", [dhcp_network()])
29-
print("Errors: " + str(err))
32+
33+
ERROR = api.build("debian10.iso", "debian", "10", "x86_64", "horst", [dhcp_network()])
34+
print("Errors: " + str(ERROR))

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
pylint

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import os
1+
"""
2+
Configuration for building the pip package
3+
"""
24

35
from setuptools import setup
46

@@ -11,12 +13,12 @@
1113
url='https://github.com/virtomize/uii-python-api',
1214
author='Virtomize GmbH',
1315
author_email='api@virtomize.com',
14-
description="A client implemenation for Virtomize Unattended Install Images API",
16+
description="A client implementation for Virtomize Unattended Install Images API",
1517
long_description=long_description,
1618
long_description_content_type="text/markdown",
1719
license='BSD 2-clause',
1820
packages=['uiipythonapi'],
19-
package_dir={'uiipythonapi': 'src/uiipythonapi'},
21+
package_dir={'uiipythonapi': './uiipythonapi'},
2022
install_requires=[
2123
'requests'
2224
],

src/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
"""
2+
Python API package
3+
"""
4+
15
__version__ = "0.0.1"
26

37
from .client import Client
4-
5-
Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
"""
2+
Client implementation for the Virtomize UII API.
3+
"""
4+
# pylint: disable=too-many-arguments,broad-except
15
import requests
26

3-
base_url = "https://api.virtomize.com/uii/"
7+
BASE_URL = "https://api.virtomize.com/uii/"
8+
49

510
class Client:
11+
""" Client to interact with the Virtomize UII API. """
612
def __init__(self, token):
713
self.token = token
814

915
def read_os_list(self):
10-
endpoint = base_url + "oslist"
16+
""" Read a list of all supported operating systems """
17+
endpoint = BASE_URL + "oslist"
1118
headers = self.__default_header()
1219

1320
response = requests.get(endpoint, headers=headers, verify=False)
@@ -21,7 +28,8 @@ def read_os_list(self):
2128
return [], "no data returned"
2229

2330
def read_package_list(self, dist: str, version: str, arch: str):
24-
endpoint = base_url + "packages"
31+
""" Read a list of all available packages for an operating system """
32+
endpoint = BASE_URL + "packages"
2533
headers = self.__default_header()
2634
data = {
2735
"arch": arch,
@@ -40,8 +48,15 @@ def read_package_list(self, dist: str, version: str, arch: str):
4048

4149
return [], "no data returned"
4250

43-
def build(self, destination: str, dist: str, version: str, arch: str, hostname: str, networks) -> str:
44-
endpoint = base_url + "images"
51+
def build(self,
52+
destination: str,
53+
dist: str,
54+
version: str,
55+
arch: str,
56+
hostname: str,
57+
networks) -> str:
58+
""" Build an ISO """
59+
endpoint = BASE_URL + "images"
4560
headers = self.__default_header()
4661
data = {
4762
"arch": arch,
@@ -55,10 +70,10 @@ def build(self, destination: str, dist: str, version: str, arch: str, hostname:
5570
if not response.status_code == 200:
5671
return parse_error(response)
5772

58-
with open(destination, "wb") as f:
73+
with open(destination, "wb") as iso_file:
5974
for chunk in response.iter_content(chunk_size=16 * 1024):
60-
f.write(chunk)
61-
return
75+
iso_file.write(chunk)
76+
return ""
6277

6378
def __default_header(self):
6479
return {
@@ -67,12 +82,13 @@ def __default_header(self):
6782
}
6883

6984
def parse_error(response) -> str:
85+
""" Parse an error returned by the API """
7086
try:
7187
response_json = response.json()
7288
if "errors" in response_json:
7389
errors = response_json["errors"]
7490
return ", ".join(errors)
75-
except:
76-
pass
91+
except Exception as ex:
92+
print(f'Error calling API: {ex}')
7793

78-
return "request was not successful and returned \"" + str(response.content) + "\""
94+
return "request was not successful and returned \"" + str(response.content) + "\""

0 commit comments

Comments
 (0)