Skip to content

Commit

Permalink
adds comment to view deps config (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoclyps authored Dec 15, 2022
1 parent c4addf5 commit ea97634
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,58 @@ export DEPS_EXPORT_TO_SVG=false
deps check
```

### Configuration

Deps supports both .ini and .env files. Deps always searches for configuration in this order:

* Environment variables;
* Repository: ini or .env file;
* Configuration Path
* Review Defaults

The following steps are used to provide the configuration using a `.env` or `.ini` file. The configuration can be read from within the module/repository (default location set by decouple) using the `.env` file or via a location specified by an environmental variable that points to a `.ini` file located in the root of the project or in a location specified by `PATH_TO_CONFIG`.

#### Using an `.env` file within the repository

```bash
cd /home/<your-user>/workspace/apoclyps/deps
touch .env

echo "GITHUB_ORG=apoclyps" >> .env
echo "GITHUB_REPOSITORIES=micropython-by-example" >> .env
python -m deps config
```

#### Using an `.ini` file within the repository

```bash
cd /home/<your-user>/workspace/apoclyps/deps
touch settings.ini
echo "[settings]\nGITHUB_ORG=apoclyps\nGITHUB_REPOSITORIES=micropython-by-example" >> settings.ini

python -m deps config
```

#### Providing a configuration path

If you wish to set the configuration path to use an `ini` or `.env` file when running the application, you can use the configuration of a specific file by supplying the path to the configuration like so:

```bash
cd /home/apoclyps/
touch settings.ini
echo "[settings]\nGITHUB_ORG=apoclyps\nGITHUB_REPOSITORIES=micropython-by-example" >> settings.ini

cd /home/<your-user>/workspace/apoclyps/deps
export DEPS_PATH_TO_CONFIG=/home/<your-user>/

python -m deps config
```

If at any time, you want to confirm your configuration reflects the file you have provided, you can use `deps config` to view what current configuration of Deps.

#### Configuring Layout


## Getting started with local development

To build and run the CLI on your host, you will need Python 3.9 or greater, pip, and virtualenv to build and run `deps`.
Expand Down
15 changes: 15 additions & 0 deletions deps/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
from rich.console import Console

from deps.environment_configuration.view import EnvironmentConfigurationView
from deps.pipenv.view import DependenciesView

from ..version import __version__
Expand All @@ -27,6 +28,20 @@ def check() -> None:
DependenciesView(console=console).render()


@cli.command(help="Show the current configuration used by Deps")
@click.option("-show", "--show/--hide", default=False, is_flag=True)
def config(show: bool) -> None:
"""
Command:\n
deps config
Usage:\n
deps config --show \n
deps config --hide \n
"""
console = Console()
EnvironmentConfigurationView(console=console).render(show=show)


def main() -> None:
"""Entry point to CLI"""
cli()
8 changes: 7 additions & 1 deletion deps/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os

from decouple import AutoConfig, Csv

config = AutoConfig()
# configures decouple to use settings.ini or .env file from another directory
if DEPS_PATH_TO_CONFIG := os.environ.get("DEPS_PATH_TO_CONFIG", None):
config = AutoConfig(search_path=DEPS_PATH_TO_CONFIG)
else:
config = AutoConfig(search_path=".")


# Github Config
Expand Down
Empty file.
60 changes: 60 additions & 0 deletions deps/environment_configuration/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from dataclasses import dataclass

from rich.console import Console
from rich.table import Table

from deps import config


@dataclass
class EnvironmentConfigurationView:
"""Responsible for rendering a table of all dependencies grouped by service"""

console: Console

def __init__(self, console: Console) -> None:
"""Initialize the view"""

self.console = console

def render(self, show: bool) -> None:
"""Render the view"""

configurations = [
{
"name": "GITHUB_TOKEN",
"value": config.GITHUB_TOKEN if show else "".join("*" for _ in range(len(config.GITHUB_TOKEN))),
},
{"name": "GITHUB_USER", "value": config.GITHUB_USER},
{"name": "GITHUB_URL", "value": config.GITHUB_URL},
{
"name": "DEPS_PATH_TO_CONFIG",
"value": f"{config.DEPS_PATH_TO_CONFIG}",
},
{
"name": "GITHUB_DEFAULT_PAGE_SIZE",
"value": f"{config.GITHUB_DEFAULT_PAGE_SIZE}",
},
{
"name": "EXTERNAL_SERVICE_MAXIMUM_REQUEST_ATTEMPTS",
"value": f"{config.EXTERNAL_SERVICE_MAXIMUM_REQUEST_ATTEMPTS}",
},
{
"name": "EXTERNAL_SERVICE_WAIT_IN_MS_BETWEEN_REQUESTS",
"value": f"{config.EXTERNAL_SERVICE_WAIT_IN_MS_BETWEEN_REQUESTS}",
},
{"name": "DEPS_EXPORT_TO_SVG", "value": f"{config.DEPS_EXPORT_TO_SVG}"},
{
"name": "GITHUB_REPOSITORIES",
"value": ", ".join(config.GITHUB_REPOSITORIES),
},
]

table = Table()
table.add_column("Name", style="white", no_wrap=True)
table.add_column("Value", style="cyan")

for configuration in configurations:
table.add_row(configuration["name"], configuration["value"])

self.console.print(table)
2 changes: 1 addition & 1 deletion deps/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def retrieve(self, name: str) -> None:
"""Retrieve the latest version of a package from PyPI"""
response = requests.get(f"https://pypi.org/pypi/{name}/json", timeout=10)

if response.status_code != HTTPStatus.OK or response.status_code != HTTPStatus.NOT_FOUND:
if response.status_code not in (HTTPStatus.OK, HTTPStatus.NOT_FOUND):
response.raise_for_status()

if response.status_code != HTTPStatus.NOT_FOUND:
Expand Down

0 comments on commit ea97634

Please sign in to comment.