Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: initialiser package #966

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gruzewski
Copy link
Contributor

Follow up from #964

Proposed Changes

Small refactoring of the initialiser.py package. Changes:

  • extracted generating a tree structure to a dedicated function
  • changed a bit output of initialise_skeleton for better visibility (see "Testing" section below)

Testing:

  • Manually ran kapitan init --directory multiple times

    State before each run:

     ➜  kapitan git:(master) tree /tmp/kapitan                                                                                                                                                            
     git:(master|)
     /tmp/kapitan
     ├── file_that_existed_before.txt
     └── this_existed_before
         └── file.txt
     
     2 directories, 2 files

    Old:

     ➜  kapitan git:(master) poetry run kapitan init --directory /tmp/kapitan                                                                                                                             git:(master|)
     creating /tmp/kapitan/components
     creating /tmp/kapitan/components/other_component
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/components/other_component/__init__.py -> /tmp/kapitan/components/other_component
     creating /tmp/kapitan/components/my_component
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/components/my_component/my_component.jsonnet -> /tmp/kapitan/components/my_component
     creating /tmp/kapitan/inventory
     creating /tmp/kapitan/inventory/targets
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/inventory/targets/my_target.yml -> /tmp/kapitan/inventory/targets
     creating /tmp/kapitan/inventory/classes
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/inventory/classes/common.yml -> /tmp/kapitan/inventory/classes
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/inventory/classes/my_component.yml -> /tmp/kapitan/inventory/classes
     creating /tmp/kapitan/templates
     creating /tmp/kapitan/templates/docs
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/templates/docs/my_readme.md -> /tmp/kapitan/templates/docs
     creating /tmp/kapitan/templates/scripts
     copying /Users/jacek/Code/kapitan/kapitan/inputs/templates/templates/scripts/my_script.sh -> /tmp/kapitan/templates/scripts
     Populated /tmp/kapitan with:
     components
         other_component
             __init__.py
         my_component
             my_component.jsonnet
     inventory
         targets
             my_target.yml
         classes
             common.yml
             my_component.yml
     templates
         docs
             my_readme.md
         scripts
             my_script.sh
    
     ➜  kapitan_fork git:(refactor_initialiser_package) ✗ poetry run kapitan init --directory /tmp/kapitan                                                       git:(refactor_initialiser_package|✚2…1
     Populated /tmp/kapitan with:

    New:

    kapitan_fork git:(refactor_initialiser_package) ✗ poetry run kapitan init --directory /tmp/kapitan                                                       git:(refactor_initialiser_package|✚2…1
    Populated /tmp/kapitan with:
    ├── components
    │   ├── other_component
    │   │   └── __init__.py
    │   └── my_component
    │       └── my_component.jsonnet
    ├── inventory
    │   ├── targets
    │   │   └── my_target.yml
    │   └── classes
    │       ├── common.yml
    │       └── my_component.yml
    └── templates
        ├── docs
        │   └── my_readme.md
        └── scripts
            └── my_script.shkapitan_fork git:(refactor_initialiser_package) ✗ poetry run kapitan init --directory /tmp/kapitan                                                       git:(refactor_initialiser_package|✚2…1
    Populated /tmp/kapitan with:

@gruzewski gruzewski changed the title Refactor initialiser package refactor: initialiser package Mar 18, 2023
@MatteoVoges
Copy link
Contributor

MatteoVoges commented Apr 5, 2023

Hey @gruzewski , The new output looks so much better!!! Thank you for that. Could you merge the pull request that belong to the init command (#966 and #964) into a single one to keep track of all the changes?
I think we can just use os.system("tree path/to/print") call to achieve a tree output of a directory. This would simplify this change so much, that no tests are needed.

@gruzewski
Copy link
Contributor Author

Hey @gruzewski , The new output looks so much better!!! Thank you for that. Could you merge the pull request that belong to the init command (#966 and #964) into a single one to keep track of all the changes? I think we can just use os.system("tree path/to/print") call to achieve a tree output of a directory. This would simplify this change so much, that no tests are needed.

I can merge both, but it felt too big for review. Changes from #964 are showing because I used that branch as a base.

Regarding using os.system("tree path/to/print"), that is not feasible. tree is not installed by default on many OS (for instance, MacOS doesn't have it).

@MatteoVoges
Copy link
Contributor

@gruzewski We could use find on macOS to get the files and output them as a tree. Another solution would be using package directory-tree.
I think if you remove or merge the changes regarding copy_tree and fix the tests we are good to go!

@MatteoVoges MatteoVoges added the enhancement enhancement to an existing feature label Apr 20, 2023
@github-actions github-actions bot added the Stale label Nov 9, 2023
@github-actions github-actions bot removed the Stale label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement enhancement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants