-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
Heyy @xmnlab , can you please review this? |
There was a problem hiding this 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 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 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:
and you should combine this for all the 3 scopes example
maybe you will need to have 3 makim files for that because the 3 different states for the global path
Create a new target here https://github.com/osl-incubator/makim/blob/main/.makim.yaml#L87 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 |
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 |
src/makim/makim.py
Outdated
@@ -93,6 +95,16 @@ def _call_shell_app(self, cmd): | |||
_new_session=True, | |||
) | |||
|
|||
self.working_directory_scoped = None # Reset scoped working directory |
There was a problem hiding this comment.
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:
Update the code as we have discussed in that last coding session. |
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! |
Mistakenly press |
I decided to create three files based on these combinations.
|
@abhijeetSaroha you can have 3 tests for absolute path for group as well (instead of just one). for example:
the same thing for the other configuration for global as well |
hey @abhijeetSaroha , it looks very nice, you are in right direction! |
@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 ? |
@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!! |
@xmnlab , Now, It's creating problem different for macos and ubuntu. In macos testing, it shows that parent directory is |
@abhijeetSaroha , instead of using the code for setup should go to a specific target, you can call that let me know if you need more details |
you can have the setup in a group called setup and the target could be called folders |
@abhijeetSaroha 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())
```
|
@xmnlab If you have time, please review the |
Looks really nice. We don't need the section "Benefits". Could you remove that please? Other than that, It looks great. |
Removed the section of |
🎉 This PR is included in version 1.9.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Changes Made:
_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