Skip to content

Commit

Permalink
Feat/configurable save location (#77)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
EtienneWallet and github-actions[bot] authored Nov 23, 2024
1 parent a637239 commit ebb5d34
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tutorials/**/contract
logs
testnet/*
temp/*
.mxops

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
15 changes: 12 additions & 3 deletions docs/source/dev_documentation/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions mxops/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
13 changes: 10 additions & 3 deletions mxops/data/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
from pathlib import Path
import platform
from typing import List

from appdirs import AppDirs
Expand Down Expand Up @@ -39,17 +40,23 @@ 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/
: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():
Expand Down
1 change: 1 addition & 0 deletions mxops/resources/default_config.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[DEFAULT]
DATA_PATH=None
PROXY=http://localhost:7950
CHAIN=localnet
TX_TIMEOUT=100
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.0.0-dev0
current_version = 3.0.0-dev1
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>\w+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down

0 comments on commit ebb5d34

Please sign in to comment.