From ebb5d34817863c0b78ce4246e956eecc25d55415 Mon Sep 17 00:00:00 2001 From: Etienne Wallet <116115319+EtienneWallet@users.noreply.github.com> Date: Sat, 23 Nov 2024 07:29:45 +0100 Subject: [PATCH] Feat/configurable save location (#77) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: allow setting a custom data path * feat: ignore custom mxops data * fix: avoid snap issues with default data path * docs: changelog * fix: typo * Bump version: 3.0.0-dev0 → 3.0.0-dev1 --------- Co-authored-by: github-actions <41898282+github-actions@users.noreply.github.com> --- .gitignore | 1 + docs/source/dev_documentation/changelog.md | 15 ++++++++++++--- mxops/config/config.py | 12 ++++++++++++ mxops/data/path.py | 13 ++++++++++--- mxops/resources/default_config.ini | 1 + pyproject.toml | 2 +- setup.cfg | 2 +- 7 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c4b62de..4944eae 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ tutorials/**/contract logs testnet/* temp/* +.mxops # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/docs/source/dev_documentation/changelog.md b/docs/source/dev_documentation/changelog.md index 9a2c7a4..2b6f219 100644 --- a/docs/source/dev_documentation/changelog.md +++ b/docs/source/dev_documentation/changelog.md @@ -2,24 +2,33 @@ ## Unreleased +### Fixed + +- Inconsistent data path due the snap packages + +### Added + +- the data save path of `MxOps` is now configurable through the config var `DATA_PATH` + + ### Changed - 🚨 BREAKING CHANGE 🚨 loop variables from `LoopStep` are now saved and accessed with the symbol `%` instead of `$` ## 2.2.0 - 2024-04-16 -## Added +### Added - `Scenario` clone command - Allowed `TransfersCheck` to dynamically evaluate sender and receiver by name -## Fixed +### Fixed - Updated the name 'local-testnet' to 'localnet' ## 2.1.0 - 2024-03-01 -## Added +### Added - ABI support for smart-contract - Added new examples for queries diff --git a/mxops/config/config.py b/mxops/config/config.py index 968f156..41fbade 100644 --- a/mxops/config/config.py +++ b/mxops/config/config.py @@ -42,6 +42,16 @@ def __init__(self, network: NetworkEnum, config_path: Optional[Path] = None): self.__network_config: Optional[NetworkConfig] = None + def set_network(self, network: NetworkEnum): + """ + Set the network enum + + :param network: network enum to set + :type network: NetworkEnum + """ + self.__network = network + self.__network_config = None + def get_network(self) -> NetworkEnum: """ Return the network of the config @@ -123,6 +133,8 @@ def set_network(cls, network: NetworkEnum): :type network: NetworkEnum """ cls.__network = network + if cls.__instance is not None: + cls.__instance.set_network(network) @staticmethod def find_config_path() -> Optional[Path]: diff --git a/mxops/data/path.py b/mxops/data/path.py index 5657e33..3664478 100644 --- a/mxops/data/path.py +++ b/mxops/data/path.py @@ -6,6 +6,7 @@ import os from pathlib import Path +import platform from typing import List from appdirs import AppDirs @@ -39,7 +40,8 @@ def get_scenario_full_name(scenario_name: str, checkpoint: str = "") -> str: def get_data_path() -> Path: """ Return the folder path where to store the data created by this project. - The folder will be created if it does not exists. + Is defined in first instance by the value 'DATA_PATH' from the config + If this value is 'None' or '', a folder will be created in the App Dir It uses the library appdirs to follow the conventions across multi OS(MAc, Linux, Windows) https://pypi.org/project/appdirs/ @@ -47,9 +49,14 @@ def get_data_path() -> Path: :return: path of the folder to use for data saving :rtype: Path """ + if platform.system() == "Linux": # handle snap issues + os.environ["XDG_DATA_HOME"] = os.path.expanduser("~/.local/share") + config = Config.get_config() + data_path_config = config.get("DATA_PATH") + if data_path_config not in ("None", ""): + return Path(data_path_config) app_dirs = AppDirs("mxops", "Catenscia") - data_path = Path(app_dirs.user_data_dir) - return data_path + return Path(app_dirs.user_data_dir) def initialize_data_folder(): diff --git a/mxops/resources/default_config.ini b/mxops/resources/default_config.ini index c479cd0..1772611 100644 --- a/mxops/resources/default_config.ini +++ b/mxops/resources/default_config.ini @@ -1,4 +1,5 @@ [DEFAULT] +DATA_PATH=None PROXY=http://localhost:7950 CHAIN=localnet TX_TIMEOUT=100 diff --git a/pyproject.toml b/pyproject.toml index ef2a98a..3e935d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "mxops" -version = "3.0.0-dev0" +version = "3.0.0-dev1" authors = [ {name="Etienne Wallet"}, ] diff --git a/setup.cfg b/setup.cfg index 96f6c4a..3a5c627 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.0.0-dev0 +current_version = 3.0.0-dev1 parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P\w+)(?P\d+))? serialize = {major}.{minor}.{patch}-{release}{build}