Skip to content

Commit

Permalink
Merge pull request #24 from depends-on/subdir-container
Browse files Browse the repository at this point in the history
add subdir support in container mode
  • Loading branch information
fredericlepied authored Sep 19, 2023
2 parents 82813fc + 4eaec7c commit 477b903
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ The action is extracting all the Pull Requests that are declared in
the description of the Pull Request with `Depends-On: <PR url>`
syntax.

If you need to specify a subdir for a particular PR, use the following syntax:

```txt
Depends-On: <PR url>?subdir=<subdir path>
```

It then injects the needed changes in the code to use the other Pull Requests.

### Go lang
Expand Down
13 changes: 12 additions & 1 deletion python.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def lookup_name(fname):
"Lookup the name of a module"
if os.path.exists(fname):
print(f"Looking up name in {fname}", file=sys.stderr)
with open(fname, "r", encoding="UTF-8") as in_stream:
for line in in_stream.readlines():
match = re.match(r"^\s*name\s*=\s*['\"](.*?)['\"]\s*,", line)
Expand Down Expand Up @@ -48,6 +49,10 @@ def process_python_requirements(main_dir, dirs, container_mode):
if container_mode:
# doc at https://pip.pypa.io/en/stable/cli/pip_install/#git
pkg = f"{mod} @ git+{module_dirs[mod]['fork_url']}@{module_dirs[mod]['branch']}"
if "subdir" in module_dirs[mod]:
pkg += (
f"#egg=subdir&subdirectory={module_dirs[mod]['subdir']}"
)
print(
f"Replacing {mod} in requirements.txt with {pkg}",
file=sys.stderr,
Expand Down Expand Up @@ -86,7 +91,13 @@ def process_python_pyproject(main_dir, dirs, container_mode):
mod = match.group(1)
if container_mode:
# doc at https://python-poetry.org/docs/dependency-specification/#git-dependencies
pkg = f"{mod} = {{ git = \"{module_dirs[mod]['fork_url']}\", branch = \"{module_dirs[mod]['branch']}\" }}"
pkg = f"{mod} = {{ git = \"{module_dirs[mod]['fork_url']}\", branch = \"{module_dirs[mod]['branch']}\""
if "subdir" in module_dirs[mod]:
pkg += (
f", subdirectory = \"{module_dirs[mod]['subdir']}\" }}"
)
else:
pkg += " }"
print(
f"Replacing {mod} in pyproject.toml with {pkg}",
file=sys.stderr,
Expand Down
2 changes: 1 addition & 1 deletion stage1.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def main(check_mode):

nb_unmerged_pr = 0
for depends_on_url in depends_on:
merged = extract_depends_on(depends_on_url, check_mode)
merged = extract_depends_on(depends_on_url.strip(), check_mode)
if not merged:
nb_unmerged_pr += 1

Expand Down

0 comments on commit 477b903

Please sign in to comment.