Skip to content

Commit

Permalink
Merge pull request #2 from FOSSEE/data_convertor
Browse files Browse the repository at this point in the history
Implemented write functions to write pyvnt trees to a file
  • Loading branch information
rajdeepadak authored May 25, 2024
2 parents 30c82e5 + 4831a19 commit 52ca0fd
Show file tree
Hide file tree
Showing 31 changed files with 337 additions and 35 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install dependencies and build package
run: |
python -m pip install --upgrade pip
python -m pip install pytest anytree setuptools wheel
python setup.py sdist bdist_wheel
python setup.py install
python -m pip install pytest anytree setuptools wheel build
python -m build
pip install dist/*.whl
- name: Test with pytest
run: |
pytest -v
pytest -v tests/
170 changes: 169 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,172 @@
env
build/
dist/
pyvnt.egg-info
pyvnt.egg-info
manual_tests/*
**/__pycache__/*
.vscode


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.pyc
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.associations": {
"dictionaryFile.C": "cpp"
},
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
Binary file not shown.
18 changes: 10 additions & 8 deletions manual_tests/test_pyvnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# set up automated tests for CI/CD in github

# test for KeyData and Foam classes
'''

key1 = KeyData('solver', prop1, prop2)
print(key1.giveVal())
head = Foam("test_head",None, None)
Expand All @@ -19,19 +19,21 @@
child1 = Foam('test_child', head, None)
child2 = Foam('test_child2', child1, None, key1)
child3 = Foam('test_child3', child1, None, key1)
'''


# Display tests
'''
print(head)

# print(head)
showTree(head)
print(RenderTree(child1).by_attr())
'''
# print(RenderTree(child1).by_attr())


# Test for Keydata class singularily

key1 = KeyData('solver', prop1)
print(key1)
# key1 = KeyData('solver', prop1)
# print(key1)

writeTo(head, 'testFile.txt')



10 changes: 5 additions & 5 deletions manual_tests/treeTest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .pyvnt.DictionaryElement.foamDS import *
from .pyvnt.DictionaryElement.keyData import *
from .pyvnt.Reference.basic import *
from pyvnt import *

prop1 = EnumProp('val1', items={'PCG', 'PBiCG', 'PBiCGStab'}, default='PCG')

key1 = KeyData('solver', prop1)

head = Foam(name="test_head", children = [key1])
head = Foam("test_head", None, None, key1)

head.dispTree()
# head.dispTree()

showTree(head)
Empty file.
13 changes: 13 additions & 0 deletions pyvnt/Converter/Writer/writer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pyvnt.DictionaryElement import *

def writeTo(root, path):
'''
Function to write the dictionary object to the file
Parameters:
Foam: Dictionary object to be written
path: Path to the file where the dictionary object is to be written
'''
with open(path, "w") as file:
root.writeOut(file)
Empty file added pyvnt/Converter/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
37 changes: 37 additions & 0 deletions pyvnt/DictionaryElement/foamDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Type
from pyvnt.DictionaryElement.keyData import KeyData
from pyvnt.Reference.errorClasses import *
from pyvnt.utils.makeIndent import makeIndent

'''
Criteria for classes:
Expand Down Expand Up @@ -134,5 +135,41 @@ def reorderData(self, data: KeyData, pos: int):
self.data.insert(data, pos)
except:
raise AttributeError(f"{data.name} does not exist in this node")

def writeOut(self, file, indent = 0):
'''
Function to write the current node to the file
'''

'''
if self.parent == None:
# TODO: Add the header to the file
pass
else:
file.write(f"{self.name}\n")
file.write("{\n")
for d in self.data:
file.write("\t")
d.writeOut(file)
file.write("}\n")
'''

makeIndent(file, indent)
file.write(f"{self.name}\n")

makeIndent(file, indent)
file.write("{\n")

for d in self.data:
d.writeOut(file, indent+1)

# makeIndent(file, indent)

for child in self.children:
child.writeOut(file, indent+1)
file.write("\n")

makeIndent(file, indent)
file.write("}\n")


Loading

0 comments on commit 52ca0fd

Please sign in to comment.