Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Implement globbing for script_dirs #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Haegi
Copy link
Contributor

@Haegi Haegi commented Jun 2, 2021

Fixes #15
This would be a globbing approach to make the script_dirs parameter more configurable.

Example

Pipeline

from pipeline_dsl import Pipeline

with Pipeline("test", script_dirs={"yaml_files": "*.yaml"}) as pipeline:
    with pipeline.job("list-yaml-files") as job:
        @job.task()
        def list_yaml_files():
            print(pipeline.script_dir("yaml_files"))

Output

Running: list-yaml-files
['first-yaml-files.yaml', 'second-yaml-file.yaml']
None

@Haegi Haegi linked an issue Jun 2, 2021 that may be closed by this pull request
@@ -35,7 +36,8 @@ def __init__(self, name, image_resource={"type": "registry-image", "source": {"r
self.init_dirs[os.path.basename(dir)] = dir
else:
for key, script in script_dirs.items():
self.init_dirs[key] = os.path.abspath(os.path.join(dirname, script))
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it a bit confusing that glob only work if you do not a use a list? Is there a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I should implement that as well. But I didn't implement it because we haven't decided if we want to go with the globbing approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can go that way. AFAIK, I was the only one promoting the other way, right :) The only think is, that this approach is not compatible, so we would have to change our pipelines. Otherwise, we might end up with binaries in the pipeline, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If implemented globbing for script_dirs list in 36b7efc.
As there is no option for the user to specify a key, the key will be created by:

  • using the dirname if no specific/direct file is specified (e.g. glob or directory)
    • Example: test for test/*.yaml or test for test/
  • using the specified file as key (e.g. test.yaml)
    • Example: test.yaml for test.yaml or test/test.yaml' for test/test.yaml`

@@ -109,8 +107,13 @@ def filter(tarinfo):
return tarinfo

for dir_concourse, dir_local in init_dirs:
dir_local = os.path.abspath(dir_local)
tar.add(dir_local, arcname=dir_concourse, filter=filter)
if isinstance(dir_local, list):
Copy link
Contributor

Choose a reason for hiding this comment

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

globed is a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because it can contain multiple files.

pipeline_dsl/test/test_pipeline.py Show resolved Hide resolved
@c0d1ngm0nk3y
Copy link
Contributor

@Haegi Did I get it right - if you want several files, you need something like folder/*.[sh|py], right?

@Haegi
Copy link
Contributor Author

Haegi commented Jun 16, 2021

@Haegi Did I get it right - if you want several files, you need something like folder/*.[sh|py], right?

@c0d1ngm0nk3y Unfortunately, the python glob module doesn't support multiple file types.pathlib.Path().glob() would be an alternative but this module does only support relative paths.

@Haegi
Copy link
Contributor Author

Haegi commented Jun 21, 2021

I've found out that pathlib.Path().glob() also doesn't work as expected. To continue I would propose to:

  • either leave it like it is and search later for a solution
  • implement it on our own
  • or use wcmatch extended globbing capabilities (e.g. *.@(py|sh)) which would work but this would introduce a dependency. For more details see here.

@c0d1ngm0nk3y What's your opinion on how we should continue?

@c0d1ngm0nk3y
Copy link
Contributor

  • implement it on our own

Sounds good to me. I doubt that it will be a problem. But if, we can tackle it then…

Co-authored-by: Benjamin Haegenlaeuer <[email protected]>
@Haegi Haegi marked this pull request as ready for review June 22, 2021 14:21
@phil9909
Copy link
Contributor

phil9909 commented Jul 9, 2021

Is this PR mixing two concerns?

  • Supporting globs for script_dir
  • Supporting lists for script_dir

Why do it in one PR?

If we do it in one PR, we should transform the list into an object instead of having multiple isinstance(x, list) calls.

Lets sort this out in a call.

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

Successfully merging this pull request may close these issues.

Allow arbitrary file for script_dirs
4 participants