Giter Site home page Giter Site logo

mateusoliveira43 / cly Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 5.96 MB

CLY?! framework to create CLIs with Python | framework para criar CLIs com Python

Home Page: https://mateusoliveira43.github.io/cly/

License: MIT License

Python 97.55% Dockerfile 0.61% Shell 1.83%
python scripts cli

cly's Introduction

CLY?! Build CLIs without dependencies!

Continuos Integration Continuos Delivery Quality Gate Status Imports: isort Code style: black security: bandit pre-commit Python versions PyPy versions

A framework to create command line interfaces with Python, using only Python's standard libraries, like argparse.

Check the project's documentation here.

Requirements

To use (or contribute to) the framework, it is necessary the following tools:

Development

Choose one of the next sections to setup your development environment.

Python

To create a virtual environment, run

python3 -m venv .venv

To activate the virtual environment, run

source .venv/bin/activate

To install the framework's development requirements in the virtual environment, run

pip install -r requirements/dev.txt

To add the framework's tools to the path, run

pip install -e .

To deactivate the virtual environment, run deactivate.

Run the commands of the following sections with the virtual environment active.

Poetry

To install the framework's development requirements in a virtual environment, run

poetry install

To activate the virtual environment, run

poetry shell

To deactivate the virtual environment, run CTRL+D or exit.

To update the requirements file, run

poetry export --format requirements.txt --output requirements/dev.txt --with dev

Run the commands of the following sections with the virtual environment active.

Docker

To connect to project's Docker container shell, run

docker/run.sh

To exit the container's shell, run CTRL+D or exit.

To run Dockerfile linter, run

docker/lint.sh

To run Docker image security vulnerability scan, run

docker/scan.sh

It is needed to have an account in Docker Hub.

To remove the project's containers, images, volumes and networks, run

docker/down.sh

To change Docker configuration, change the variables in .env file.

Run the commands of the following sections in the container's shell.

Quality

The quality measures of the framework are reproduced by the continuos integration (CI) pipeline of the project. CI configuration in .github/workflows/ci.yml file.

Tests

To run tests and coverage report, run

pytest

To see the html report, check the tests/coverage-results/htmlcov/index.html file generated by the command.

Tests and coverage configuration in pyproject.toml file.

Type checking

To run Python type checker, run

mypy .

Python type checker configuration in pyproject.toml file.

Linter

To run Python linter, run

prospector
prospector --profile tests/.prospector.yaml tests

Python linter configuration in .prospector.yaml and tests/.prospector.yaml files.

Code formatters

To check Python code imports format, run

isort --check --diff .

To format Python code imports, run

isort .

To check Python code format, run

black --check --diff .

To format Python code, run

black .

isort and black configuration in pyproject.toml file.

To check all repository's files format, run

ec -verbose

File format configuration in .editorconfig file.

Security vulnerability scanners

To check common security issues in Python code, run

bandit --recursive cly

To check known security vulnerabilities in Python dependencies, run

safety check --file requirements/dev.txt --full-report

Documentation

To check Python documentation generation, run

sphinx-apidoc --module-first --private --output-dir docs/modules cly
sphinx-build -W -T -v -n -a docs public

To generate Python documentation, run

sphinx-apidoc --module-first --private --output-dir docs/modules cly
sphinx-build -v -n -a docs public

To see the documentation, check the public/index.html file that the command generated.

Sphinx configuration in docs/conf.py file.

The documentation is updated automatically by the continuous deploy (CD) pipeline of the project. CD configuration in .github/workflows/cd.yml file.

SonarCloud Code Analysis

SonarCloud analyzes the source code of the project through the CI pipeline.

Pre-commit

To configure pre-commit automatically when cloning the repo, run

pip install pre-commit
git config --global init.templateDir ~/.git-template
pre-commit init-templatedir --hook-type commit-msg --hook-type pre-commit ~/.git-template

Must be installed globally. More information here.

To configure pre-commit locally, run

pre-commit install --hook-type commit-msg --hook-type pre-commit

with your virtual environment active.

To test it, run

pre-commit run --all-files

pre-commit configuration in .pre-commit-config.yaml file.

License

This repository is licensed under the terms of MIT License.

cly's People

Contributors

mateusoliveira43 avatar vandaimer avatar

Stargazers

Eric Yang avatar Adam avatar Alexandre Seemund avatar

Watchers

Kostas Georgiou avatar  avatar

Forkers

vandaimer

cly's Issues

Issue with Wiki

What is the issue?
The repository does not have a Wiki.

What do you suggest?
Create a Wiki and update README.

Issue with Docker

What is the issue?
The repository has no option to run with Docker.

What do you suggest?
Add Docker use for repository.

Issue with install script

What is the issue?
Installation script should delete old files as well.

What do you suggest?
Add this feature.

Issue with change work directory

What is the issue?
The shell manipulation functions in utils.py do not accept an optional argument to change the directory the command must be run.

What do you suggest?
Add the option and pass it to cwd of subprocess.

Issue with "production" code

What is the issue?
There is no command to transform the written code with CLY?! in a single file that can later be executed with

curl path/to/file/in/github | python -

What do you suggest?
Implement this feature.

Issue with Argparse error messages

What is the issue?
Argparse handles error messages by itself, without any configuration from the template.

What do you suggest?
Discover how to configure Argparse's messages.

Issue with documentation

What is the issue?
The project has no documentation about motivation, examples, when to use and comparison with plain argparse.

What do you suggest?
Use Sphinx and GitHub Pages for this.

Issue with Test environment

What is the issue?
The template does not have a testing environment.

What do you suggest?
Implement it.

Something like this

def cli_for_tests(cli: ConfiguredParser, sys_mock: InputOptions) -> int:
    with patch.object(sys, "argv", ["file_name", *sys_mock]):
        try:
            cli()
            return 0
        except SystemExit as sys_exit:
            return sys_exit.code

But still needs to return the shell output...

Issue with relative imports

What is the issue?
The cli package is not using relative imports (which can break the use of the template and is less performative).

What do you suggest?
Use relative imports.
Example:

from cli import something
from cli.something import otherthing

to

from . import something
from .something import otherthing

Issue with README

What is the issue?
The README does not have an Authors section, for example.

What do you suggest?
Study (and create an template) about what sections and structure a README must have.

Issue with create_command

What is the issue?
cli.config:ConfiguredParser.create_command could retrieve the help message from the command's docstring.

What do you suggest?
Automate this task.

Issue with shell funtions

What is the issue?
There is no shell function (in utils.py) that can run multiple commands (would receive a list of the arguments of run_command) and return if the process was successful (all exit code were zero) or one (or more) of them failed.

What do you suggest?
Create it.

Issue with subprocess.Popen

What is the issue?
subprocess.Popen does not work as expected
error

What do you suggest?
Return use of subprocess.run

Issue with long help messages of commands

What is the issue?
If the command's help is long, do not show all of it in the parser's help, only in the subparser's help.

What do you suggest?
Break the help message where are line breaks.

Issue with sonar

What is the issue?
Run sonar locally.

What do you suggest?
Discover how to run sonar locally and add it to README, pre-commit and where else necessary.

Issue with testing

What is the issue?
To run the testing function, it is necessary to pass the CLY?! object every time, which is a repetition.

What do you suggest?
Transform the function in a class, that initializes with the CLY?! object and then the user can call it just passing the command line arguments (which should be a list or a string!).

Issue with CI Artifacts

What is the issue?
The CI generates artifacts that user should be able to download (like coverage reports).

What do you suggest?
Discover how to enable their download in GitHub actions.

Issue with script prog

What is the issue?
When creating a parser, the script uses sys.argv[0] as the prog (how to call the CLI in help). This creates long executable paths.

What do you suggest?
Short the executable paths.

Issue with example/tests theme

What is the issue?
The example/tests have no specific theme (like star wars, batman, ...).

What do you suggest?
Choose one and apply it (fixing TODO in tests/__init__.py).

Issue with code formatter

What is the issue?
The repository does not have a general code formatter (like black).

What do you suggest?
Study the possibilities and add one to the repository.

Issue with new Docker compose command

What is the issue?
Docker now has compose as a command and not a part in docker-compose.

What do you suggest?
Adjust scripts in the docker folder to accept both the new and previous ways of calling compose.

Issue with Linter in tests

What is the issue?
The functions written to test the template also need docstrings.

What do you suggest?
Discover how to remove this rule from Prospector.

Issue with Project

What is the issue?
The repository has no Project for managing Issues.

What do you suggest?
Create a Project to the repository and update Issue's template.

Issue with CI/CD running twice

What is the issue?
After a PR closes, the CI/CD of the project runs twice (for the PR and for the versioning automation).

What do you suggest?
Find a way to it only run it once.

Issue with install script

What is the issue?
The project has no installation/update script.

What do you suggest?
Create it.

Add Poetry

What is the issue?
Study and evaluate if is better to use Poetry in the repository.

Issue with Docstring automation

What is the issue?
If a parameter description breaks line, the script does not read the description correctly.

What do you suggest?
Fix this problem.

Issue with tests/batcomputer.py | Problema com tests/batcomputer.py

What is the issue? | Qual é o problema?

While testing the examples (aka tests/batcomputer.py), I saw that the code isn't handling the input as case-insentive.

Also, I don't know if CLY?! should do it or not.

Anyway, if I type

  • tests/batcomputer.py id batman it works fine.
  • tests/batcomputer.py id Batman it throws an error.

Example:

(cly-py3.11) develop@docker:~/cly$ tests/batcomputer.py id batman
Bruce Wayne A.K.A. Batman 🦇
(cly-py3.11) develop@docker:~/cly$ 
(cly-py3.11) develop@docker:~/cly$ 
(cly-py3.11) develop@docker:~/cly$ tests/batcomputer.py id Batman
Traceback (most recent call last):
  File "/home/develop/cly/tests/batcomputer.py", line 5, in <module>
    CLI()
  File "/home/develop/cly/cly/config.py", line 382, in __call__
    self.commands[namespace.commands](
  File "/home/develop/cly/cly/config.py", line 66, in wrap
    return func(**kwargs)
           ^^^^^^^^^^^^^^
  File "/home/develop/cly/tests/batcomputer_cli/commands/identify.py", line 25, in identify
    responses = [
                ^
  File "/home/develop/cly/tests/batcomputer_cli/commands/identify.py", line 27, in <listcomp>
    get_oracle_data(alias) if oracle else get_alias_data(alias),
                                          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/develop/cly/tests/batcomputer_cli/database.py", line 47, in get_alias_data
    return f"{CHARACTERS[alias]} A.K.A. {alias.title()} {ICONS[alias]}"
              ~~~~~~~~~~^^^^^^^
KeyError: 'Batman'

Also, I can see that if I type tests/batcomputer.py id batmand the result is Batmand not identified by Batcomputer yet, so the code handles very well the unknown values. So my first assumption might the wrong.

What do you suggest? | O que sugere?

  • Decide if CLY?! should handle it, as adding a default option to make it case-insensitive (or not)
  • Just fix the current example as it's not really related to the library - just showing how to use CLY?!

Issue with pre-commit

What is the issue?
The hooks in the repository's pre-commit are almost all locals.

What do you suggest?
Search for implementation of the libraries used in repository's pre-commit and change them.

Issue with Poetry in CI

What is the issue?
The CI uses pip to install dependencies, should be better to use Poetry to do it?

What do you suggest?
Study if is a good idea to use Poetry in CI environment.

Feature for Docstring automation

What is the issue?
The docstring automation should be able to read reST format and output to shell (underline, color, etc).

What do you suggest?
Implement feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.