Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Change module imports to private scope #515

Merged
merged 15 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
zghannam marked this conversation as resolved.
Show resolved Hide resolved
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
author = "Steven Atkinson"

# TODO update this automatically from nam.__version__!
release = "0.11"
version = "0.11.1"
release = "0.12"
version = "0.12.0"

# -- General configuration

Expand Down
4 changes: 2 additions & 2 deletions nam/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Created Date: Saturday February 5th 2022
# Author: Steven Atkinson (steven@atkinson.mn)

from copy import deepcopy
from copy import deepcopy as _deepcopy


class InitializableFromConfig(object):
Expand All @@ -12,4 +12,4 @@ def init_from_config(cls, config):

@classmethod
def parse_config(cls, config):
return deepcopy(config)
return _deepcopy(config)
2 changes: 1 addition & 1 deletion nam/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.1"
__version__ = "0.12.0"
54 changes: 27 additions & 27 deletions nam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def _ensure_graceful_shutdowns():
https://github.com/sdatkinson/neural-amp-modeler/issues/105
https://stackoverflow.com/a/44822794
"""
import os
import os as _os
zghannam marked this conversation as resolved.
Show resolved Hide resolved

if os.name == "nt": # OS is Windows
os.environ["FOR_DISABLE_CONSOLE_CTRL_HANDLER"] = "1"
if _os.name == "nt": # OS is Windows
_os.environ["FOR_DISABLE_CONSOLE_CTRL_HANDLER"] = "1"


_ensure_graceful_shutdowns()
Expand All @@ -37,38 +37,38 @@ def removesuffix(s: str, suffix: str) -> str:
return s
return s[: -len(suffix)] if s.endswith(suffix) else s

import importlib
import os
import sys
import importlib as _importlib
zghannam marked this conversation as resolved.
Show resolved Hide resolved
import os as _os
import sys as _sys

# DRY: Make sure this matches the test!
home_path = os.environ["HOMEPATH"] if os.name == "nt" else os.environ["HOME"]
extensions_path = os.path.join(home_path, ".neural-amp-modeler", "extensions")
if not os.path.exists(extensions_path):
home_path = _os.environ["HOMEPATH"] if _os.name == "nt" else _os.environ["HOME"]
extensions_path = _os.path.join(home_path, ".neural-amp-modeler", "extensions")
if not _os.path.exists(extensions_path):
return
if not os.path.isdir(extensions_path):
if not _os.path.isdir(extensions_path):
print(
f"WARNING: non-directory object found at expected extensions path {extensions_path}; skip"
)
print("Applying extensions...")
if extensions_path not in sys.path:
sys.path.append(extensions_path)
if extensions_path not in _sys.path:
_sys.path.append(extensions_path)
extensions_path_not_in_sys_path = True
else:
extensions_path_not_in_sys_path = False
for name in os.listdir(extensions_path):
for name in _os.listdir(extensions_path):
if name in {"__pycache__", ".DS_Store"}:
continue
try:
importlib.import_module(removesuffix(name, ".py")) # Runs it
_importlib.import_module(removesuffix(name, ".py")) # Runs it
print(f" {name} [SUCCESS]")
except Exception as e:
print(f" {name} [FAILED]")
print(e)
if extensions_path_not_in_sys_path:
for i, p in enumerate(sys.path):
for i, p in enumerate(_sys.path):
if p == extensions_path:
sys.path = sys.path[:i] + sys.path[i + 1 :]
_sys.path = _sys.path[:i] + _sys.path[i + 1 :]
break
else:
raise RuntimeError("Failed to remove extensions path from sys.path?")
Expand All @@ -77,17 +77,17 @@ def removesuffix(s: str, suffix: str) -> str:

_apply_extensions()

import json
from argparse import ArgumentParser
from pathlib import Path
import json as _json
from argparse import ArgumentParser as _ArgumentParser
from pathlib import Path as _Path

from nam.train.full import main as _nam_full
from nam.train.gui import run as nam_gui # noqa F401 Used as an entry point
from nam.util import timestamp
from nam.train.gui import run as _nam_gui # noqa F401 Used as an entry point
from nam.util import timestamp as _timestamp


def nam_full():
parser = ArgumentParser()
parser = _ArgumentParser()
parser.add_argument("data_config_path", type=str)
parser.add_argument("model_config_path", type=str)
parser.add_argument("learning_config_path", type=str)
Expand All @@ -96,17 +96,17 @@ def nam_full():

args = parser.parse_args()

def ensure_outdir(outdir: str) -> Path:
outdir = Path(outdir, timestamp())
def ensure_outdir(outdir: str) -> _Path:
outdir = _Path(outdir, _timestamp())
outdir.mkdir(parents=True, exist_ok=False)
return outdir

outdir = ensure_outdir(args.outdir)
# Read
with open(args.data_config_path, "r") as fp:
data_config = json.load(fp)
data_config = _json.load(fp)
with open(args.model_config_path, "r") as fp:
model_config = json.load(fp)
model_config = _json.load(fp)
with open(args.learning_config_path, "r") as fp:
learning_config = json.load(fp)
learning_config = _json.load(fp)
_nam_full(data_config, model_config, learning_config, outdir, args.no_show)
Loading
Loading