Skip to content

Commit

Permalink
Enable windows tests again (#528)
Browse files Browse the repository at this point in the history
* Resolve XDG paths in a OS independent way (using pathlib.Path)
* Create directories for config file if it does not exist.
* Workaround for removal of tmp XDG files on windows.
  shutil.rmtree sometimes fails one windows, seems to be UAC related.
  • Loading branch information
halfow authored and olofk committed Nov 17, 2023
1 parent dba68ff commit b72d3ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
8 changes: 5 additions & 3 deletions fusesoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
from configparser import ConfigParser as CP
from pathlib import Path

from fusesoc.librarymanager import Library

Expand All @@ -24,12 +25,13 @@ def __init__(self, path=None):
)
config_files = [
"/etc/fusesoc/fusesoc.conf",
os.path.join(xdg_config_home, "fusesoc", "fusesoc.conf"),
str(Path(xdg_config_home) / "fusesoc" / "fusesoc.conf"),
"fusesoc.conf",
]
else:
logger.debug(f"Using config file '{path}'")
if not os.path.isfile(path):
Path(path).parent.mkdir(parents=True, exist_ok=True)
with open(path, "a"):
pass
config_files = [path]
Expand Down Expand Up @@ -127,7 +129,7 @@ def _get_cache_root(self):
xdg_cache_home = os.environ.get("XDG_CACHE_HOME") or os.path.join(
os.path.expanduser("~"), ".cache"
)
return os.path.join(xdg_cache_home, "fusesoc")
return str(Path(xdg_cache_home) / "fusesoc")

def _get_library_root(self):
from_cfg = self._path_from_cfg("library_root")
Expand All @@ -137,7 +139,7 @@ def _get_library_root(self):
xdg_data_home = os.environ.get("XDG_DATA_HOME") or os.path.join(
os.path.expanduser("~"), ".local/share"
)
return os.path.join(xdg_data_home, "fusesoc")
return str(Path(xdg_data_home) / "fusesoc")

def _get_ignored_dirs(self):
return self._paths_from_cfg("ignored_dirs")
Expand Down
6 changes: 2 additions & 4 deletions fusesoc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import os
import shutil
import signal
import subprocess
import sys
import warnings
from pathlib import Path

from fusesoc import __version__

Expand Down Expand Up @@ -131,9 +131,7 @@ def add_library(fs, args):
if args.config:
config = Config(args.config)
elif vars(args)["global"]:
xdg_config_home = os.environ.get("XDG_CONFIG_HOME") or os.path.join(
os.path.expanduser("~"), ".config"
)
xdg_config_home = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config"))
config_file = os.path.join(xdg_config_home, "fusesoc", "fusesoc.conf")
config = Config(config_file)
else:
Expand Down
7 changes: 2 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ deps =
# directory, but creates an isolated home directory within the tox working
# directory, and clears it out after each test.
commands =
/bin/rm -rf {toxworkdir}/.tmp/homedir/.cache {toxworkdir}/.tmp/homedir/.local/share {toxworkdir}/.tmp/homedir/.config
mkdir -p {toxworkdir}/.tmp/homedir/.config/fusesoc
python -c "import os, shutil, pathlib, uuid; path = pathlib.Path(os.environ['XDG_CACHE_HOME']).parent; path.exists() or exit(); new = path.rename(path.parent / str(uuid.uuid4())); shutil.rmtree(str(new), ignore_errors=True)"

fusesoc --verbose library add --global fusesoc_cores https://github.com/fusesoc/fusesoc-cores
fusesoc list-cores
fusesoc library update
Expand All @@ -29,9 +29,6 @@ setenv =
passenv =
GITHUB_ACTIONS

allowlist_externals =
/bin/rm
mkdir

[testenv:doc]
# Note: this target is *not* used by ReadTheDocs, which runs sphinx-build
Expand Down

0 comments on commit b72d3ff

Please sign in to comment.