diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index a6b1b1a..bfa0acf 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -7,8 +7,8 @@ jobs: steps: - run: python --version - run: curl -sSL https://install.python-poetry.org | python3 - -# - run: cp /home/runner/work/2024/2024/Basic/Basic_Of_Python/pyproject.toml . -# - run: poetry install + - run: cd ${{ github.workspace }}/Basic/Basic_Of_Python + - run: poetry install - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." diff --git a/Basic/Basic_Of_Python/basic_of_python/__init__.py b/Basic/Basic_Of_Python/basic_of_python/__init__.py deleted file mode 100644 index 62536e4..0000000 --- a/Basic/Basic_Of_Python/basic_of_python/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# This allows you to import prime_numbers directly from prime_module -from .prime_numbers import prime_numbers diff --git a/Basic/Basic_Of_Python/src/__init__.py b/Basic/Basic_Of_Python/src/__init__.py new file mode 100644 index 0000000..74a1793 --- /dev/null +++ b/Basic/Basic_Of_Python/src/__init__.py @@ -0,0 +1,2 @@ +"""This allows you to import prime_numbers directly from prime_module.""" +from .prime_numbers import prime_numbers diff --git a/Basic/Basic_Of_Python/src/occurrence_char.py b/Basic/Basic_Of_Python/src/occurrence_char.py new file mode 100644 index 0000000..68cc0aa --- /dev/null +++ b/Basic/Basic_Of_Python/src/occurrence_char.py @@ -0,0 +1,101 @@ +"""This module is to check occurances of character.""" + +import argparse +import logging + + +# from Basic +# from .configs.occurrence_config import (INPUT_STRING) + + +def count_of_occurrence(value): + """ + Determine if a number is prime. + + Args: + x (int): The number to check for primality + + Returns: + str: A message stating whether the number is prime or not. + + """ + d = {} + for i in value: + if i not in d: + d[i] = + 1 + else: + d[i] = 1 + return d + + +class OccurrenceChar: + """HelloArg.""" + + def __init__(self): + """ + Get Instance of OccurrenceCharacter. + + :param logger: Logger + :param input_string: input value + """ + logging.basicConfig(level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s = %(message)s') + self.logger = logging.getLogger(__name__) + + self.parser = argparse.ArgumentParser(description="Occurrence of Characters") + self.parser.add_argument('--verbose', action='store_true', help='Enable verbose logging') + self.parser.add_argument('--name', type=str, required=True, help="String to be process") + + def parse_arguments(self): + """ + Determine if a number is prime. + + Args: + x (int): The number to parse arguments + + Returns: + str: arguments. + + """ + args = self.parser.parse_args() + if args.verbose: + self.logger.setLevel(logging.DEBUG) + else: + self.logger.setLevel(logging.INFO) + return args + + def run(self): + """ + Determine if a number is prime. + + Args: + x (int): The number to check for primality + + Returns: + str: A message stating whether the number is prime or not. + + """ + args = self.parse_arguments() + self.logger.debug('Arguments parsed: %s', args) + + # Example of using the parsed argument + self.logger.info('Hello, %s!', args.name) + + # Simulate some processing + try: + self.logger.debug('Starting processing...') + # Simulate processing step + out = count_of_occurrence(args.name) + # result = f"Output {out}" + self.logger.info("Here you GO :") + for key, value in out.items(): + self.logger.info("%s is occurring %s times", key, value) + + # self.logger.info('Processing complete: %s', result) + except (TypeError, KeyError) as e: + self.logger.error('A specific error occurred: %s', e) + + +if __name__ == "__main__": + app = OccurrenceChar() + app.run() diff --git a/Basic/Basic_Of_Python/basic_of_python/prime_numbers.py b/Basic/Basic_Of_Python/src/prime_numbers.py similarity index 100% rename from Basic/Basic_Of_Python/basic_of_python/prime_numbers.py rename to Basic/Basic_Of_Python/src/prime_numbers.py diff --git a/Basic/Basic_Of_Python/tests/prime_test.py b/Basic/Basic_Of_Python/tests/prime_test.py index 7984c0f..e5e3d42 100644 --- a/Basic/Basic_Of_Python/tests/prime_test.py +++ b/Basic/Basic_Of_Python/tests/prime_test.py @@ -1,5 +1,5 @@ import pytest -from basic_of_python.prime_numbers import prime_numbers +from src.prime_numbers import prime_numbers def test_prime_number(): assert prime_numbers(11) == "11 is Prime Number"