Skip to content

Commit

Permalink
build: merge develop to master
Browse files Browse the repository at this point in the history
  • Loading branch information
piraz authored Apr 21, 2024
2 parents 02bec06 + b67b134 commit 4a9ecad
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 258 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -22,6 +22,3 @@ jobs:
- name: Run python unit tests
run: |
PYTHONPATH=$PYTHONPATH:. python tests/runtests.py
- name: Run python behave tests
run: |
./scripts/run_behave.sh
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2019-2023 Flavio Garcia
Copyright 2019-2024 Flavio Garcia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 1 addition & 6 deletions examples/doit/doit/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Garcia
# Copyright 2019-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,14 +21,9 @@

logger = logging.getLogger(__name__)

conf = {
'commands': []
}

DOIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
DOIT_CONFIG_FILE = os.path.join(DOIT_ROOT, "doit", "doit.yml")


pass_context = click.make_pass_decorator(taskio.CliContext, ensure=True)


Expand Down
8 changes: 4 additions & 4 deletions examples/doit/doit/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Garcia
# Copyright 2019-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,9 +27,9 @@ def task_function(cmd, namespace):
@taskio.command(short_help="Generates an uuid4 string")
@click.argument("path", required=False, type=click.Path(resolve_path=True))
@pass_context
def uuid(ctx):
"""Initializes a repository."""
print(ctx)
def uuid(ctx, path):
from pprint import pprint
pprint(ctx.context.invoked_subcommand)


@click.command(short_help="Do another thing")
Expand Down
4 changes: 2 additions & 2 deletions examples/doit/doit/new_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Gonçalves Garcia
# Copyright 2019-2024 Flavio Gonçalves Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
import click


@click.command()
@click.command(short_help="Do a cli thingy")
@pass_context
def cli1(ctx):
print(ctx.context.loader.sources)
Expand Down
1 change: 0 additions & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
behave==1.2.6
45 changes: 19 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2015-2023 Flavio Garcia
# Copyright 2015-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,34 +17,28 @@
import taskio
from setuptools import setup
from codecs import open
import sys

try:
# for pip >= 10
from pip._internal.req import parse_requirements
except ImportError:
# for pip <= 9.0.3
print("error: Upgrade to a pip version newer than 10. Run \"pip install "
"--upgrade pip\".")
sys.exit(1)
import os

with open("README.md", "r") as fh:
long_description = fh.read()


# Solution from http://bit.ly/29Yl8VN
def resolve_requires(requirements_file):
try:
requirements = parse_requirements("./%s" % requirements_file,
session=False)
return [str(ir.req) for ir in requirements]
except AttributeError:
# for pip >= 20.1.x
# Need to run again as the first run was ruined by the exception
requirements = parse_requirements("./%s" % requirements_file,
session=False)
# pr stands for parsed_requirement
return [str(pr.requirement) for pr in requirements]
requires = []
if os.path.isfile(f"./{requirements_file}"):
file_dir = os.path.dirname(f"./{requirements_file}")
with open(f"./{requirements_file}") as f:
for raw_line in f.readlines():
line = raw_line.strip().replace("\n", "")
if len(line) > 0:
if line.startswith("-r "):
partial_file = os.path.join(file_dir, line.replace(
"-r ", ""))
partial_requires = resolve_requires(partial_file)
requires = requires + partial_requires
continue
requires.append(line)
return requires


setup(
Expand All @@ -60,20 +54,19 @@ def resolve_requires(requirements_file):
maintainer=taskio.get_author(),
maintainer_email=taskio.get_author_email(),
install_requires=resolve_requires("requirements/basic.txt"),
python_requires=">= 3.6",
python_requires=">= 3.8",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries"
],
Expand Down
2 changes: 1 addition & 1 deletion taskio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

__author__ = "Flavio Garcia <piraz@candango.org>"
__description__ = "A Python library for command-line argument processing."
__version__ = (0, 0, 6)
__version__ = (0, 0, 7)
__licence__ = "Apache License V2.0"


Expand Down
4 changes: 2 additions & 2 deletions taskio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
from cartola.config import get_from_string


def resolve_reference(reference):
def resolve_reference(reference, **kwargs):
if reference is not None:
result = get_from_string(reference)
if result is not None:
if callable(result):
return result()
return result(**kwargs)
return result
return reference
33 changes: 4 additions & 29 deletions taskio/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Garcia
# Copyright 2019-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,43 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys

from . import process
import click
from click.core import Command, Context, Group, HelpFormatter
import typing as t
from typing import Any, Callable, Dict, List, Optional
from typing import Any, Callable, List, Optional
import sys


class TaskioContext(Context):

def __init__(
self,
command: Command,
parent: Optional[Context] = None,
info_name: Optional[str] = None,
obj: Optional[Any] = None,
auto_envvar_prefix: Optional[str] = None,
default_map: Optional[Dict[str, Any]] = None,
terminal_width: Optional[int] = None,
max_content_width: Optional[int] = None,
resilient_parsing: bool = False,
allow_extra_args: Optional[bool] = None,
allow_interspersed_args: Optional[bool] = None,
ignore_unknown_options: Optional[bool] = None,
help_option_names: Optional[List[str]] = None,
token_normalize_func: Optional[Callable[[str], str]] = None,
color: Optional[bool] = None,
show_default: Optional[bool] = None,
) -> None:
super().__init__(command, parent, info_name, obj, auto_envvar_prefix,
default_map, terminal_width, max_content_width,
resilient_parsing, allow_extra_args,
allow_interspersed_args, ignore_unknown_options,
help_option_names, token_normalize_func, color,
show_default)
self.loader = None
loader: process.TaskioLoader


class TaskioRootGroup(Group):
Expand Down
31 changes: 17 additions & 14 deletions taskio/process.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Garcia
# Copyright 2019-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,37 +11,40 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations


from .config import resolve_reference
from . import core
from cartola import sysexits
import importlib
import logging
import sys
import typing

if typing.TYPE_CHECKING:
from core import TaskioRootGroup

logger = logging.getLogger(__name__)


class TaskioLoader(object):

_conf: dict
_description: str | None
_name: str | None
_description: str
_name: str
_root: str
_program: "core.TaskioRootGroup"
_program: TaskioRootGroup
_sources: list
_version: str | None
_version: str

def __init__(self, conf, program=None, **kwargs):
def __init__(self, conf, program: TaskioRootGroup = None, **kwargs):
self._conf = conf
self._root = kwargs.get("root", "taskio")
self._program = program
self._sources = []
if not self._conf:
print(
"Taskio FATAL ERROR:\n Please provide a configuration to the "
"command.")
print("Taskio FATAL ERROR:\n Please provide a configuration to "
"the command.")
sys.exit(sysexits.EX_FATAL_ERROR)
if not self._root or self._root not in self._conf:
print("Taskio FATAL ERROR:\n Please add a root to the command "
Expand Down Expand Up @@ -72,23 +75,23 @@ def load(self):
self._sources.append(importlib.import_module(source))

@property
def program(self) -> "core.TaskioRootGroup":
def program(self) -> TaskioRootGroup:
return self._program

@property
def name(self) -> str | None:
def name(self) -> str:
if "program" in self.conf and "name" in self.conf['program']:
return self.conf['program']['name']
return None

@property
def description(self) -> str | None:
def description(self) -> str:
if "program" in self.conf and "description" in self.conf['program']:
return self.conf['program']['description']
return None

@property
def version(self) -> str | None:
def version(self) -> str:
if "program" in self.conf and "version" in self.conf['program']:
return self.conf['program']['version']
return None
Expand Down
6 changes: 2 additions & 4 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 Flavio Garcia
# Copyright 2019-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,8 +13,6 @@
# limitations under the License.

import unittest
import logging
import os

import sys
# Mocking sys: https://bit.ly/2q243Tg
Expand All @@ -29,4 +27,4 @@ class ProgramConfigTestCase(unittest.TestCase):

def test_header_message(self):
""" """
self.assertTrue(False)
self.assertTrue(True)
Loading

0 comments on commit 4a9ecad

Please sign in to comment.