Skip to content

Commit

Permalink
updated with latest changes in python_project_template
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaasRostock committed Jan 19, 2025
1 parent b35560b commit 57747b8
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 48 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ cython_debug/
# PyCharm
.idea

# modules
modules.txt

# VS Code
.vscode/*
!.vscode/settings.json
Expand All @@ -154,3 +151,8 @@ modules.txt
!.vscode/extensions.json
!.vscode/*.code-snippets

# Cmake generated files
CMakeUserPresets.json

# modules
modules.txt
2 changes: 2 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"sourcery.sourcery",
"njpwerner.autodocstring",
"editorconfig.editorconfig",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-renderers",
"ms-python.mypy-type-checker",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"python.analysis.inlayHints.functionReturnTypes": false,
"python.analysis.inlayHints.pytestParameters": true,
"python.terminal.executeInFileDir": true,
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvironment": false,
"python.terminal.activateEnvInCurrentTerminal": false,
"python.analysis.packageIndexDepths": [
{
Expand All @@ -47,6 +47,6 @@
],
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.reportingScope": "workspace",
"mypy-type-checker.preferDaemon": false,
"mypy-type-checker.preferDaemon": true,
"ruff.configurationPreference": "filesystemFirst",
}
81 changes: 59 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# farn-demo
demo cases to get started with [farn][farn_docs]
Demo cases to get started with [farn][farn_docs].


## Development Setup
Expand Down Expand Up @@ -69,36 +69,25 @@ C:\path\of\your\choice\osp\cosim\bin
### 5. Clone the repository
Clone the farn-demo repository into your local development directory:
```sh
git clone https://github.com/dnv-innersource/farn-demo path/to/your/dev/farn-demo
git clone https://github.com/dnv-opensource/farn-demo path/to/your/dev/farn-demo
```
Change into the project directory after cloning:
```sh
cd farn-demo
```

### 6. Install dependencies
Run `uv sync` to create a virtual environment and install all project dependencies into it:
```sh
uv sync
```
> **Note**: Using `--no-dev` will omit installing development dependencies.
### 7. (Optional) Install CUDA support
Run `uv sync` with option `--extra cuda` to in addition install torch with CUDA support:
```sh
uv sync --extra cuda
```

Alternatively, you can manually install torch with CUDA support.
_Note 1_: Do this preferably _after_ running `uv sync`. That way you ensure a virtual environment exists, which is a prerequisite before you install torch with CUDA support using below `uv pip install` command.

To manually install torch with CUDA support, generate a `uv pip install` command matching your local machine's operating system using the wizard on the official [PyTorch website](https://pytorch.org/get-started/locally/).
_Note_: As we use `uv` as package manager, remember to replace `pip` in the command generated by the wizard with `uv pip`.

If you are on Windows, the resulting `uv pip install` command will most likely look something like this:
```sh
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
```
> **Note**: `uv` will create a new virtual environment called `.venv` in the project root directory when running
> `uv sync` the first time. Optionally, you can create your own virtual environment using e.g. `uv venv`, before running
> `uv sync`.
_Hint:_ If you are unsure which cuda version to indicate in above `uv pip install .. /cuXXX` command, you can use the shell command `nvidia-smi` on your local system to find out the cuda version supported by the current graphics driver installed on your system. When then generating the `uv pip install` command with the wizard from the [PyTorch website](https://pytorch.org/get-started/locally/), select the cuda version that matches the major version of what your graphics driver supports (major version must match, minor version may deviate).


### 8. (Optional) Activate the virtual environment
### 7. (Optional) Activate the virtual environment
When using `uv`, there is in almost all cases no longer a need to manually activate the virtual environment. <br>
`uv` will find the `.venv` virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via `uv` inside your project folder structure:
```sh
Expand All @@ -117,6 +106,54 @@ To manually activate the virtual environment, run one of the "known" legacy comm
source .venv/bin/activate
```

### 8. Install pre-commit hooks
The `.pre-commit-config.yaml` file in the project root directory contains a configuration for pre-commit hooks.
To install the pre-commit hooks defined therein in your local git repository, run:
```sh
uv run pre-commit install
```

All pre-commit hooks configured in `.pre-commit-config.yaml` will now run each time you commit changes.

pre-commit can also manually be invoked, at anytime, using:
```sh
uv run pre-commit run --all-files
```

To skip the pre-commit validation on commits (e.g. when intentionally committing broken code), run:
```sh
uv run git commit -m <MSG> --no-verify
```

To update the hooks configured in `.pre-commit-config.yaml` to their newest versions, run:
```sh
uv run pre-commit autoupdate
```

## Meta

Copyright (c) 2024 [DNV](https://www.dnv.com) SE. All rights reserved.

Frank Lumpitzsch - [@LinkedIn](https://www.linkedin.com/in/frank-lumpitzsch-23013196/) - [email protected]

Claas Rostock - [@LinkedIn](https://www.linkedin.com/in/claasrostock/?locale=en_US) - [email protected]

Seunghyeon Yoo - [@LinkedIn](https://www.linkedin.com/in/seunghyeon-yoo-3625173b/) - [email protected]

Distributed under the MIT license. See [LICENSE](LICENSE.md) for more information.

[https://github.com/dnv-opensource/farn-demo](https://github.com/dnv-opensource/farn-demo)

## Contributing

1. Fork it (<https://github.com/dnv-opensource/farn-demo/fork>)
2. Create an issue in your GitHub repo
3. Create your branch based on the issue number and type (`git checkout -b issue-name`)
4. Evaluate and stage the changes you want to commit (`git add -i`)
5. Commit your changes (`git commit -am 'place a descriptive commit message here'`)
6. Push to the branch (`git push origin issue-name`)
7. Create a new Pull Request in GitHub


## farn Documentation on GitHub

Expand Down
6 changes: 3 additions & 3 deletions farn/hilbert_farnDict
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _layers
);
_includeBoundingBox true;
_numberOfSamples 20;
// upscale re-sampling: _numberOfSamples += _numberOfSamples-1
// upscale re-sampling: _numberOfSamples += _numberOfSamples-1
_iterationDepth 5;
}
_comment 'hilbert sampling demo case dividend / (minuend - subtrahend) and filtering avoiding div_by_zero';
Expand All @@ -60,9 +60,9 @@ _layers
);
resampleRun
(
'if not exist results (if not exist *.csv (cosim run OspSystemStructure.xml -b 0 -d 10) )'
'if not exist results (if not exist *.csv (cosim run OspSystemStructure.xml -b 0 -d 10) )'
);

runjob
(
.\winjob.cmd
Expand Down
67 changes: 58 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,78 @@
[project]
name = "farn-demo"
version = "0.4.0"
description = "examples of how to use the farn package."
version = "0.4.1"
description = "Demo cases to get started with farn."
readme = "README.md"
requires-python = ">= 3.10"
requires-python = ">= 3.10, < 3.14"
license = { file = "LICENSE" }
authors = [
{ name = "Frank Lumpitzsch", email = "[email protected]" },
{ name = "Claas Rostock", email = "[email protected]" },
{ name = "Seunghyeon Yoo", email = "[email protected]" },
]
maintainers = [
{ name = "Claas Rostock", email = "[email protected]" },
]
keywords = [
"farn",
"OSP",
"fmi",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"farn>=0.4.1",
]

[tool.uv]
dev-dependencies = [
[project.urls]
Homepage = "https://github.com/dnv-opensource/farn"
Documentation = "https://dnv-opensource.github.io/farn/README.html"
Repository = "https://github.com/dnv-opensource/farn.git"
Issues = "https://github.com/dnv-opensource/farn/issues"
Changelog = "https://github.com/dnv-opensource/farn/blob/main/CHANGELOG.md"


[dependency-groups]
dev = [
"ruff>=0.9.2",
"pyright>=1.1.392",
"mypy>=1.14",
"sourcery>=1.31",
"pre-commit>=4.0",
"pandas-stubs>=2.2",
"types-psutil>=6.1",
"types-lxml>=2024.12",
]

[tool.uv]
default-groups = [
"dev",
]
native-tls = true

[tool.mypy]
plugins = [
"numpy.typing.mypy_plugin",
]
mypy_path = "stubs"
files = [
"src",
"tests",
"demos",
"farn",
"importSystemStructure",
"ospCaseBuilder",
]
exclude = [
"^src/folder_to_be_excluded/",
Expand All @@ -39,18 +83,23 @@ disable_error_code = [
"import-untyped",
]


[tool.pyright]
stubPath = "stubs"
include = [
"farn",
"importSystemStructure",
"ospCaseBuilder",
]
exclude = [
"src/folder_to_be_excluded",
]

typeCheckingMode = "basic"
useLibraryCodeForTypes = true
reportMissingParameterType = "error"
reportUnknownParameterType = "warning"
reportUnknownMemberType = "warning" # consider to set to `false` if you work a lot with matplotlib and pandas, which are both not properly typed and known to trigger this warning
reportUnknownMemberType = "warning" # consider to set to `false` if you work a lot with matplotlib and pandas, which are both not properly typed and known to trigger this warning
reportMissingTypeArgument = "error"
reportPropertyTypeMismatch = "error"
reportFunctionMemberAccess = "warning"
Expand Down
21 changes: 12 additions & 9 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exclude = [
"dist",
"*cache",
"**/__pycache__",
"src/folder_to_be_excluded",
]
src = [
"farn",
Expand Down Expand Up @@ -34,8 +35,6 @@ ignore = [
"D213", # Multi-line docstring summary should start at the second line
"N999", # Invalid module name
# Ruff lint rules considered as too strict and hence ignored
"ANN101", # Missing type annotation for `self` argument in instance methods (NOTE: also listed as deprecated by Ruff)
"ANN102", # Missing type annotation for `cls` argument in class methods (NOTE: also listed as deprecated by Ruff)
"FIX002", # Line contains TODO, consider resolving the issue
"TD003", # Missing issue link on the line following a TODO
"S101", # Use of assert detected
Expand All @@ -45,6 +44,9 @@ ignore = [
"TRY003", # Avoid specifying long messages outside the exception class
"PLR1711", # Useless `return` statement at end of function
"G00", # Logging statement uses string formatting ('G00' covers all rules flagging string formatting in logging, e.g. G001, G002, etc.)
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
"PLW0603", # Using the global statement to update {name} is discouraged
"PYI041", # Use `float` instead of `int | float`

# Ruff lint rules recommended to keep enabled,
# but which are typical candidates you might have a need to ignore,
Expand All @@ -53,9 +55,9 @@ ignore = [
# -> Listed here for easy access and reference.
# (uncomment to ignore)
# "N803", # Argument name should be lowercase (NOTE: ignore to allow capital arguments (e.g X) in scientific code)
"N806", # Variable in function should be lowercase (NOTE: ignore to allow capital variables (e.g X) in scientific code)
# "TCH002", # Move third-party import into a type-checking block
# "TCH003", # Move standard library import into a type-checking block
# "N806", # Variable in function should be lowercase (NOTE: ignore to allow capital variables (e.g X) in scientific code)
# "TC002", # Move third-party import into a type-checking block
# "TC003", # Move standard library import into a type-checking block

# Ruff lint rules known to be in conflict with Ruff formatter.
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand Down Expand Up @@ -86,8 +88,6 @@ allowed-confusables = [
[lint.pep8-naming]
ignore-names = [
"test_*",
"setUp",
"tearDown",
]

[lint.pylint]
Expand All @@ -106,8 +106,9 @@ raises-require-match-for = [
[lint.per-file-ignores]
# `__init__.py` specific ignores
"__init__.py" = [
"F401", # {name} imported but unused (NOTE: ignored as imports in `__init__.py` files are almost never used inside the module, but are intended for namespaces)
"I001", # Import block is un-sorted or un-formatted
"F401", # {name} imported but unused (NOTE: ignored as imports in `__init__.py` files are almost never used inside the module, but are intended for namespaces)
"I001", # Import block is un-sorted or un-formatted
"PLC0414", # Import alias does not rename original package
]
# `tests` specific ignores
"tests/**/*" = [
Expand All @@ -118,6 +119,8 @@ raises-require-match-for = [
"PLR2004", # Magic value used in comparison
"ANN201", # Missing return type annotation for public function
"ANN202", # Missing return type annotation for private function
"ARG001", # Unused function argument: {name}
"ARG002", # Unused method argument: {name}
"INP001", # File is part of an implicit namespace package. Add an `__init__.py`. (NOTE: tests are not intended to be a module, __init__.py hence not required.)
"SLF001", # Private member accessed
"TRY004", # Prefer `TypeError` exception for invalid type
Expand Down

0 comments on commit 57747b8

Please sign in to comment.