Skip to content

Commit

Permalink
Merge pull request #146 from shay-te/CL-6
Browse files Browse the repository at this point in the history
Cl 6 - fix core-lib creation command line
  • Loading branch information
oren-una authored Sep 3, 2024
2 parents 8c8a8af + cc3037d commit f9fd414
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
24 changes: 22 additions & 2 deletions core_lib/core_lib_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import logging
import os
from core_lib.alembic.alembic import Alembic
from hydra import compose, initialize
import hydra
from hydra import compose, initialize, initialize_config_dir
import click
from dotenv import load_dotenv
from core_lib.helpers.validation import is_int
from core_lib_generator.core_lib_config_generate_yaml import generate_core_lib_yaml
from core_lib_generator.core_lib_generator_from_yaml import CoreLibGenerator


def list_to_string(lst: list):
Expand Down Expand Up @@ -36,6 +39,23 @@ def load_config():
def main():
pass

@click.command()
@click.option('--yaml', help='name of new revision')
def generate(yaml):
if yaml:
if not os.path.exists(yaml):
click.echo(f"yaml file was not found\nmake sure you have the right path (including .yaml or other extenions)\npath:{yaml}\nexiting now...")
exit()
else:
yaml_file = generate_core_lib_yaml()
yaml = f'{os.getcwd()}/{yaml_file}'

file_name = os.path.basename(yaml)
absolute_folter_path = os.path.dirname(yaml)
hydra.core.global_hydra.GlobalHydra.instance().clear()
initialize_config_dir(config_dir=absolute_folter_path)
config = hydra.compose(file_name)
CoreLibGenerator(config).run_all()

@click.command()
@click.option('--rev', required=True, help=' '.join(get_rev_options()))
Expand Down Expand Up @@ -78,5 +98,5 @@ def migrate(rev, name, env_file):
# CoreLibGenerate().generate(list_to_string(value))
#
# main.add_command(create)
# main.add_command(generate)
main.add_command(generate)
main.add_command(migrate)
3 changes: 3 additions & 0 deletions core_lib_generator/config_collectors/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ def _generate_db_config(
migrate: bool = False
) -> dict:
config = _build_url(db_type, db_name, db_username, db_password, db_port, db_host)
if db_type:
db_type: str = 'core_lib.connection.sql_alchemy_connection_registry.SqlAlchemyConnectionRegistry'
return {
'env': config['env'],
'connection': {
'type': db_type,
'key': db_name,
'migrate': migrate,
'log_queries': db_log_queries,
Expand Down
4 changes: 2 additions & 2 deletions core_lib_generator/core_lib_config_generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_yaml_file(core_lib_name: str):
OmegaConf.save(config=conf, f=file.name)


def get_data_from_user():
def generate_core_lib_yaml():
core_lib_name = any_to_pascal(input_str('Please enter the name for your Core-lib', 'MyCoreLib'))

want_cache = input_yes_no('\nWould you like to use cache?', True)
Expand All @@ -125,4 +125,4 @@ def get_data_from_user():


if __name__ == '__main__':
get_data_from_user()
generate_core_lib_yaml()
4 changes: 4 additions & 0 deletions tests/test_generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def has_special_chars(input_string: str):

class TestGenerateData(unittest.TestCase):

def test_generate_yaml_connection(self):
from core_lib_generator.core_lib_config_generate_yaml import _get_data_layers_config
_get_data_layers_config()

def test_generate_string(self):
string = generate_random_string()
self.assertEqual(10, len(string))
Expand Down

0 comments on commit f9fd414

Please sign in to comment.