Skip to content

Commit

Permalink
Migrate from legacy importlib.path to importlib.files (#28)
Browse files Browse the repository at this point in the history
* Migrate from legacy importlib.path to importlib.files

* Add Python 3.8 to package tests

* Make things backwards compatible to python 3.8
  • Loading branch information
fmauch authored Jun 2, 2024
1 parent 3a9c9b2 commit fab9d83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
python-version:
- '3.8'
- '3.10'
- '3.11'
- '3.12'
Expand Down
13 changes: 10 additions & 3 deletions src/robot_folders/helpers/config_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@
from __future__ import print_function
import os
import shutil
import sys
import yaml

from importlib import resources

import robot_folders.helpers.resources

XDG_CONFIG_HOME = os.getenv(
"XDG_CONFIG_HOME", os.path.expandvars(os.path.join("$HOME", ".config"))
)
FILENAME_USERCONFIG = os.path.join(XDG_CONFIG_HOME, "robot_folders.yaml")


def get_resource_path(filename):
if sys.version_info.major == 3 and sys.version_info.minor < 9:
return resources.path(".".join([__package__, "resources"]), filename)
return resources.files(robot_folders.helpers.resources).joinpath(filename)


class Userconfig(object):
"""Class for managing a userconfig"""

Expand All @@ -43,9 +52,7 @@ class Userconfig(object):
@classmethod
def init_class(cls):
"""Load the distribution config file"""
with resources.path(
".".join([__package__, "resources"]), "userconfig_distribute.yaml"
) as p:
with get_resource_path("userconfig_distribute.yaml") as p:
filename_distribute = p.as_posix()
file_content = p.read_text()
try:
Expand Down

0 comments on commit fab9d83

Please sign in to comment.