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

feat: Add working-directory to the target, group and global scope #65

Merged
merged 32 commits into from
Dec 8, 2023

Conversation

abhijeetSaroha
Copy link
Collaborator

@abhijeetSaroha abhijeetSaroha commented Nov 29, 2023

Changes Made:

  • Modified the _call_shell_app and _load_working_directory methods to address the working directory issue.

Details:

  • Refactored the _call_shell_app method to dynamically set the working directory based on the target, group, or global scope.

  • Updated the _load_working_directory method to handle both absolute and relative paths appropriately.

  • The _call_shell_app method now utilizes the correct working directory based on the priority of target, group, and global settings.

  • The _load_working_directory method has been improved to handle various scenarios for setting the working directory.

Solves #48

@abhijeetSaroha
Copy link
Collaborator Author

Heyy @xmnlab , can you please review this?

Copy link
Member

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in _call_shell_app function: https://github.com/osl-incubator/makim/pull/65/files#diff-c70963049bfd82892ce83a4cc6a34fa99a9975e7cbbe93418a2d2fcfa2ed405aR94-R104

you shouldn't be doing this there. _load_working_directory should be handling all the step for setting a variable in the class with the value of the working_directory to be used.

it is kind of the idea of single responsible one function should be responsible for just one thing.

for env we have the following class attributes:

    env: dict = {}  # initial env
    env_scoped: dict = {}  # current env

so I think you can have something similar:

    working_directory: dict = {}  # initial working_directory
    working_directory_scoped: dict = {}  # current working_directory

additionally, pay attention in the order of the resolution for the working directory. in a makim file you can have the working directory in the global scope, group scope and target scope .. you should resolve that in that order ... so instead of if/elif ... you should use just if for each one ... you can use _load_scoped_data as a reference about how to resolve that in the correct order

I know that it is too much information, but let me know if you have any questions

@abhijeetSaroha
Copy link
Collaborator Author

  • Improved the logic for determining the working directory, making the code more readable and maintainable.
  • Set the scoped working directory appropriately based on the resolved path.

@xmnlab
Copy link
Member

xmnlab commented Nov 30, 2023

@abhijeetSaroha could you please create some tests? you can create a new makim file for test based on this other one: https://github.com/osl-incubator/makim/blob/main/tests/.makim-env.yaml

it could be tests/.makim-working-directory.yaml

some ideas for the tests (pseudo makim file, not the real one):

global:
- working directory: /tmp
- groups:
  group-setup:
    working directory: group1
    targets:
      target-setup:
        run: |
          # create here all the paths necessary for the test ex:
          mkdir -p /tmp/group1
  group1:
   targets:
    target-1:  # NO  working directory
       run: |
          import os
          assert os.getcwd() == "/tmp/group1"

    target-2 working directory: target2
      run: |
        import os
        assert os.getcwd() == "/tmp/group1/target2"

this is just an idea of example, try to create different kind of tests for the following states:

  • absolute path
  • relative path
  • no path

and you should combine this for all the 3 scopes example

  • global absolute path, group relative path, target no path
  • global absolute path, group relative path, target absolute path
  • global absolute path, group relative path, target relative path
  • global absolute path, group absolute path, target no path
  • global absolute path, group no path, target no path
  • ...

maybe you will need to have 3 makim files for that because the 3 different states for the global path

  • tests/.makim-working-directory-absolute.yaml
  • tests/.makim-working-directory-relative.yaml
  • tests/.makim-working-directory-no-path.yaml

Create a new target here https://github.com/osl-incubator/makim/blob/main/.makim.yaml#L87
for the working-directory test, in the beginning of your test call the target for the setup, so it will create all the directory first

additionally, update this target in order to add your new targets for working directory smoke tests: https://github.com/osl-incubator/makim/blob/main/.makim.yaml#L69C7-L69C12

@xmnlab
Copy link
Member

xmnlab commented Nov 30, 2023

additionally, please create a new step in the CI workflow for testing the working directory feature. example: https://github.com/osl-incubator/makim/blob/main/.github/workflows/main.yaml#L86-L87

@@ -93,6 +95,16 @@ def _call_shell_app(self, cmd):
_new_session=True,
)

self.working_directory_scoped = None # Reset scoped working directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of setting working directory here,
please do it inside the change_target and change_group_data methods.
use the shell_app flow as a reference:

src/makim/makim.py Outdated Show resolved Hide resolved
src/makim/makim.py Outdated Show resolved Hide resolved
@abhijeetSaroha
Copy link
Collaborator Author

Update the code as we have discussed in that last coding session.

@abhijeetSaroha
Copy link
Collaborator Author

/tests/,makim-working-directory-absolute.yaml

version: 1.0
working-directory: "/tmp/tests"

groups:
  group-relative:
    working-directory: "group1"
    targets:
      target-no-path:
        help: Test global absolute path, group relative path, target no path
        run: |
          import os
          assert os.getcwd() == "/tmp/tests/group1"

      target-absoulte:
        working-directory: "/tmp"
        help: Test global absolute path, group relative path, target absolute path
        run: |
          import os
          assert os.getcwd() == "/tmp"

      target-realtive:
        working-directory: "target3"
        help: Test global absolute path, group relative path, target relative path
        run: |
          import os
          assert os.getcwd() == "/tmp/tests/group1/target3"

      target-no-path:
        help: Test global absolute path, group relative path, target no path
        run: |
          import os
          assert os.getcwd() == "/tmp/tests/group1"

  group-absolute:
    working-directory: "/tmp/tests/group2"
    targets:
      target-no-path:
        help: Test global absolute path, group absolute path, target no path
        run: |
          import os 
          assert os.getcwd() == "/tmp/tests/group2"

  group-no-path:
    targets:
      target-no-path:
        help: Test global absolute path, group no path, target no path
        run: |
          import os
          assert os.getcwd() == "/tmp/tests"

      target-absolute:
        working-directory: "/tmp"
        help: Test global absolute path, group no path, target absolute path
        run: |
          import os
          assert os.getcwd() == "/tmp"

      target-relative:
        working-directory: "group1/target3"
        help: est global absolute path, group no path, target relative path
        run: |
          import os
          assert os.getcwd() == "/tmp/tests/group1/target3"

Can you please review this, what are your thoughts about this?

I know run command is almost same for everyone, but I think for testing, it will be good.

Any other suggestion!

@abhijeetSaroha
Copy link
Collaborator Author

Mistakenly press Close with comment instead of Comment.

@abhijeetSaroha
Copy link
Collaborator Author

I decided to create three files based on these combinations.

  1. tests/.makim-working-directory-absolute.yaml:

     * Global Absolute Path, Group Relative Path, Target No Path
     * Global Absolute Path, Group Relative Path, Target Absolute Path
     * Global Absolute Path, Group Relative Path, Target Relative Path
     * Global Absolute Path, Group Absolute Path, Target No Path
     * Global Absolute Path, Group No Path, Target No Path
     * Global Absolute Path, Group No Path, Target Absolute Path
     * Global Absolute Path, Group No Path, Target Relative Path
    
  2. tests/.makim-working-directory-relative.yaml:

     * Global Relative Path, Group Relative Path, Target No Path
     * Global Relative Path, Group Relative Path, Target Absolute Path
     * Global Relative Path, Group Relative Path, Target Relative Path
     * Global Relative Path, Group Absolute Path, Target No Path
     * Global Relative Path, Group No Path, Target No Path
     * Global Relative Path, Group No Path, Target Absolute Path
     * Global Relative Path, Group No Path, Target Relative Path
    
  3. tests/.makim-working-directory-no-path.yaml:

     * Global No Path, Group Relative Path, Target No Path
     * Global No Path, Group Relative Path, Target Absolute Path
     * Global No Path, Group Relative Path, Target Relative Path
     * Global No Path, Group Absolute Path, Target No Path
     * Global No Path, Group No Path, Target No Path
     * Global No Path, Group No Path, Target Absolute Path
     * Global No Path, Group No Path, Target Relative Path
    

@xmnlab
Copy link
Member

xmnlab commented Dec 4, 2023

@abhijeetSaroha you can have 3 tests for absolute path for group as well (instead of just one).

for example:

  • Global Absolute Path, Group Absolute Path, Target No Path (as you already mentioned)
  • Global Absolute Path, Group Absolute Path, absolute path
  • Global Absolute Path, Group Absolute Path, relative path

the same thing for the other configuration for global as well

@xmnlab
Copy link
Member

xmnlab commented Dec 4, 2023

hey @abhijeetSaroha , it looks very nice, you are in right direction!
please add a step in the CI workflow for your new test, similar to this one: https://github.com/osl-incubator/makim/blob/main/.github/workflows/main.yaml#L86-L87

@abhijeetSaroha
Copy link
Collaborator Author

abhijeetSaroha commented Dec 5, 2023

@xmnlab, It shows error for not finding the file / directory, which I have used and created for testing the working-directory-absolute-path. So, now I have to upload those directory also? or Is there any solution which should I approach or may I change the directory names in the testing file ?

@xmnlab
Copy link
Member

xmnlab commented Dec 5, 2023

@abhijeetSaroha as we discused before, we need a setup step before the tests. So maybe the easiest way for now, wpuld be create all the folders used by your tests in your in the .makim.yaml file inside the target you created at the beginning of the "run".

Use this example as reference: "mkdir -p /path/to/folder/"

Let me know if you need more explanation.

Thanks!!

@abhijeetSaroha
Copy link
Collaborator Author

@xmnlab , Now, It's creating problem different for macos and ubuntu. In macos testing, it shows that parent directory is /private but in linux, that's not the case.

@xmnlab
Copy link
Member

xmnlab commented Dec 5, 2023

@abhijeetSaroha , instead of using /private, use /tmp

the code for setup should go to a specific target, you can call that setup and call that as a dependency for each other target.

let me know if you need more details

@xmnlab
Copy link
Member

xmnlab commented Dec 5, 2023

you can have the setup in a group called setup and the target could be called folders

@xmnlab xmnlab changed the title WIP: add working-directory to the target, group and global scope feat: Add working-directory to the target, group and global scope Dec 7, 2023
@xmnlab
Copy link
Member

xmnlab commented Dec 7, 2023

@abhijeetSaroha
now it is just missing some documentation
please create a new file at https://github.com/osl-incubator/makim/tree/main/docs
it could be called features.md let use that to describe all the new features

You can add the following information (just an idea of structure, feel free to improve that):

# Working Directory

attribute: working-directory
scopes: global, group, target

## Example

```yaml

version: 1.0
working-directory: /tmp/tests

groups:
  group1:
    working-directory: group1
    targets:
      target-no-path:
        help: example of the usage of working-directory attribute
        working-directory: target1
        run: |
          import os
          print(os.getcwd())


```

@abhijeetSaroha
Copy link
Collaborator Author

@xmnlab If you have time, please review the features.md file.

@xmnlab
Copy link
Member

xmnlab commented Dec 8, 2023

Looks really nice. We don't need the section "Benefits". Could you remove that please? Other than that, It looks great.

@abhijeetSaroha
Copy link
Collaborator Author

Removed the section of Benefit

@xmnlab xmnlab merged commit 3fbd61e into osl-incubator:main Dec 8, 2023
8 checks passed
Copy link

github-actions bot commented Dec 8, 2023

🎉 This PR is included in version 1.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants