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

Lg/rework input #5

Merged
merged 16 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
rev: v0.8.4
hooks:
# Run the linter.
- id: ruff
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.3.0
- Rework the Textarea for Inputing Variables
- Add `duplicate` and `file was edited` hint in preview panel
- Fix Modal Save Screen start with Button disabled if Input is empty
- Fix Save Button enabling/disabling when content was changed

## Version 0.2.3
- Fix CSS for modals and buttons
- Small Text Adjustments
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Phony: test

test:
uv run pytest
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dotenvhub"
version = "0.2.3"
version = "0.3.0"
description = "Terminal App to manage .env files written in Python powered by Textual"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -35,6 +35,8 @@ dot = "dotenvhub.app:run"


[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "file"
addopts = "--cov src/dotenvhub --cov-report term-missing --verbose --color=yes"
testpaths = ["tests"]

Expand All @@ -48,4 +50,5 @@ dev = [
"pytest-cov>=6.0.0",
"pytest>=8.3.4",
"textual-dev>=1.7.0",
"pytest-asyncio>=0.25.0",
]
85 changes: 18 additions & 67 deletions src/dotenvhub/app.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,48 @@
"""
This is a skeleton file that can serve as a starting point for a Python
console script. To run this script uncomment the following lines in the
``[options.entry_points]`` section in ``setup.cfg``::

console_scripts =
fibonacci = dotenvhub.skeleton:run

Then run ``pip install .`` (or ``pip install -e .`` for editable mode)
which will install the command ``fibonacci`` inside your current environment.

Besides console scripts, the header (i.e. until ``_logger``...) of this file can
also be used as template for Python modules.

Note:
This file can be renamed depending on your needs or safely removed if not needed.

References:
- https://setuptools.pypa.io/en/latest/userguide/entry_point.html
- https://pip.pypa.io/en/stable/reference/pip_install
"""

import sys

from dotenvhub import cli_parser, constants, tui, utils
from dotenvhub.tui import DotEnvHub
from dotenvhub.cli_parser import parse_args
from dotenvhub.constants import ENV_FILE_DIR_PATH, CONFIG_FILE_PATH
from dotenvhub.config import create_init_config
from dotenvhub.utils import (
create_copy_in_cwd,
get_env_content,
create_shell_export_str,
console,
)

__author__ = "Zaloog"
__copyright__ = "Zaloog"
__license__ = "MIT"


# ---- Python API ----
# The functions defined in this section can be imported by users in their
# Python scripts/interactive interpreter, e.g. via
# `from dotenvhub.skeleton import fib`,
# when using this Python module as a library.


# ---- CLI ----
# The functions defined in this section are wrappers around the main Python
# API allowing them to be called directly from the terminal as a CLI
# executable/script.


def main(args):
"""Wrapper allowing :func:`fib` to be called with string arguments in a CLI fashion

Instead of returning the value from :func:`fib`, it prints the result to the
``stdout`` in a nicely formatted message.
create_init_config(conf_path=CONFIG_FILE_PATH, data_path=ENV_FILE_DIR_PATH)

Args:
args (List[str]): command line parameters as list of strings
(for example ``["--verbose", "42"]``).
"""
parsed_args = cli_parser.parse_args(args)
parsed_args = parse_args(args)

if not args:
tui.DotEnvHub().run()
DotEnvHub(config_path=CONFIG_FILE_PATH, data_path=ENV_FILE_DIR_PATH).run()

if parsed_args.mode == "shell":
content = utils.get_env_content(
filepath=constants.ENV_FILE_DIR_PATH / parsed_args.filename
)
content = get_env_content(filepath=ENV_FILE_DIR_PATH / parsed_args.filename)

shell_str = utils.create_shell_export_str(
shell_str = create_shell_export_str(
shell=parsed_args.shell, env_content=content
)

utils.console.print(f"Copied [blue]{shell_str}[/] to clipboard")
console.print(f"Copied [blue]{shell_str}[/] to clipboard")

if parsed_args.mode == "copy":
utils.create_copy_in_cwd(
filepath=constants.ENV_FILE_DIR_PATH / parsed_args.filename,
create_copy_in_cwd(
filepath=ENV_FILE_DIR_PATH / parsed_args.filename,
filename=parsed_args.export_name,
)


def run():
"""Calls :func:`main` passing the CLI arguments extracted from :obj:`sys.argv`

This function can be used as entry point to create console scripts with setuptools.
"""
main(sys.argv[1:])


if __name__ == "__main__":
# ^ This is a guard statement that will prevent the following code from
# being executed in the case someone imports this file instead of
# executing it as a script.
# https://docs.python.org/3/library/__main__.html

# After installing your project with pip, users can also run your Python
# modules as scripts via the ``-m`` flag, as defined in PEP 338::
#
# python -m dotenvhub.skeleton 42
#
run()
30 changes: 25 additions & 5 deletions src/dotenvhub/assets/tui.css → src/dotenvhub/assets/tui.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
layout: grid;
grid-size: 2; /* two columns */
grid-columns: 1fr;
grid-rows: 1fr;
grid-rows: 55% 45%;
}

/* ############################################### */
Expand Down Expand Up @@ -64,16 +64,35 @@ CollapsibleTitle {
/* ############################################### */
/* Env File Preview */
#file-preview {
width: auto;
width: 1fr;
background: $panel;
border: red;
height: 100%;
height: 1fr;
background: $boost;
}
KeyValPair {
height:auto;
width:1fr;

Label{
width:3;
content-align:center middle;
margin:1 0;
}
ValueInput {
height:auto;
width:4fr;
margin:0 1 0 0;
}
VariableInput {
height:auto;
width:4fr;
}
}
/* ############################################### */
/* Interaction General */
#interaction {
height: 100%;
height: 1fr;
layout: grid;
grid-size: 3;
grid-columns: 1fr;
Expand Down Expand Up @@ -114,6 +133,7 @@ CollapsibleTitle {
/* Interaction Export Name */
#interaction-export-name {
width: 1fr;
height:auto;
column-span: 2;
margin: 0 1 0 1 ;
}
Expand All @@ -135,7 +155,7 @@ CollapsibleTitle {
margin: 1 0 0 0;
}
#horizontal-save-new > Button {
height: 1fr;
height: 3;
width: 1fr;
margin: 0 1;
}
Expand Down
15 changes: 3 additions & 12 deletions src/dotenvhub/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@

from dotenvhub import __version__

from dotenvhub.config import cfg
from dotenvhub.config import DotEnvHubConfig
from dotenvhub.constants import SHELLS


def parse_args(args):
"""Parse command line parameters

Args:
args (List[str]): command line parameters as list of strings
(for example ``["--help"]``).

Returns:
:obj:`argparse.Namespace`: command line parameters namespace
"""

cfg = DotEnvHubConfig()
parser = argparse.ArgumentParser(description="DotEnvHub your .env file manager")
subparsers = parser.add_subparsers(dest="mode")
parser.add_argument(
"--version",
action="version",
version=f"kanban-python {__version__}",
version=f"dotenvhub {__version__}",
)
sub_exp = subparsers.add_parser("copy", help="Export target File to CWD")
sub_exp.add_argument(
Expand Down
17 changes: 5 additions & 12 deletions src/dotenvhub/config.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import configparser

from dotenvhub.constants import (
CONFIG_FILE_NAME,
CONFIG_FILE_PATH,
CONFIG_PATH,
DATA_PATH,
ENV_FILE_DIR_PATH,
)


def create_init_config(conf_path=CONFIG_PATH, data_path=DATA_PATH):
def create_init_config(conf_path=CONFIG_FILE_PATH, data_path=ENV_FILE_DIR_PATH):
if check_config_exists(path=conf_path):
return

config = configparser.ConfigParser(default_section=None)
config.optionxform = str
config["settings"] = {"Shell": "bash"}

if not ENV_FILE_DIR_PATH.exists():
data_path.mkdir(exist_ok=True)
ENV_FILE_DIR_PATH.mkdir(exist_ok=True)

with open(conf_path / CONFIG_FILE_NAME, "w") as configfile:
with open(conf_path, "w") as configfile:
config.write(configfile)


Expand Down Expand Up @@ -49,9 +48,3 @@ def shell(self) -> str:
def shell(self, new_shell) -> str:
self._config["settings"]["Shell"] = new_shell
self.save()


if not check_config_exists():
create_init_config()

cfg = DotEnvHubConfig()
Loading
Loading