Skip to content

Commit 84b847d

Browse files
authored
Merge pull request #1 from bcmi-labs/module_project_restructure
Module - structure aligninment with python requirements
2 parents 98aac1c + 05fa659 commit 84b847d

32 files changed

+214
-106
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,21 @@
22

33
To build package:
44
* pip install build
5-
* python -m build
5+
* python -m build
6+
7+
# Development
8+
9+
For development purposes, install module a "editable install"
10+
```sh
11+
pip install -e ".[dev]"
12+
```
13+
14+
All tests must be added in tests/ folder. To execute tests, run command:
15+
```sh
16+
pytest -vs tests
17+
```
18+
19+
or, to execute a single test
20+
```sh
21+
pytest -vs tests\test_execute_function.py
22+
```

appslab_modules/steps/db_storage/test_database_storage.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

appslab_modules/steps/execute_function/test_execute_function.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

appslab_modules/steps/json_parser/test_json_parser.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

appslab_modules/steps/log/__init__.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

appslab_modules/steps/log/module_config.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ dependencies = [
2222
]
2323

2424
[project.optional-dependencies]
25+
dev = [
26+
"pytest",
27+
]
2528
db_storage = [
2629
"influxdb_client>=1.48.0",
2730
]
@@ -37,8 +40,8 @@ all = [
3740
"Homepage" = "https://github.com/bcmi-labs/appslab-python-modules"
3841

3942
[tool.setuptools.packages.find]
40-
where = ["."]
41-
include = ["appslab_modules*"]
43+
where = ["src"]
44+
include = ["*"]
4245

4346
[tool.setuptools.package-data]
4447
"*" = ["*.yaml", "*.md"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .module import get_module_config_file, get_module_compose_file, get_module_linked_resource_file

src/appslab_modules/core/module.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
3+
config_file_name = "module_config.yaml"
4+
compose_config_file_name = "module_compose.yaml"
5+
6+
def get_module_config_file(cls) -> str|None:
7+
"""Gets the full path of the module_config.yaml file."""
8+
return get_module_linked_resource_file(cls, config_file_name)
9+
10+
def get_module_compose_file(cls) -> str|None:
11+
"""Gets the full path of the module_compose.yaml file, if present."""
12+
return get_module_linked_resource_file(cls, compose_config_file_name)
13+
14+
def get_module_linked_resource_file(cls, resource_file_name) -> str|None:
15+
"""Gets the full path to a config file in the directory containing a class."""
16+
try:
17+
module = cls.__module__
18+
if module == '__main__':
19+
directory_path = os.path.dirname(os.path.abspath(__file__))
20+
else:
21+
module_obj = __import__(module, fromlist=['__file__'])
22+
file_path = os.path.abspath(module_obj.__file__)
23+
directory_path = os.path.dirname(file_path)
24+
25+
requested_path = os.path.join(directory_path, resource_file_name)
26+
if os.path.exists(requested_path):
27+
return requested_path
28+
else:
29+
return None
30+
except AttributeError:
31+
# Handle built-in classes or other cases where __file__ is not available
32+
return None
33+
except ModuleNotFoundError:
34+
return None
File renamed without changes.

0 commit comments

Comments
 (0)