Skip to content

Commit

Permalink
Merge pull request #40 from dnv-opensource/feature/python-sdk
Browse files Browse the repository at this point in the history
Start of python sdk, fixed with ruff, all functionality up till GmodPath implemented
  • Loading branch information
anderf2706 authored Aug 13, 2024
2 parents 4b8a260 + fbfb01f commit ed770f8
Show file tree
Hide file tree
Showing 36 changed files with 3,449 additions and 1 deletion.
78 changes: 78 additions & 0 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Python Package

on:
push:
branches: [main]
paths: ["python/**", ".github/workflows/build-python.yml"]
pull_request:
branches: [main]
paths: ["python/**", ".github/workflows/build-python.yml"]
workflow_dispatch:

env:
CI_BUILD: true

jobs:
build:
name: Build, test, and publish
runs-on: ubuntu-latest

steps:
- name: Checkout entire repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -r python/requirements.txt
- name: Copy resources folder into python/vista_sdk
run: |
cp -r ./resources ./python/vista_sdk/resources
- name: Generate VisVersion script
env:
PYTHONPATH: ${{ github.workspace }}/python # Set PYTHONPATH to the python directory
run: |
python python/vista_sdk/SourceGenerator/VisVersionsGenerator.py --resources-dir resources
- name: Run tests
env:
PYTHONPATH: ${{ github.workspace }}/python # Ensure PYTHONPATH is set for tests as well
run: |
pytest python/tests
- name: Move Python directory to root
run: |
mv python/* ./
mv python/.[!.]* ./
rm -rf python
- name: Set up Python again
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies for building
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build package
if: success()
run: |
python setup.py sdist bdist_wheel --version=${{ github.run_number }}
- name: Publish package
if: success()
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
twine upload dist/* --verbose
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ lerna-debug.log
# System Files
.DS_Store
Thumbs.db

.vs

# Python test files
*.pytest_cache/
17 changes: 16 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,20 @@
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "csharpier.csharpier-vscode"
}
},
"python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "basic",
"python.testing.unittestArgs": [
"-v",
"-s",
"./python",
"-p",
"test_*.py"
],
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"python.testing.pytestArgs": [

]
}
12 changes: 12 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore compiled Python bytecode files
*.pyc

# Ignore Python cache directories
__pycache__/

# Ignore environment-specific settings
.env

# Ignore editor-specific files
.idea/
*.sublime-*
1 change: 1 addition & 0 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include python/vista_sdk/resources *
5 changes: 5 additions & 0 deletions python/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
import sys

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(ROOT_DIR)
4 changes: 4 additions & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cachetools==5.3.3
parameterized==0.9.0
pydantic==2.7.4
python-dotenv==1.0.1
42 changes: 42 additions & 0 deletions python/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Consider packages in the src directory as first-party code
src = ["src"]
# Run ruff on Notebooks as well
extend-include = ["*.ipynb"]

[lint.per-file-ignores]
# Allow the use of assert in tests
"tests/*" = ["S101"]

[lint]
select = [
"F", # Pyflakes
"E", # pycodestyle
"W", # pycodestyle
"I", # isort
"ICN", # flake8-import-conventions
# "D", # pydocstyle
# "N", # pep8-naming
# "A", # flake8-builtins
"B", # flake8-bugbear
"S", # flake8-bandit
"SIM", # flake8-simplify
# "C4", # flake8-comprehensions
# "DTZ", # flake8-datetimez
# "FA", # flake8-future-annotations
# "ISC", # flake8-implicit-str-concat
# "PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "PTH", # flake8-use-pathlib
# "UP", # pyupgrade
# "RUF", # Ruff-specific rules
# "PD", # pandas-vet
# # "FAST", # FastAPI
]
ignore = [
"ISC001", # may cause conflicts when used with the formatter
]

[lint.pydocstyle]
convention = "google"
37 changes: 37 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys

from setuptools import find_packages, setup # type: ignore

# Default version number


version = "0.1.0-preview-"

if len(sys.argv) > 1:
for arg in sys.argv:
if arg.startswith("--version="):
version += arg.split("=")[1]
sys.argv.remove(arg)

setup(
name="vista-sdk",
version=version,
author="Anders Fredriksen",
author_email="[email protected]",
description="SDKs and tools relating to DNVs Vessel Information Structure (VIS),"
"ISO 19847, ISO 19848 standards",
url="https://github.com/dnv-opensource/vista-sdk",
license="MIT",
packages=find_packages(),
include_package_data=True,
package_data={
"vista_sdk": ["resources/*"],
},
install_requires=["cachetools>=5.3.3", "parameterized>=0.9.0", "pydantic>=2.7.1"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.8",
)
Empty file added python/tests/__init__.py
Empty file.
Loading

0 comments on commit ed770f8

Please sign in to comment.