Skip to content

Commit

Permalink
Bugfix 92 - exclude local modules from requirements (#96)
Browse files Browse the repository at this point in the history
* Removed local modules from requirements
  • Loading branch information
marcelotrevisani authored Mar 11, 2020
1 parent 9bcae81 commit 6f86b4e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions grayskull/pypi/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ def _format_dependencies(all_dependencies: List, name: str) -> List:
re_remove_space = re.compile(r"([<>!=]+)\s+")
re_remove_tags = re.compile(r"\s*(\[.*\])", re.DOTALL)
for req in all_dependencies:

match_req = re_deps.match(req)
deps_name = req
if deps_name.replace("-", "_") == name.replace("-", "_"):
Expand Down
15 changes: 14 additions & 1 deletion grayskull/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ast
import os
from functools import lru_cache
from glob import glob
from typing import List


Expand Down Expand Up @@ -44,9 +46,20 @@ def get_vendored_dependencies(script_file: str) -> List:
"""
all_std_modules = get_std_modules()
all_modules_used = get_all_modules_imported_script(script_file)
local_modules = get_local_modules(os.path.dirname(script_file))
vendored_modules = []
for dep in all_modules_used:
if dep in all_std_modules:
if dep in local_modules or dep in all_std_modules:
continue
vendored_modules.append(dep.lower())
return vendored_modules


@lru_cache(maxsize=20)
def get_local_modules(sdist_folder: str) -> List:
result = []
for py_file in glob("*.py"):
if py_file == "setup.py":
continue
result.append(os.path.splitext(py_file)[0])
return result
3 changes: 2 additions & 1 deletion tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_download_pkg_sdist(pkg_pytest):
def test_ciso_recipe():
recipe = PyPi(name="ciso", version="0.1.0")
assert sorted(recipe["requirements"]["host"]) == sorted(
["cython", "numpy", "pip", "python", "versioneer"]
["cython", "numpy", "pip", "python"]
)
assert sorted(recipe["requirements"]["run"]) == sorted(
["cython", "python", "<{ pin_compatible('numpy') }}"]
Expand Down Expand Up @@ -437,3 +437,4 @@ def test_get_test_imports():
def test_nbdime_license_type():
recipe = PyPi(name="nbdime", version="2.0.0")
assert recipe["about"]["license"] == "BSD-3-Clause"
assert "setupbase" not in recipe["requirements"]["host"]

0 comments on commit 6f86b4e

Please sign in to comment.