Skip to content

Commit

Permalink
Samila Command Line Interface (CLI) (#233)
Browse files Browse the repository at this point in the history
* add : CLI added.

* add : tests added.

* log : changes logged.

* fix : Codacy issues fixed.

* fix : tests for CLI fixed.

* change : `version` --> `info`.

* add : `--show_image` flag added.

* update : `README.md` updated.

* change : `--show-image` --> `--no-display`.
  • Loading branch information
sadrasabouri authored Oct 13, 2024
1 parent c5d6d4f commit d4b477a
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ jobs:
pip install .
- name: First test
run: |
python -m samila
python -m samila --version
python -m samila --info
- name: Samila CLI test
run: |
python -m samila --no-display --color=red --bgcolor=black --rotation=30 --projection=polar --mode f2_vs_f1 --save-image test.png
- name: Test requirements Installation
run: |
python otherfiles/requirements-splitter.py
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Command Line Interface (CLI)
## [1.3] - 2024-09-09
### Added
- `deprecated` function
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,26 @@ Config structure:
}
```

### Command Line Interface (CLI)
You can easily create art directly from the command line with Samila CLI. Here's an example command to get started:
```bash
samila --color=red --bgcolor=black --rotation=30 --projection=polar --mode f2_vs_f1 --save-image test.png
```

In this example:
- `--color=red`: Sets the primary color of the art.
- `--bgcolor=black`: Sets the background color.
- `--rotation=30`: Rotates the artwork by 30 degrees.
- `--projection=polar`: Use polar projection for plotting.
- `--mode=f2_vs_f1`: Sets the generation mode
- `--save-image=test.png`: Saves the generated image as test.png.

For more options and detailed usage, run the following command to access help:
```bash
samila --help
```
This will provide additional information on all available parameters and how to customize your artwork further.

## Mathematical details
Samila is simply a transformation between a square-shaped space from the Cartesian coordinate system to any arbitrary coordination like [Polar coordinate system](https://en.wikipedia.org/wiki/Polar_coordinate_system).

Expand Down
107 changes: 103 additions & 4 deletions samila/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,110 @@
# -*- coding: utf-8 -*-
"""Samila main."""

import argparse
import matplotlib.pyplot as plt

from art import tprint
from .params import SAMILA_VERSION
from .params import SAMILA_VERSION, GenerateMode, Projection, Marker
from .functions import samila_help
from .genimage import GenerativeImage


def main():
"""
CLI main function.
:return: None
"""
parser = argparse.ArgumentParser()
parser.add_argument('--version', help='version', action='store_true', default=False)
parser.add_argument('--info', help='info', action='store_true', default=False)

parser.add_argument('--load-config', help='load config', type=str)
parser.add_argument('--load-data', help='load data', type=str)
parser.add_argument('--function1', help='function1', type=str)
parser.add_argument('--function2', help='function2', type=str)
parser.add_argument('--function_seed', help='function seed', type=str)

parser.add_argument('--seed', help='seed', type=str)
parser.add_argument('--start', help='start', type=float)
parser.add_argument('--step', help='step', type=float)
parser.add_argument('--stop', help='stop', type=float)
parser.add_argument(
'--mode',
help='generation mode',
type=str,
choices=[x.value for x in GenerateMode])

parser.add_argument('--color', help='color', type=str)
parser.add_argument('--bgcolor', help='bgcolor', type=str)
parser.add_argument('--cmap', help='cmap', type=str)
parser.add_argument('--spot-size', help='spot size', type=float)
parser.add_argument('--size', help='size', type=tuple)
parser.add_argument('--alpha', help='alpha', type=float)
parser.add_argument('--linewidth', help='linewidth', type=float)
parser.add_argument('--rotation', help='rotation', type=float)
parser.add_argument(
'--projection',
help='projection type',
type=str,
choices=[x.value for x in Projection])
parser.add_argument(
'--marker',
help='marker type',
type=str,
choices=[x.value for x in Marker])

parser.add_argument('--save-image', help='save image', type=str)
parser.add_argument('--depth', help='depth', type=float)
parser.add_argument('--save-data', help='save data', type=str)
parser.add_argument('--save-config', help='save config', type=str)
parser.add_argument('--no-display', help='no display', action='store_true', default=False)
args = parser.parse_args()

if args.version:
print(SAMILA_VERSION)
elif args.info:
tprint("samila")
tprint("V:" + SAMILA_VERSION)
samila_help()
else:
gi = GenerativeImage(
function1=args.function1,
function2=args.function2,
func_seed=args.function_seed,
data=args.load_data,
config=args.load_config,
)
gi.generate(
seed=args.seed,
start=args.start,
step=args.step,
stop=args.stop,
mode=args.mode,
)
gi.plot(
color=args.color,
bgcolor=args.bgcolor,
cmap=args.cmap,
spot_size=args.spot_size,
size=args.size,
projection=args.projection,
marker=args.marker,
alpha=args.alpha,
linewidth=args.linewidth,
rotation=args.rotation,
)
if not args.no_display:
plt.show()

if args.save_image:
gi.save_image(args.save_image, args.depth)
if args.save_data:
gi.save_data(args.save_data)
if args.save_config:
gi.save_config(args.save_config)


if __name__ == "__main__":
tprint("samila")
tprint("V:" + SAMILA_VERSION)
samila_help()
main()

0 comments on commit d4b477a

Please sign in to comment.