Skip to content

Commit 7ae49c1

Browse files
Correct errors
1 parent c53e1b1 commit 7ae49c1

14 files changed

Lines changed: 64 additions & 65 deletions

File tree

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [3.7, 3.8, 3.9]
18+
python-version: [3.9 3.10 3.11]
1919

2020
steps:
2121
- uses: actions/checkout@v2

backend/api/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
from fastapi import FastAPI, Request
1818
from fastapi.middleware.cors import CORSMiddleware
19-
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
20-
from fastapi.staticfiles import StaticFiles
19+
from fastapi.responses import JSONResponse, RedirectResponse
2120

2221
from api.routes import convert, export, health, validate
2322
from shexstatements.parser_cache import ParserCache

backend/api/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
"""API models package."""
88

9-
from .requests import ConvertRequest, ValidateRequest, ExportRequest
9+
from .requests import ConvertRequest, ExportRequest, ValidateRequest
1010
from .responses import (
1111
ConvertResponse,
1212
ValidateResponse,

backend/api/routes/export.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ def _to_shacl(shapes: dict, original_shex: str) -> str:
286286
separator = ";" if i < len(props) - 1 else "."
287287
prop_name = prop["name"]
288288

289-
lines.append(f" sh:property [")
289+
lines.append(" sh:property [")
290290
lines.append(f" sh:path {prop_name} ;")
291291

292292
# Add datatype or node constraint
293293
if prop["type"] == "LITERAL":
294-
lines.append(f" sh:datatype xsd:string ;")
294+
lines.append(" sh:datatype xsd:string ;")
295295
elif prop["type"].startswith("xsd:"):
296296
lines.append(f" sh:datatype {prop['type']} ;")
297297
elif prop["type"].startswith("@<"):
@@ -301,12 +301,12 @@ def _to_shacl(shapes: dict, original_shex: str) -> str:
301301
# Add cardinality
302302
card = prop["cardinality"]
303303
if card == "+":
304-
lines.append(f" sh:minCount 1 ;")
304+
lines.append(" sh:minCount 1 ;")
305305
elif card == "?":
306-
lines.append(f" sh:maxCount 1 ;")
306+
lines.append(" sh:maxCount 1 ;")
307307
elif card == "":
308-
lines.append(f" sh:minCount 1 ;")
309-
lines.append(f" sh:maxCount 1 ;")
308+
lines.append(" sh:minCount 1 ;")
309+
lines.append(" sh:maxCount 1 ;")
310310

311311
lines.append(f" ] {separator}")
312312

backend/api/services/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pathlib import Path
1717
from typing import Literal
1818

19-
from api.models.responses import ConvertResponse, ParseError, Warning
19+
from api.models.responses import ConvertResponse, ParseError
2020
from shexstatements.errors import UnrecognizedCharacterError
2121
from shexstatements.shexfromcsv import CSV
2222

backend/shexstatements/cliargs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#
66

77
import argparse
8+
import runpy
9+
from os.path import splitext
10+
11+
import shexstatements.application
12+
from shexstatements.shexfromapplprofilecsv import ApplicationProfile
813
from shexstatements.shexfromcsv import CSV
9-
from shexstatements.shexjfromcsv import ShExJCSV
1014
from shexstatements.shexfromspreadsheet import Spreadsheet
11-
from shexstatements.shexfromapplprofilecsv import ApplicationProfile
12-
import shexstatements.application
13-
from os.path import splitext
14-
import setuptools
15-
import runpy
15+
from shexstatements.shexjfromcsv import ShExJCSV
1616

1717

1818
def handle_cli_arguments(arguments):

backend/shexstatements/errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def __init__(self, message):
1414
1515
Parameters
1616
----------
17-
self :
17+
self :
1818
The name to use.
1919
message: str
2020
error message
2121
"""
22-
super(UnrecognizedCharacterError, self).__init__(message)
22+
super().__init__(message)
2323
self.message = message
2424

2525

@@ -34,10 +34,10 @@ def __init__(self, message):
3434
3535
Parameters
3636
----------
37-
self :
37+
self :
3838
The name to use.
3939
message: str
4040
error message
4141
"""
42-
super(ParserError, self).__init__(message)
42+
super().__init__(message)
4343
self.message = message

backend/shexstatements/shexfromapplprofilecsv.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#
66

77
import csv
8-
import re
9-
from shexstatements.shexstatementsparser import ShExStatementLexerParser
8+
109
from shexstatements.shexfromcsv import CSV
1110

1211
"""
@@ -16,13 +15,13 @@
1615
DCAP term : ShExStatements
1716
==========================
1817
Entityname : Node name
19-
Property : Property
20-
PropertyLabel :
18+
Property : Property
19+
PropertyLabel :
2120
Mand : Cardinality
2221
Repeat : Cardinality
2322
Value : Value
2423
Valuetype : Value
25-
Annotation : Annotation
24+
Annotation : Annotation
2625
2726
"""
2827

@@ -40,7 +39,7 @@ def generate_shex_from_csv(filepath, delim=",", skip_header=False):
4039
filepath : str
4140
This parameter can contain either a file path of a CSV file or shexstatements in CSV format.
4241
delim : str
43-
a delimiter. Allowed values include ',', '|' and ';'
42+
a delimiter. Allowed values include ',', '|' and ';'
4443
skip_header : bool
4544
if the first line is a header, set this value to True. By default, the value is False.
4645
@@ -53,7 +52,7 @@ def generate_shex_from_csv(filepath, delim=",", skip_header=False):
5352
shexstatement = ""
5453
try:
5554
data = ""
56-
with open(filepath, 'r') as csvfile:
55+
with open(filepath) as csvfile:
5756
csvreader = csv.reader(csvfile, delimiter=delim)
5857
rowno = 0
5958
shapename = ""

backend/shexstatements/shexfromcsv.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import csv
88
import re
9-
from shexstatements.shexstatementsparser import ShExStatementLexerParser
109
from io import StringIO
1110

11+
from shexstatements.shexstatementsparser import ShExStatementLexerParser
12+
1213

1314
class CSV:
1415
"""
@@ -35,7 +36,7 @@ def generate_shex_from_data_string(data):
3536
lexerparser = ShExStatementLexerParser()
3637
lexerparser.build()
3738
lexerparser.buildparser()
38-
tokens = lexerparser.input(data)
39+
lexerparser.input(data)
3940
result = lexerparser.parse(data)
4041
shexstatement = result.generate_shex()
4142
except Exception as e:
@@ -52,7 +53,7 @@ def generate_shex_from_csv(filepath, delim=",", skip_header=False, filename=True
5253
filepath : str
5354
This parameter can contain either a file path of a CSV file or shexstatements in CSV format.
5455
delim : str
55-
a delimiter. Allowed values include ',', '|' and ';'
56+
a delimiter. Allowed values include ',', '|' and ';'
5657
skip_header : bool
5758
if the first line is a header, set this value to True. By default, the value is False.
5859
filename : bool
@@ -66,10 +67,10 @@ def generate_shex_from_csv(filepath, delim=",", skip_header=False, filename=True
6667
"""
6768
shexstatement = ""
6869
try:
69-
pattern = '^\s*$'
70+
pattern = r'^\s*$'
7071
data = ""
7172
if filename:
72-
csvfile = open(filepath, 'r')
73+
csvfile = open(filepath)
7374
csvreader = csv.reader(csvfile, delimiter=delim)
7475
else:
7576
# It's a multi-line string

backend/shexstatements/shexfromspreadsheet.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
# SPDX-License-Identifier: GPL-3.0-or-later
55
#
66

7+
from os import remove
8+
from os.path import splitext
9+
10+
from odf.opendocument import load
11+
from odf.table import TableCell, TableRow
712
from openpyxl import load_workbook
813
from xlrd import open_workbook
9-
from os.path import splitext
10-
from odf.opendocument import OpenDocumentSpreadsheet, load
11-
from odf.table import Table, TableCell, TableRow
14+
1215
from shexstatements.shexfromcsv import CSV
13-
from os import remove
1416

1517

1618
class Spreadsheet:
@@ -39,11 +41,10 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
3941
"""
4042
shexstatement = ""
4143
try:
42-
pattern = '^\s*$'
4344
data = ""
44-
filename, file_extension = splitext(filepath)
45+
_, file_extension = splitext(filepath)
4546

46-
if(file_extension in {".xlsx", ".xlsm", ".xltx", ".xltm"}):
47+
if file_extension in {".xlsx", ".xlsm", ".xltx", ".xltm"}:
4748
wb = None
4849
if stream is not None:
4950
with open("tmp" + filepath, "wb") as sf:
@@ -54,7 +55,7 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
5455
wb = load_workbook(filepath)
5556
for ws in wb.worksheets:
5657
for i in range(1, ws.max_row+1):
57-
line = list()
58+
line = []
5859
for j in range(1, ws.max_column+1):
5960
cell = ws.cell(row=i, column=j).value
6061
if cell is not None:
@@ -65,23 +66,23 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
6566
if stream is not None:
6667
remove(filepath)
6768

68-
elif(file_extension in {".xls"}):
69+
elif file_extension in {".xls"}:
6970
wb = None
7071
if stream is not None:
71-
#wb = open_workbook(file_contents=stream, encoding_override="cp1252")
72+
# wb = open_workbook(file_contents=stream, encoding_override="cp1252")
7273
wb = open_workbook(file_contents=stream)
7374
else:
7475
wb = open_workbook(filepath)
7576
for sheet in wb.sheets():
7677
for i in range(0, wb.sheets()[0].nrows):
77-
line = list()
78+
line = []
7879
for j in range(0, wb.sheets()[0].ncols):
7980
cell = sheet.cell(i, j).value
8081
if len(str(cell)) > 0:
8182
line.append(cell)
8283
data = data + "|".join(line) + "\n"
8384

84-
elif(file_extension in {".ods"}):
85+
elif file_extension in {".ods"}:
8586
wb = None
8687
if stream is not None:
8788
with open("tmp" + filepath, "wb") as sf:
@@ -94,7 +95,7 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
9495
rows = wb.getElementsByType(TableRow)
9596
for row in rows:
9697
cells = row.getElementsByType(TableCell)
97-
line = list()
98+
line = []
9899
for cell in cells:
99100
if len(str(cell)) > 0:
100101
line.append(str(cell))

0 commit comments

Comments
 (0)