Skip to content

Commit

Permalink
Merge pull request #59 from BishoyHanyRaafat/change_data_dir
Browse files Browse the repository at this point in the history
refactor: reorganize pieces data directory in the com.pieces.os
  • Loading branch information
mark-at-pieces authored Mar 19, 2024
2 parents cd41c9e + 534828d commit 6d063c7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,3 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# Data dir
# Ignore everything in the 'src/pieces/data/' directory
src/pieces/data/*

# Except for the 'init' file
!src/pieces/data/init
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
pieces_os_client = "1.2.7"
prompt-toolkit = "^3.0.43"
rich = "^13.7.1"
platformdirs = "^4.2.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
Expand Down
9 changes: 5 additions & 4 deletions src/pieces/api/config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import pieces_os_client as pos_client
import importlib.resources
from pathlib import Path
import platform
import os
from platformdirs import user_data_dir

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # same as used in django!

# Define the directory path

pieces_data_dir = importlib.resources.files(
"pieces.data"
) # our static packaged data files directory

# Check if the directory exists, if not, create it
pieces_data_dir = user_data_dir(appauthor="pieces", appname="cli-agent",ensure_exists=True)

applications_db_path = Path(
pieces_data_dir,"applications.db"
Expand Down
2 changes: 1 addition & 1 deletion src/pieces/api/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def categorize_os():
def get_version() -> Optional[str]:
"""Get pieces os version return None if there is a problem"""
try:
version = pos_client.WellKnownApi(api_client).get_well_known_health()
version = pos_client.WellKnownApi(api_client).get_well_known_version()
return version
except: # There is a problem in the startup
return None
Expand Down
Empty file removed src/pieces/data/__init__.py
Empty file.

0 comments on commit 6d063c7

Please sign in to comment.