Skip to content

Commit

Permalink
Add skip when path to other file provided (#6)
Browse files Browse the repository at this point in the history
* add path support

* add integration test

* lint

* add grep v

* fix id

* fix echo

* fix path

* remove -v

* Update minimum_dependency_generator.py

* lint
  • Loading branch information
gsheni authored May 11, 2021
1 parent d073eb5 commit 5e9e5c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
with:
requirements_paths: 'requirements.txt'
- name: Save the output minimum test requirements
run: printf "${{ steps.min_dep_gen_1.outputs.min_reqs }}" >> generated-min--test-reqs.txt
run: printf "${{ steps.min_dep_gen_1.outputs.min_reqs }}" >> generated-min-test-reqs.txt
- name: Verify output
run: |
echo "${{ steps.min_dep_gen_1.outputs.min_reqs }}" | grep -c "packaging==20.9"
echo "${{ steps.min_dep_gen_1.outputs.min_reqs }}" | grep -c "requests==2.25.1"
echo "${{ steps.min_dep_gen_1.outputs.min_reqs }}" | grep -c "wheel==0.36.2"
- name: Run Minimum Dependency Generator with 2 files
- name: Run Minimum Dependency Generator with 2 files, no other path reference
id: min_dep_gen_2
uses: ./
with:
Expand All @@ -48,3 +48,19 @@ jobs:
echo "${{ steps.min_dep_gen_2.outputs.min_reqs }}" | grep -c "pytest==6.2.4"
echo "${{ steps.min_dep_gen_2.outputs.min_reqs }}" | grep -c "isort==5.8.0"
echo "${{ steps.min_dep_gen_2.outputs.min_reqs }}" | grep -c "pytest-cov==2.11.1"
- name: Create other requirements file
run: echo -e "-r core-requirements.txt \nnumpy>=1.13.1" > other-requirements.txt
- name: Run Minimum Dependency Generator with 2 files, path reference
id: min_dep_gen_3
uses: ./
with:
requirements_paths: 'requirements.txt other-requirements.txt'
- name: Save the output minimum test and core requirements
run: printf "${{ steps.min_dep_gen_3.outputs.min_reqs }}" >> generated-min-other-reqs.txt
- name: Verify output
run: |
echo "${{ steps.min_dep_gen_3.outputs.min_reqs }}" | grep -c "packaging==20.9"
echo "${{ steps.min_dep_gen_3.outputs.min_reqs }}" | grep -c "requests==2.25.1"
echo "${{ steps.min_dep_gen_3.outputs.min_reqs }}" | grep -c "wheel==0.36.2"
echo "${{ steps.min_dep_gen_3.outputs.min_reqs }}" | grep -c "numpy==1.13.1"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
other-requirements.txt

docs/source/generated/
*.dirlock
*.~lock*
Expand Down
16 changes: 15 additions & 1 deletion minimum_dependency_generator/minimum_dependency_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def remove_comment(requirement):
return requirement


def is_requirement_path(requirement):
if '.txt' in requirement and '-r' in requirement:
return True
return False


def find_operator_version(package, operator):
version = None
for x in package.specifier:
Expand All @@ -43,9 +49,13 @@ def determine_package_name(package):


def find_min_requirement(requirement, python_version="3.7", major_python_version="py3"):
if is_requirement_path(requirement):
# skip requirement paths
# ex '-r core_requirements.txt'
return
requirement = remove_comment(requirement)
if not verify_python_environment(requirement):
return None
return
if ">=" in requirement:
# mininum version specified (ex - 'package >= 0.0.4')
package = Requirement(requirement)
Expand Down Expand Up @@ -79,6 +89,10 @@ def generate_min_requirements(requirements_paths):
with open(path) as f:
requirements.extend(f.readlines())
for req in requirements:
if is_requirement_path(req):
# skip requirement paths
# ex '-r core_requirements.txt'
continue
package = Requirement(remove_comment(req))
name = determine_package_name(package)
if name in requirements_to_specifier:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def numpy_upper():
return "numpy<1.20.0"


@pytest.fixture(scope="session", autouse=True)
def other_req_path():
return "-r core-requirements.txt"


def test_lower_bound(ploty_dep):
mininum_package = find_min_requirement(ploty_dep)
verify_mininum(mininum_package, "plotly", "4.14.0")
Expand Down Expand Up @@ -72,6 +77,11 @@ def test_upper_bound():
find_min_requirement("colorama")


def test_other_requirement(other_req_path):
mininum_package = find_min_requirement(other_req_path)
assert mininum_package is None


def test_bound(woodwork_dep):
mininum_package = find_min_requirement(woodwork_dep)
verify_mininum(mininum_package, "woodwork", "0.0.11")
Expand Down Expand Up @@ -107,11 +117,11 @@ def test_wrong_python_env():


def test_generate_min_requirements(
ploty_dep, dask_dep, pandas_dep, woodwork_dep, numpy_upper, numpy_lower
ploty_dep, dask_dep, pandas_dep, woodwork_dep, numpy_upper, numpy_lower, other_req_path
):
min_requirements = []
requirements_core = "\n".join([dask_dep, pandas_dep, woodwork_dep, numpy_upper])
requirements_koalas = "\n".join([ploty_dep, numpy_lower])
requirements_koalas = "\n".join([ploty_dep, numpy_lower, other_req_path])
with tempfile.NamedTemporaryFile(
mode="w", suffix=".txt", prefix="out_requirements"
) as _:
Expand All @@ -131,6 +141,9 @@ def test_generate_min_requirements(
requirements_paths=paths
)
assert isinstance(min_requirements, str)
assert '-r' not in min_requirements
assert '.txt' not in min_requirements
assert 'core-requirements.txt' not in min_requirements
min_requirements = min_requirements.split('\n')
assert min_requirements[-1] == ''
min_requirements = min_requirements[:-1]
Expand Down

0 comments on commit 5e9e5c3

Please sign in to comment.