Repository: conda-incubator/grayskull
Pull request #292 (2022-02-08 06:32:45)

Fix version placeholder 
Fix version placeholder for source url when fetching the package from github

codecov-commenter: # [Codecov](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#292](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (1bf583b) into [main](https://codecov.io/gh/conda-incubator/grayskull/commit/9c3242e1667135f34875a6d9e44d53b83ab3d9ba?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (9c3242e) will **increase** coverage by `0.17%`.
> The diff coverage is `93.50%`.

[![Impacted file tree graph](https://codecov.io/gh/conda-incubator/grayskull/pull/292/graphs/tree.svg?width=650&height=150&src=pr&token=ziE8y5VBkG&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

```diff
@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   91.30%   91.48%   +0.17%     
==========================================
  Files          17       16       -1     
  Lines        1576     1503      -73     
==========================================
- Hits         1439     1375      -64     
+ Misses        137      128       -9     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `91.48% <93.50%> (+0.17%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [setup.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c2V0dXAucHk=) | `0.00% <0.00%> (ø)` | |
| [grayskull/license/discovery.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL2xpY2Vuc2UvZGlzY292ZXJ5LnB5) | `95.62% <44.44%> (-1.52%)` | :arrow_down: |
| [grayskull/strategy/abstract\_strategy.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL3N0cmF0ZWd5L2Fic3RyYWN0X3N0cmF0ZWd5LnB5) | `83.33% <83.33%> (ø)` | |
| [grayskull/utils.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL3V0aWxzLnB5) | `89.67% <86.08%> (-10.33%)` | :arrow_down: |
| [grayskull/base/github.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL2Jhc2UvZ2l0aHViLnB5) | `88.67% <88.67%> (ø)` | |
| [grayskull/\_\_main\_\_.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL19fbWFpbl9fLnB5) | `95.29% <92.10%> (-2.86%)` | :arrow_down: |
| [grayskull/base/factory.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL2Jhc2UvZmFjdG9yeS5weQ==) | `91.17% <93.33%> (+1.17%)` | :arrow_up: |
| [grayskull/strategy/py\_base.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL3N0cmF0ZWd5L3B5X2Jhc2UucHk=) | `95.11% <95.11%> (ø)` | |
| [grayskull/config.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL2NvbmZpZy5weQ==) | `98.27% <98.27%> (ø)` | |
| [grayskull/strategy/pypi.py](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Z3JheXNrdWxsL3N0cmF0ZWd5L3B5cGkucHk=) | `98.72% <98.72%> (ø)` | |
| ... and [7 more](https://codecov.io/gh/conda-incubator/grayskull/pull/292/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [3a17579...1bf583b](https://codecov.io/gh/conda-incubator/grayskull/pull/292?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/grayskull/strategy/pypi.py b/grayskull/strategy/pypi.py
index f756a34..71c9577 100644
--- a/grayskull/strategy/pypi.py
+++ b/grayskull/strategy/pypi.py
@@ -75,11 +75,18 @@ def merge_pypi_sdist_metadata(
     all_packages_names = get_val("packages")
     if not all_packages_names:
         all_packages_names = get_val("py_modules")
+
+    source_section = get_val("source")
+    if not config.from_local_sdist:
+        source_section["url"] = adjust_source_url_to_include_placeholders(
+            source_section["url"], get_val("version")
+        )
+
     return {
         "author": get_val("author"),
         "name": get_val("name"),
         "version": get_val("version"),
-        "source": get_val("source"),
+        "source": source_section,
         "packages": all_packages_names,
         "url": get_val("url"),
         "classifiers": get_val("classifiers"),
@@ -103,6 +110,12 @@ def merge_pypi_sdist_metadata(
     }
 
 
+def adjust_source_url_to_include_placeholders(url, version):
+    url_split = url.rsplit("/", 1)
+    url_split[-1] = url_split[-1].replace(version, "{{ version }}")
+    return "/".join(url_split)
+
+
 def get_url_filename(metadata: dict, default: Optional[str] = None) -> str:
     """Method responsible to get the filename and right extension to add
     to the pypi url


Test patch:
diff --git a/tests/test_github_recipes.py b/tests/test_github_recipes.py
new file mode 100644
index 0000000..a24ab79
--- /dev/null
+++ b/tests/test_github_recipes.py
@@ -0,0 +1,24 @@
+import pytest
+
+from grayskull.__main__ import create_python_recipe
+from grayskull.strategy.pypi import adjust_source_url_to_include_placeholders
+
+
+@pytest.mark.github
+def test_289_github_url_version_placeholder():
+    recipe, _ = create_python_recipe(
+        "https://github.com/spdx/spdx-license-matcher", version="2.1"
+    )
+    assert (
+        recipe["source"]["url"]
+        == "https://github.com/spdx/spdx-license-matcher/archive/v{{ version }}.tar.gz"
+    )
+
+
+def test_adjust_source_url_to_include_placeholders():
+    assert (
+        adjust_source_url_to_include_placeholders(
+            "https://github.com/spdx/spdx-license-matcher/archive/v2.1.tar.gz", "2.1"
+        )
+        == "https://github.com/spdx/spdx-license-matcher/archive/v{{ version }}.tar.gz"
+    )