Skip to content

Commit

Permalink
fix: unbound local var (#127)
Browse files Browse the repository at this point in the history
* fix: resolve unbound local variable

Closes #118

* chore: clean up issues identified by linter

* revert rename

* tidy up workflows

* bump pytest
  • Loading branch information
mikejgray authored Jun 8, 2024
1 parent f1e1c6d commit f7f6873
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ jobs:
uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master
with:
test_pipaudit: true
pipaudit_ignored: "GHSA-r9hx-vwmv-q579 PYSEC-2022-43012 GHSA-j8r2-6x86-q33q"
# PYSEC-2023-228 is a pip vulnerability that only exists in the pipeline
# GHSA-9wx4-h78v-vm56 is problematic but it's an issue upstream
pipaudit_ignored: "GHSA-r9hx-vwmv-q579 PYSEC-2022-43012 GHSA-j8r2-6x86-q33q PYSEC-2023-228 GHSA-9wx4-h78v-vm56"
9 changes: 5 additions & 4 deletions .github/workflows/install_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:
strategy:
max-parallel: 2
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
python-version: [3.8, 3.9, "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand All @@ -31,4 +32,4 @@ jobs:
python setup.py bdist_wheel
- name: Install package
run: |
pip install .[all]
pip install .[all]
47 changes: 24 additions & 23 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,45 @@ on:
branches:
- dev
paths-ignore:
- 'ovos_config/version.py'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
- "ovos_config/version.py"
- "examples/**"
- ".github/**"
- ".gitignore"
- "LICENSE"
- "CHANGELOG.md"
- "MANIFEST.in"
- "readme.md"
- "scripts/**"
push:
branches:
- master
paths-ignore:
- 'ovos_config/version.py'
- 'requirements/**'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
- "ovos_config/version.py"
- "requirements/**"
- "examples/**"
- ".github/**"
- ".gitignore"
- "LICENSE"
- "CHANGELOG.md"
- "MANIFEST.in"
- "readme.md"
- "scripts/**"
workflow_dispatch:

jobs:
unit_tests:
strategy:
max-parallel: 2
matrix:
python-version: [ 3.7, 3.8, 3.9]
python-version: [3.8, 3.9, "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install System Dependencies
run: |
sudo apt-get update
Expand All @@ -62,4 +63,4 @@ jobs:
- name: Upload coverage
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
9 changes: 5 additions & 4 deletions ovos_config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def show(user, system, remote, section, list_sections):
# based on chosen configuration
if name != "Joined":
_sections = [k for k, v in config.items() if isinstance(v, dict)]
if len([k for k, v in config.items() if not isinstance(v, dict)]):
if [k for k, v in config.items() if not isinstance(v, dict)]:
_sections.append("base")
else:
_sections = SECTIONS
Expand Down Expand Up @@ -275,7 +275,7 @@ def set(key, value):
console.print("User exit", style="red")
exit()
elif not paths:
console.print(f"[red]Error:[/red] No key that fits the query")
console.print("[red]Error:[/red] No key that fits the query")
exit()
else:
choice = 0
Expand All @@ -292,6 +292,8 @@ def set(key, value):
f"(type: [red]{selected_type}[/red]) "))
value = value.replace('"','').replace("'","").replace("`","")

local_conf = CONFIGS[2][1]
_value = None
# type checking/casting
try:
if isinstance(selected_value, str):
Expand Down Expand Up @@ -319,8 +321,7 @@ def set(key, value):
except (TypeError, ValueError):
console.print(f"[red]Error:[/red] The value passed can't be cast into {selected_type}")
exit()

local_conf = CONFIGS[2][1]

pathSet(local_conf, selected_path, _value)
local_conf.store()

Expand Down
14 changes: 8 additions & 6 deletions ovos_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def load_local(self, path=None):
"""
path = path or self.path
if not path:
LOG.error(f"in memory configuration, nothing to load")
LOG.error("in memory configuration, nothing to load")
return
if exists(path) and isfile(path):
with self.__lock:
try:
if self._get_file_format(path) == "yaml":
with open(path) as f:
with open(path, encoding="utf-8") as f:
config = yaml.safe_load(f)
else:
config = load_commented_json(path)
Expand All @@ -120,7 +120,9 @@ def load_local(self, path=None):
LOG.debug(f"Configuration '{path}' not defined, skipping")

def reload(self):
if isfile(self.path) and self._last_loaded == getmtime(self.path):
if isfile(self.path) \
and self._last_loaded \
and self._last_loaded == getmtime(self.path):
LOG.debug(f"{self.path} not changed since last load "
f"(changed {time() - self._last_loaded} seconds ago)")
return
Expand All @@ -129,15 +131,15 @@ def reload(self):
def store(self, path=None):
path = path or self.path
if not path:
LOG.error(f"in memory configuration, no save location")
LOG.error("in memory configuration, no save location")
return
with self.__lock:
if self._get_file_format(path) == "yaml":
with open(path, 'w+') as f:
with open(path, 'w+', encoding="utf-8") as f:
yaml.dump(dict(self), f, allow_unicode=True,
default_flow_style=False, sort_keys=False)
else:
with open(path, 'w+') as f:
with open(path, 'w+', encoding="utf-8") as f:
json.dump(self, f, indent=2)

def merge(self, conf):
Expand Down
5 changes: 2 additions & 3 deletions ovos_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def init_module_config(module_name: str, module_override: str,

# Check for and update submodules
if module_name == "__main__":
raise ValueError(f"Configuring `__main__` has unintended consequences"
f"and is not supported here")
raise ValueError("Configuring `__main__` has unintended consequences"
"and is not supported here")
if module_name in ovos_conf['submodule_mappings']:
LOG.debug(f"{module_name} already configured, skipping configuration")
else:
Expand Down Expand Up @@ -109,4 +109,3 @@ def init_module_config(module_name: str, module_override: str,
importlib.reload(ovos_config.models)
importlib.reload(ovos_config.config)
importlib.reload(ovos_config)

2 changes: 1 addition & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coveralls==1.8.2
flake8==3.7.9
pytest==5.2.4
pytest==8.2.2
pytest-cov==2.8.1
cov-core==1.15.0
sphinx==2.2.1
Expand Down

0 comments on commit f7f6873

Please sign in to comment.