Skip to content

Commit 13f9e54

Browse files
authored
Update illegals (#70)
* fix illegals logic * fix ruff * fix dot
1 parent cd86b97 commit 13f9e54

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

pyinfraformat/core/core.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,6 @@ def add_survey(self, survey):
612612
"""Add survey information to object."""
613613
self.survey.add(survey)
614614

615-
def _add_illegal(self, illegal):
616-
"""Add illegal lines to object."""
617-
self._illegal.add(illegal)
618-
619615
def plot(self, output="figure", figsize=(4, 4)):
620616
"""
621617
Plot a diagram of a sounding with matplotlib.
@@ -660,17 +656,13 @@ def get_comments_list(self):
660656
"""Get fileheader as a dict."""
661657
return self.inline_comment.data
662658

663-
def get_illegals_list(self):
664-
"""Get fileheader as a dict."""
665-
return self._illegal.data
666-
667659
def get_dict(self):
668660
"""Get survey data, hole header, fileheader, comments and illegals as list of dicts."""
669661
d_header = self.get_header_dict()
670662
data_list = self.get_data_list()
671663
d_fileheader = self.get_fileheader_dict()
672664
comment_list = self.get_comments_list()
673-
illegals_list = self.get_illegals_list()
665+
illegals_list = self.illegals
674666
return {
675667
"header": d_header,
676668
"fileheader": d_fileheader,

pyinfraformat/core/io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ def write_body(hole, f, comments=True, illegal=False, body_spacer=None, body_spa
457457

458458
# Gather illegal lines
459459
if illegal:
460-
for linenumber, line_string in hole._illegal.data:
460+
illegals_dict = {
461+
item["linenumber"]: item["line_highlighted"] + " # " + item["error"]
462+
for item in hole.illegals
463+
}
464+
for linenumber, line_string in illegals_dict.items():
461465
if int(linenumber) not in body_text:
462466
body_text[int(line_dict["linenumber"])] = line_string
463467
else:

setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
"""Python setup information."""
22

3-
import codecs
43
import os
54
import re
5+
from pathlib import Path
66

77
from setuptools import find_packages, setup
88

9-
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
10-
REQUIREMENTS_FILE = os.path.join(PROJECT_ROOT, "requirements.txt")
11-
README_FILE = os.path.join(PROJECT_ROOT, "README.md")
12-
VERSION_FILE = os.path.join(PROJECT_ROOT, "pyinfraformat", "__init__.py")
9+
PROJECT_ROOT = Path(os.path.realpath(__file__)).parent
10+
REQUIREMENTS_FILE = PROJECT_ROOT / "requirements.txt"
11+
README_FILE = PROJECT_ROOT / "README.md"
12+
VERSION_FILE = PROJECT_ROOT / "pyinfraformat" / "__init__.py"
1313

1414

1515
def get_requirements():
1616
"""Read contents from requirements.txt."""
17-
with codecs.open(REQUIREMENTS_FILE) as buff:
17+
with open(REQUIREMENTS_FILE, encoding="utf-8") as buff:
1818
return buff.read().splitlines()
1919

2020

2121
def get_long_description():
2222
"""Read contents from README.md."""
23-
with codecs.open(README_FILE, "rt") as buff:
23+
with open(README_FILE, encoding="utf-8") as buff:
2424
return buff.read()
2525

2626

2727
def get_version():
2828
"""Read version info from __init__.py."""
29-
lines = open(VERSION_FILE).readlines()
29+
with open(VERSION_FILE, encoding="utf-8") as buff:
30+
lines = buff.readlines()
3031
version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]"
3132
for line in lines:
3233
version_search = re.search(version_regex, line, re.MULTILINE)

0 commit comments

Comments
 (0)