Compare commits
No commits in common. "bbfb83cdba10b2639751a72d107961d2ea6ad63e" and "e78719d41488d610e692111a63d3937601b41bdb" have entirely different histories.
bbfb83cdba
...
e78719d414
|
@ -1,176 +0,0 @@
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/python
|
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
|
||||||
|
|
||||||
### Python ###
|
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
share/python-wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# PyInstaller
|
|
||||||
# Usually these files are written by a python script from a template
|
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
||||||
*.manifest
|
|
||||||
*.spec
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.nox/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
*.py,cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
cover/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
db.sqlite3
|
|
||||||
db.sqlite3-journal
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
.pybuilder/
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# IPython
|
|
||||||
profile_default/
|
|
||||||
ipython_config.py
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
# For a library or package, you might want to ignore these files since the code is
|
|
||||||
# intended to run in multiple environments; otherwise, check them in:
|
|
||||||
# .python-version
|
|
||||||
|
|
||||||
# pipenv
|
|
||||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
||||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
||||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
||||||
# install all needed dependencies.
|
|
||||||
#Pipfile.lock
|
|
||||||
|
|
||||||
# poetry
|
|
||||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
||||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
||||||
# commonly ignored for libraries.
|
|
||||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
||||||
#poetry.lock
|
|
||||||
|
|
||||||
# pdm
|
|
||||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
||||||
#pdm.lock
|
|
||||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
||||||
# in version control.
|
|
||||||
# https://pdm.fming.dev/#use-with-ide
|
|
||||||
.pdm.toml
|
|
||||||
|
|
||||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
||||||
__pypackages__/
|
|
||||||
|
|
||||||
# Celery stuff
|
|
||||||
celerybeat-schedule
|
|
||||||
celerybeat.pid
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Environments
|
|
||||||
.env
|
|
||||||
.venv
|
|
||||||
env/
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
env.bak/
|
|
||||||
venv.bak/
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
.dmypy.json
|
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
||||||
|
|
||||||
# pytype static type analyzer
|
|
||||||
.pytype/
|
|
||||||
|
|
||||||
# Cython debug symbols
|
|
||||||
cython_debug/
|
|
||||||
|
|
||||||
# PyCharm
|
|
||||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
### Python Patch ###
|
|
||||||
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
|
||||||
poetry.toml
|
|
||||||
|
|
||||||
# ruff
|
|
||||||
.ruff_cache/
|
|
||||||
|
|
||||||
# LSP config files
|
|
||||||
pyrightconfig.json
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,27 +1,23 @@
|
||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from nvexpo import nvexpo
|
from nvexpo import nvexpo
|
||||||
from nvexpo import consts as CONSTS
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
args = sys.argv
|
args = sys.argv
|
||||||
print(args)
|
|
||||||
if len(args) <= 1:
|
if len(args) <= 1:
|
||||||
nvexpo.show_help()
|
nvexpo.help()
|
||||||
|
return 0
|
||||||
|
if len(args) == 2 and args[1] in ["--load"]:
|
||||||
|
nvexpo.load()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if args[1] in ["--unset"]:
|
if args[1] in ["--unset"]:
|
||||||
nvexpo.unset_env(args[2:])
|
nvexpo.unset_env(args[2:])
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if args[1] in ["--load"]:
|
|
||||||
nvexpo._load()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if args[1] in ["init"]:
|
if args[1] in ["init"]:
|
||||||
try:
|
try:
|
||||||
nvexpo.init(args[2])
|
nvexpo.init(args[2])
|
||||||
|
@ -30,27 +26,22 @@ def main() -> int:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
raw_vars = args[1:]
|
raw_vars = args[1:]
|
||||||
|
if not all("=" in x for x in raw_vars):
|
||||||
|
nvexpo.help()
|
||||||
|
return 1
|
||||||
|
|
||||||
variables = {}
|
variables = {}
|
||||||
for raw_var in raw_vars:
|
for raw_var in raw_vars:
|
||||||
if "=" not in raw_var:
|
|
||||||
nvexpo.show_help("Use the syntax \"key=value\"")
|
|
||||||
return 1
|
|
||||||
try:
|
try:
|
||||||
key, value = raw_var.split("=", 1)
|
key, value = raw_var.split("=", 1)
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
nvexpo.show_help(f"Unexpected error {e}")
|
nvexpo.help()
|
||||||
return 1
|
return 1
|
||||||
key = key.strip("=")
|
key = key.strip("=")
|
||||||
value = value.strip("=").strip('"')
|
value = value.strip("=").strip("\"")
|
||||||
variables[key] = value
|
variables[key] = value
|
||||||
if not key:
|
if not key or not value:
|
||||||
nvexpo.show_help("Empty name")
|
nvexpo.help()
|
||||||
return 1
|
|
||||||
if not value:
|
|
||||||
nvexpo.show_help("Empty value")
|
|
||||||
return 1
|
|
||||||
if not re.match(CONSTS.VARNAME_PATTERN, key):
|
|
||||||
nvexpo.show_help(f"\"{key}\" is not a valid name")
|
|
||||||
return 1
|
return 1
|
||||||
nvexpo.set_env(variables)
|
nvexpo.set_env(variables)
|
||||||
return 0
|
return 0
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,3 +0,0 @@
|
||||||
import re
|
|
||||||
|
|
||||||
VARNAME_PATTERN = re.compile(r"^(\w|_|)+$")
|
|
|
@ -1,9 +1,8 @@
|
||||||
from __future__ import annotations
|
import os
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Any
|
from typing import IO, Any, Dict, List
|
||||||
|
|
||||||
ENV_VARS = Path.home() / ".nvexpo.env"
|
ENV_VARS = Path.home() / ".nvexpo.env"
|
||||||
|
|
||||||
|
@ -12,7 +11,6 @@ class Mode(Enum):
|
||||||
R = "r"
|
R = "r"
|
||||||
W = "w"
|
W = "w"
|
||||||
|
|
||||||
|
|
||||||
class Cmd(Enum):
|
class Cmd(Enum):
|
||||||
Set = "export"
|
Set = "export"
|
||||||
Unset = "unset"
|
Unset = "unset"
|
||||||
|
@ -21,8 +19,7 @@ class Cmd(Enum):
|
||||||
def _get_file(mode: Mode) -> IO[Any]:
|
def _get_file(mode: Mode) -> IO[Any]:
|
||||||
return ENV_VARS.open(mode.value)
|
return ENV_VARS.open(mode.value)
|
||||||
|
|
||||||
|
def _get_saved_vars() -> Dict[str, str]:
|
||||||
def _get_saved_vars() -> dict[str, str]:
|
|
||||||
output = {}
|
output = {}
|
||||||
with _get_file(Mode.R) as file:
|
with _get_file(Mode.R) as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
|
@ -33,42 +30,31 @@ def _get_saved_vars() -> dict[str, str]:
|
||||||
output[key] = value
|
output[key] = value
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def _save_vars(variables: Dict[str, str]):
|
||||||
def _save_vars(variables: dict[str, str]) -> None:
|
new_variables = [f"{key}={value}" for key, value in variables.items()]
|
||||||
new_variables = []
|
|
||||||
for key, value in variables.items():
|
|
||||||
if "'" in value:
|
|
||||||
comma = '"'
|
|
||||||
elif '"' in value:
|
|
||||||
comma = "'"
|
|
||||||
else:
|
|
||||||
comma = ""
|
|
||||||
|
|
||||||
new_variables.append(f"{key}={comma}{value}{comma}")
|
|
||||||
|
|
||||||
with _get_file(Mode.W) as file:
|
with _get_file(Mode.W) as file:
|
||||||
file.write("\n".join(new_variables))
|
file.write("\n".join(new_variables))
|
||||||
|
|
||||||
|
|
||||||
def _print_bulk(attrs: list[str], cmd: Cmd) -> None:
|
def _print_bulk(attrs: List[str], cmd: Cmd):
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
print(f"{cmd.value} {attr}")
|
print(f"{cmd.value} {attr}")
|
||||||
|
|
||||||
|
def _load():
|
||||||
def _load() -> None:
|
|
||||||
current_vars = _get_saved_vars()
|
current_vars = _get_saved_vars()
|
||||||
attrs = [f"{key}={value}" for key, value in current_vars.items()]
|
attrs = [f"{key}={value}" for key, value in current_vars.items()]
|
||||||
_print_bulk(attrs, Cmd.Set)
|
_print_bulk(attrs, Cmd.Set)
|
||||||
|
|
||||||
|
|
||||||
def set_env(variables: dict[str, str]) -> None:
|
def set_env(variables: Dict[str, str]):
|
||||||
current_vars = _get_saved_vars()
|
current_vars = _get_saved_vars()
|
||||||
current_vars.update(variables)
|
current_vars.update(variables)
|
||||||
_save_vars(current_vars)
|
_save_vars(current_vars)
|
||||||
_load()
|
_load()
|
||||||
|
|
||||||
|
|
||||||
def unset_env(variables: list[str]) -> None:
|
def unset_env(variables: List[str]):
|
||||||
current_vars = _get_saved_vars()
|
current_vars = _get_saved_vars()
|
||||||
for var in variables:
|
for var in variables:
|
||||||
current_vars.pop(var, None)
|
current_vars.pop(var, None)
|
||||||
|
@ -76,7 +62,7 @@ def unset_env(variables: list[str]) -> None:
|
||||||
_print_bulk(variables, Cmd.Unset)
|
_print_bulk(variables, Cmd.Unset)
|
||||||
|
|
||||||
|
|
||||||
def show_help(error: None | str = None) -> None:
|
def help(error: None | str = None):
|
||||||
msg = """
|
msg = """
|
||||||
nx: Non-Volatile Export
|
nx: Non-Volatile Export
|
||||||
|
|
||||||
|
@ -100,24 +86,22 @@ def show_help(error: None | str = None) -> None:
|
||||||
hello world
|
hello world
|
||||||
""".strip()
|
""".strip()
|
||||||
msg = "\n".join(map(str.strip, msg.splitlines()))
|
msg = "\n".join(map(str.strip, msg.splitlines()))
|
||||||
if error is not None:
|
|
||||||
msg = f"Error: {error}\n\n" + msg
|
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def init(shell: str | None = None) -> None:
|
def init(shell: str | None = None):
|
||||||
if shell is None:
|
if shell is None:
|
||||||
shell = "bash"
|
shell = "bash"
|
||||||
|
|
||||||
if shell == "bash":
|
if shell == "bash":
|
||||||
cmd = """
|
cmd = """
|
||||||
function nx(){
|
function nx(){
|
||||||
eval "$(nvexpo $@)"
|
eval "$(poetry run nvexpo $@)"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
print(cmd)
|
print(cmd)
|
||||||
_load()
|
_load()
|
||||||
|
|
||||||
|
|
||||||
if not ENV_VARS.exists():
|
if not os.path.exists(ENV_VARS):
|
||||||
_get_file(Mode.W).close()
|
_get_file(Mode.W).close()
|
||||||
|
|
|
@ -38,9 +38,7 @@ ignore = [
|
||||||
"PLR0911",
|
"PLR0911",
|
||||||
"T201",
|
"T201",
|
||||||
"PLR2004",
|
"PLR2004",
|
||||||
"FA102",
|
"FA102"
|
||||||
"PLW2901",
|
|
||||||
"N812"
|
|
||||||
]
|
]
|
||||||
fixable = ["ALL"]
|
fixable = ["ALL"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue