Skip to content

Commit

Permalink
Vanish dss content (#95)
Browse files Browse the repository at this point in the history
* Update version

* Adding flake8

* Adding Multiline feature

* Split the test and publish
  • Loading branch information
felipemarkson authored Apr 28, 2022
1 parent e4f9243 commit 83c0fdc
Show file tree
Hide file tree
Showing 15 changed files with 2,129 additions and 879 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish
on:
push:
tags:
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.10
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,3 @@ jobs:

- name: Run Tests
run: poetry run python -m unittest

- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
73 changes: 68 additions & 5 deletions dssdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,61 @@
from os import path as pathfunc
from typing import Iterable, List

__version__ = "0.1.2"
__version__ = "0.1.6"


def _redirect_handler(path) -> List[str]:
"""
If a redirect command is found, call the function recursively
Args:
path: The path to the file.
acc: A buffer to store the commands.
Returns:
True if the file has a solve command.
"""
with open(path, "rt") as file:
lines = file.readlines()

commands = _remove_comments_dss(lines)
no_redirect_cmds = []

for line in commands:
if "redirect" in line.lower().strip():
cmd = " ".join(line.split(" ")[1:]).strip()
head = pathfunc.split(path)[0]
no_redirect_cmds += _redirect_handler(pathfunc.join(head, cmd))
else:
no_redirect_cmds.append(line)

return no_redirect_cmds


def _remove_comments_dss(list_cmd: List[str]) -> List[str]:

vanished: List[str] = []
in_a_comment = False
for cmd in list_cmd:
if cmd.strip().startswith("/*"):
in_a_comment = True
continue
elif cmd.strip().endswith("*/"):
in_a_comment = False
continue
if in_a_comment:
continue
elif cmd.strip().startswith("!"):
continue
elif cmd.strip().startswith("//"):
continue
elif len(cmd.strip()) == 0:
continue

if cmd.strip().startswith("~"):
vanished[-1] += cmd.strip()[1:].split("!")[0]
else:
vanished.append(cmd.strip())

return vanished


class SystemClass:
Expand All @@ -20,8 +74,7 @@ def __init__(self, *, path: str, kV: Iterable[float], loadmult: float = 1):
loadmult (float, optional): The load multiplier. See ```loadmult``` in [OpenDSS User Manual](http://svn.code.sf.net/p/electricdss/code/trunk/Distrib/Doc/> OpenDSSManual.pdf).
""" # noqa: E501

with open(path, "rt") as file:
self._dsscontent = file.read().splitlines()
self._dsscontent = _redirect_handler(path)

self.__path = path
self.__folder = pathfunc.split(path)[0]
Expand Down Expand Up @@ -118,10 +171,20 @@ def init_sys(self):
self.dss.Basic.ClearAll()
if self.__folder != "":
chdir(self.__folder)
list(map(self.run_command, self._dsscontent,))
list(
map(
self.run_command,
self._dsscontent,
)
)
chdir(directory)
else:
list(map(self.run_command, self._dsscontent,))
list(
map(
self.run_command,
self._dsscontent,
)
)

self.run_command(f"Set voltagebases={self.__kV}")
self.run_command("calcv")
Expand Down
5 changes: 1 addition & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ theme:
name: material
language: en
features:
- instant
- navigation.instant

markdown_extensions:
- codehilite



plugins:
- search
- mkdocstrings:
Expand All @@ -44,7 +42,6 @@ nav:

- License: LICENSE.md


extra_css:
- css/termynal.css
- css/custom.css
Expand Down
Loading

0 comments on commit 83c0fdc

Please sign in to comment.