├── thoth └── solver │ ├── py.typed │ ├── exceptions.py │ ├── python │ ├── __init__.py │ ├── python_solver.py │ ├── base.py │ ├── instrument.py │ └── python.py │ ├── __init__.py │ ├── _typing.py │ └── cli.py ├── thoth-solver ├── MANIFEST.in ├── tests ├── __init__.py ├── python │ ├── __init__.py │ ├── python_solver_test.py │ ├── instrument_test.py │ └── python_test.py ├── base_test.py └── data │ └── metadata │ ├── tensorflow.json │ ├── click.json │ ├── delegator-py.json │ └── tensorflow_extracted.json ├── app.sh ├── .s2i └── bin │ └── assemble ├── .gitignore ├── requirements.txt ├── .github ├── ISSUE_TEMPLATE │ ├── kebechet_update.md │ ├── major-release.md │ ├── minor-release.md │ ├── patch-release.md │ ├── kebechet_info.md │ ├── redeliver_container_image.md │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── pyproject.toml ├── OWNERS ├── docs └── source │ ├── _templates │ └── layout.html │ ├── index.rst │ └── conf.py ├── .prow.yaml ├── overlays ├── solver-fedora-34-py39 │ └── Pipfile ├── solver-rhel-8-py36 │ └── Pipfile ├── solver-rhel-8-py38 │ └── Pipfile ├── solver-rhel-9-py39 │ └── Pipfile └── solver-fedora-35-py310 │ └── Pipfile ├── Pipfile ├── .pre-commit-config.yaml ├── mypy.ini ├── .thoth.yaml ├── .aicoe-ci.yaml ├── setup.py ├── README.rst └── LICENSE /thoth/solver/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /thoth-solver: -------------------------------------------------------------------------------- 1 | thoth/solver/cli.py -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """Init for tests.""" 2 | -------------------------------------------------------------------------------- /tests/python/__init__.py: -------------------------------------------------------------------------------- 1 | """Init.""" 2 | -------------------------------------------------------------------------------- /app.sh: -------------------------------------------------------------------------------- 1 | python3 thoth/solver/cli.py python 2 | -------------------------------------------------------------------------------- /.s2i/bin/assemble: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python3 -m venv solver-venv 4 | solver-venv/bin/python3 -m pip install pipdeptree 5 | 6 | exec /usr/libexec/s2i/assemble 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.pyc 3 | .eggs/ 4 | thoth_solver.egg-info/ 5 | venv/ 6 | docs/source/thoth.*.rst 7 | build/ 8 | .coverage 9 | .mypy_cache/ 10 | .lock 11 | /.idea 12 | coverage.xml 13 | .env 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | attr 2 | autopep8 3 | click 4 | importlib-metadata 5 | packaging 6 | pipdeptree 7 | requests 8 | thoth-analyzer 9 | thoth-common 10 | thoth-python 11 | thoth-license-solver 12 | virtualenv 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/kebechet_update.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Kebechet update 3 | about: Manually trigger update of dependencies 4 | title: Kebechet update 5 | labels: bot 6 | --- 7 | 8 | Hey, Kebechet! 9 | 10 | Update my dependencies, please. 11 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 120 3 | py36 = true 4 | include = '\.pyi?$' 5 | exclude = ''' 6 | /( 7 | \.git 8 | | \.hg 9 | | \.mypy_cache 10 | | \.tox 11 | | \.venv 12 | | _build 13 | | build 14 | | dist 15 | )/ 16 | ''' 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/major-release.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Major release 3 | about: Create a new major release 4 | title: New major release 5 | assignees: sesheta 6 | labels: bot, priority/critical-urgent 7 | --- 8 | 9 | Hey, Kebechet! 10 | 11 | Create a new major release, please. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/minor-release.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Minor release 3 | about: Create a new minor release 4 | title: New minor release 5 | assignees: sesheta 6 | labels: bot, priority/critical-urgent 7 | --- 8 | 9 | Hey, Kebechet! 10 | 11 | Create a new minor release, please. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/patch-release.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Patch release 3 | about: Create a new patch release 4 | title: New patch release 5 | assignees: sesheta 6 | labels: bot, priority/critical-urgent 7 | --- 8 | 9 | Hey, Kebechet! 10 | 11 | Create a new patch release, please. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/kebechet_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Kebechet info 3 | about: Obtain information about application dependencies 4 | title: Kebechet info 5 | assignees: 'sesheta' 6 | labels: bot 7 | --- 8 | 9 | Hey, Kebechet! 10 | 11 | Give me information about my dependencies, please. 12 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - goern 5 | - kpostoffice 6 | - harshad16 7 | - mayaCostantini 8 | - sesheta 9 | 10 | reviewers: 11 | - kpostoffice 12 | - harshad16 13 | - mayaCostantini 14 | 15 | emeritus_approvers: 16 | - pacospace 17 | - fridex 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/redeliver_container_image.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Deliver Container Image 3 | about: build a git tag and push it as a container image to quay 4 | title: Deliver Container Image 5 | assignees: sesheta 6 | labels: bot, priority/critical-urgent 7 | --- 8 | 9 | Hey, AICoE-CI! 10 | 11 | Please build and deliver the following git tag: 12 | 13 | Tag: x.y.z 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Related Issues and Dependencies 2 | 3 | … 4 | 5 | ## This introduces a breaking change 6 | 7 | - [ ] Yes 8 | - [ ] No 9 | 10 | 11 | 12 | ## This Pull Request implements 13 | 14 | … Explain your changes. 15 | 16 | ## Description 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/source/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block footer %} 4 | {{ super() }} 5 | 6 | 7 | 17 | {% endblock %} 18 | -------------------------------------------------------------------------------- /.prow.yaml: -------------------------------------------------------------------------------- 1 | presubmits: 2 | - always_run: true 3 | context: op1st/prow/pre-commit 4 | decorate: true 5 | name: pre-commit 6 | skip_report: false 7 | spec: 8 | containers: 9 | - command: 10 | - pre-commit 11 | - run 12 | - --all-files 13 | image: quay.io/thoth-station/thoth-precommit-py38:v0.15.0 14 | - always_run: true 15 | context: op1st/prow/pytest 16 | decorate: true 17 | name: thoth-pytest-py38 18 | skip_report: false 19 | spec: 20 | containers: 21 | - command: 22 | - /bin/run-pytest 23 | image: quay.io/thoth-station/thoth-pytest-py38:v0.15.0 24 | -------------------------------------------------------------------------------- /overlays/solver-fedora-34-py39/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-license-solver = "*" 17 | thoth-python = "*" 18 | virtualenv = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | 28 | [requires] 29 | python_version = "3.9" 30 | -------------------------------------------------------------------------------- /overlays/solver-rhel-8-py36/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-license-solver = "*" 17 | thoth-python = "*" 18 | virtualenv = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | 28 | [requires] 29 | python_version = "3.6" 30 | -------------------------------------------------------------------------------- /overlays/solver-rhel-8-py38/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-license-solver = "*" 17 | thoth-python = "*" 18 | virtualenv = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | 28 | [requires] 29 | python_version = "3.8" 30 | -------------------------------------------------------------------------------- /overlays/solver-rhel-9-py39/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-license-solver = "*" 17 | thoth-python = "*" 18 | virtualenv = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | 28 | [requires] 29 | python_version = "3.9" 30 | -------------------------------------------------------------------------------- /overlays/solver-fedora-35-py310/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-license-solver = "*" 17 | thoth-python = "*" 18 | virtualenv = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | 28 | [requires] 29 | python_version = "3.10" 30 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | attr = "*" 8 | "autopep8" = "*" 9 | click = "*" 10 | importlib-metadata = "*" 11 | packaging = "*" 12 | pipdeptree = "*" 13 | requests = "*" 14 | thoth-analyzer = "*" 15 | thoth-common = "*" 16 | thoth-python = "*" 17 | virtualenv = "*" 18 | thoth-license-solver = "*" 19 | 20 | [dev-packages] 21 | pytest = "*" 22 | pytest-timeout = "*" 23 | pytest-cov = "*" 24 | pytest-venv = "*" 25 | mypy = "*" 26 | pytest-mypy = "*" 27 | types-setuptools = "*" 28 | pipdeptree = "*" 29 | 30 | [requires] 31 | python_version = "3.8" 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | labels: "bug, kind/bug" 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Additional context** 24 | Add any other context about the problem here. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | labels: "enhancement, kind/feature" 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | repos: 3 | - repo: https://github.com/asottile/add-trailing-comma 4 | rev: v2.2.3 5 | hooks: 6 | - id: add-trailing-comma 7 | 8 | - repo: https://github.com/Lucas-C/pre-commit-hooks 9 | rev: v1.3.1 10 | hooks: 11 | - id: remove-tabs 12 | 13 | - repo: https://github.com/pre-commit/pre-commit-hooks 14 | rev: v4.3.0 15 | hooks: 16 | - id: trailing-whitespace 17 | - id: check-merge-conflict 18 | - id: end-of-file-fixer 19 | - id: name-tests-test 20 | - id: check-added-large-files 21 | - id: check-byte-order-marker 22 | - id: check-case-conflict 23 | - id: check-docstring-first 24 | - id: check-json 25 | - id: check-symlinks 26 | - id: detect-private-key 27 | - id: check-ast 28 | - id: debug-statements 29 | 30 | - repo: https://github.com/pycqa/pydocstyle.git 31 | rev: "6.1.1" 32 | hooks: 33 | - id: pydocstyle 34 | -------------------------------------------------------------------------------- /tests/base_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2019 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # type: ignore 18 | 19 | """Core logic for solver test suite.""" 20 | 21 | import os 22 | 23 | 24 | class SolverTestCase: 25 | """A base class for solver test cases.""" 26 | 27 | data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") 28 | -------------------------------------------------------------------------------- /thoth/solver/exceptions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | """Exception hierarchy used in thoth-solver.""" 19 | 20 | 21 | class SolverException(Exception): 22 | """Exception to be raised in Solver.""" 23 | 24 | 25 | class NoReleasesFound(SolverException): 26 | """Exception raised if no releases were found for the given package.""" 27 | -------------------------------------------------------------------------------- /thoth/solver/python/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 Pavel Odvody 4 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 5 | # 6 | # This program is free software: you can redistribute it and / or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | """Implementation of ecosystem specific solvers.""" 20 | 21 | from .base import get_ecosystem_solver 22 | from .python_solver import PythonDependencyParser 23 | from .python_solver import PythonReleasesFetcher 24 | from .python_solver import PythonSolver 25 | from .python import resolve 26 | 27 | 28 | __all__ = ["get_ecosystem_solver", "PythonReleasesFetcher", "PythonDependencyParser", "PythonSolver", "resolve"] 29 | -------------------------------------------------------------------------------- /thoth/solver/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | """Thoth's solver package.""" 19 | 20 | from .python import get_ecosystem_solver 21 | from .python import PythonDependencyParser 22 | from .python import PythonReleasesFetcher 23 | from .python import PythonSolver 24 | from .python import resolve 25 | 26 | __version__ = "1.15.0" 27 | __title__ = "thoth-solver" 28 | __author__ = "Fridolin Pokorny" 29 | 30 | __all__ = ["resolve", "get_ecosystem_solver", "PythonDependencyParser", "PythonReleasesFetcher", "PythonSolver"] 31 | -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | python_version = 3.6 3 | warn_unused_configs = true 4 | disallow_subclassing_any = true 5 | disallow_any_generics = true 6 | disallow_untyped_calls = true 7 | disallow_untyped_defs = true 8 | disallow_incomplete_defs = true 9 | check_untyped_defs = true 10 | disallow_untyped_decorators = true 11 | no_implicit_optional = true 12 | warn_redundant_casts = true 13 | warn_unused_ignores = true 14 | warn_return_any = true 15 | no_implicit_reexport = true 16 | show_error_codes = true 17 | # pretty = true 18 | show_column_numbers = true 19 | 20 | [mypy-thoth.common] 21 | ignore_missing_imports = true 22 | 23 | [mypy-thoth.python] 24 | ignore_missing_imports = true 25 | 26 | [mypy-thoth.python.helpers] 27 | ignore_missing_imports = true 28 | 29 | [mypy-thoth.analyzer] 30 | ignore_missing_imports = true 31 | 32 | [mypy-pkg_resources._vendor.packaging.utils] 33 | ignore_missing_imports = true 34 | 35 | [mypy-importlib_metadata] 36 | ignore_missing_imports = true 37 | 38 | [mypy-packaging.requirements] 39 | ignore_missing_imports = true 40 | 41 | [mypy-packaging.markers] 42 | ignore_missing_imports = true 43 | 44 | [mypy-packaging.utils] 45 | ignore_missing_imports = true 46 | 47 | [mypy-thoth.python.exceptions] 48 | ignore_missing_imports = true 49 | 50 | [mypy-thoth.license_solver] 51 | ignore_missing_imports = true 52 | -------------------------------------------------------------------------------- /.thoth.yaml: -------------------------------------------------------------------------------- 1 | host: khemenu.thoth-station.ninja 2 | tls_verify: true 3 | requirements_format: pipenv 4 | overlays_dir: overlays 5 | 6 | runtime_environments: 7 | - name: solver-fedora-34-py39 8 | operating_system: 9 | name: "fedora" 10 | version: "34" 11 | python_version: "3.9" 12 | recommendation_type: latest 13 | base_image: quay.io/thoth-station/s2i-thoth-f34-py39:v0.35.0 14 | 15 | - name: solver-fedora-35-py310 16 | operating_system: 17 | name: "fedora" 18 | version: "35" 19 | python_version: "3.10" 20 | recommendation_type: latest 21 | base_image: quay.io/thoth-station/s2i-thoth-f35-py310:v0.35.0 22 | 23 | - name: solver-rhel-8-py36 24 | operating_system: 25 | name: "rhel" 26 | version: "8" 27 | python_version: "3.6" 28 | recommendation_type: latest 29 | base_image: quay.io/thoth-station/s2i-thoth-ubi8-py36:v0.35.0 30 | 31 | - name: solver-rhel-8-py38 32 | operating_system: 33 | name: "rhel" 34 | version: "8" 35 | python_version: "3.8" 36 | recommendation_type: latest 37 | base_image: quay.io/thoth-station/s2i-thoth-ubi8-py38:v0.35.0 38 | 39 | - name: solver-rhel-9-py39 40 | operating_system: 41 | name: "rhel" 42 | version: "9" 43 | python_version: "3.9" 44 | recommendation_type: latest 45 | base_image: quay.io/thoth-station/s2i-thoth-ubi9-py39:v0.35.0 46 | 47 | managers: 48 | - name: pipfile-requirements 49 | - name: update 50 | configuration: 51 | labels: [bot] 52 | - name: info 53 | - name: version 54 | configuration: 55 | assignees: 56 | - sesheta 57 | labels: [bot] 58 | changelog_file: true 59 | -------------------------------------------------------------------------------- /thoth/solver/_typing.py: -------------------------------------------------------------------------------- 1 | """Adopted from the packaging project. 2 | 3 | https://github.com/pypa/packaging 4 | 5 | As we want to have solver running also for older versions of Python that do not 6 | support typing, let's use this typing hack. 7 | 8 | For neatly implementing static typing in packaging. 9 | 10 | `mypy` - the static type analysis tool we use - uses the `typing` module, which 11 | provides core functionality fundamental to mypy's functioning. 12 | 13 | Generally, `typing` would be imported at runtime and used in that fashion - 14 | it acts as a no-op at runtime and does not have any run-time overhead by 15 | design. 16 | 17 | As it turns out, `typing` is not vendorable - it uses separate sources for 18 | Python 2/Python 3. Thus, this codebase can not expect it to be present. 19 | To work around this, mypy allows the typing import to be behind a False-y 20 | optional to prevent it from running at runtime and type-comments can be used 21 | to remove the need for the types to be accessible directly during runtime. 22 | 23 | This module provides the False-y guard in a nicely named fashion so that a 24 | curious maintainer can reach here to read this. 25 | 26 | In packaging, all static-typing related imports should be guarded as follows: 27 | 28 | from packaging._typing import MYPY_CHECK_RUNNING 29 | 30 | if MYPY_CHECK_RUNNING: 31 | from typing import ... 32 | 33 | Ref: https://github.com/python/mypy/issues/3216 34 | """ 35 | 36 | MYPY_CHECK_RUNNING = False 37 | 38 | if MYPY_CHECK_RUNNING: # pragma: no cover 39 | import typing 40 | 41 | cast = typing.cast 42 | else: 43 | def cast(type_, value): # type: ignore 44 | """ 45 | # A dummy no-op version, which we tell mypy to ignore. 46 | 47 | typing's cast() is needed at runtime, but we don't want to import typing. 48 | """ 49 | return value 50 | -------------------------------------------------------------------------------- /.aicoe-ci.yaml: -------------------------------------------------------------------------------- 1 | check: 2 | - overlays-build 3 | overlays_dir: overlays 4 | overlays: 5 | - name: solver-rhel-9-py39 6 | build: 7 | base-image: quay.io/thoth-station/s2i-thoth-ubi9-py39:v0.35.0 8 | build-stratergy: 'Source' 9 | custom-tag: 'latest' 10 | registry: quay.io 11 | registry-org: thoth-station 12 | registry-project: 'solver-rhel-9-py39' 13 | registry-secret: thoth-station-thoth-pusher-secret 14 | deploy: 15 | image-name: 'solver-rhel-9-py39' 16 | overlay-contextpath: 'solver/overlays/test/imagestreamtag.yaml' 17 | project-name: thoth-application 18 | project-org: thoth-station 19 | 20 | - name: solver-rhel-8-py38 21 | build: 22 | base-image: quay.io/thoth-station/s2i-thoth-ubi8-py38:v0.35.0 23 | build-stratergy: 'Source' 24 | custom-tag: 'latest' 25 | registry: quay.io 26 | registry-org: thoth-station 27 | registry-project: 'solver-rhel-8-py38' 28 | registry-secret: thoth-station-thoth-pusher-secret 29 | deploy: 30 | image-name: 'solver-rhel-8-py38' 31 | overlay-contextpath: 'solver/overlays/test/imagestreamtag.yaml' 32 | project-name: thoth-application 33 | project-org: thoth-station 34 | 35 | - name: solver-rhel-8-py36 36 | build: 37 | base-image: quay.io/thoth-station/s2i-thoth-ubi8-py36:v0.35.0 38 | build-stratergy: 'Source' 39 | custom-tag: 'latest' 40 | registry: quay.io 41 | registry-org: thoth-station 42 | registry-project: 'solver-rhel-8-py36' 43 | registry-secret: thoth-station-thoth-pusher-secret 44 | deploy: 45 | image-name: 'solver-rhel-8-py36' 46 | overlay-contextpath: 'solver/overlays/test/imagestreamtag.yaml' 47 | project-name: thoth-application 48 | project-org: thoth-station 49 | 50 | - name: solver-fedora-34-py39 51 | build: 52 | base-image: quay.io/thoth-station/s2i-thoth-f34-py39:v0.35.0 53 | build-stratergy: 'Source' 54 | custom-tag: 'latest' 55 | registry: quay.io 56 | registry-org: thoth-station 57 | registry-project: 'solver-fedora-34-py39' 58 | registry-secret: thoth-station-thoth-pusher-secret 59 | deploy: 60 | image-name: 'solver-fedora-34-py39' 61 | overlay-contextpath: 'solver/overlays/test/imagestreamtag.yaml' 62 | project-name: thoth-application 63 | project-org: thoth-station 64 | 65 | - name: solver-fedora-35-py310 66 | build: 67 | base-image: quay.io/thoth-station/s2i-thoth-f35-py310:v0.35.0 68 | build-stratergy: 'Source' 69 | custom-tag: 'latest' 70 | registry: quay.io 71 | registry-org: thoth-station 72 | registry-project: 'solver-fedora-35-py310' 73 | registry-secret: thoth-station-thoth-pusher-secret 74 | deploy: 75 | image-name: 'solver-fedora-35-py310' 76 | overlay-contextpath: 'solver/overlays/test/imagestreamtag.yaml' 77 | project-name: thoth-application 78 | project-org: thoth-station 79 | -------------------------------------------------------------------------------- /tests/data/metadata/tensorflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "Metadata-Version": "2.1", 4 | "Name": "tensorflow", 5 | "Version": "2.0.0", 6 | "Summary": "TensorFlow is an open source machine learning framework for everyone.", 7 | "Home-page": "https://www.tensorflow.org/", 8 | "Author": "Google Inc.", 9 | "Author-email": "packages@tensorflow.org", 10 | "License": "Apache 2.0", 11 | "Download-URL": "https://github.com/tensorflow/tensorflow/tags", 12 | "Keywords": "tensorflow tensor machine learning", 13 | "Platform": ["UNKNOWN"], 14 | "Classifier": [ 15 | "Programming Language :: Python", 16 | "Programming Language :: Python :: 2.6", 17 | "Programming Language :: Python :: 2.7", 18 | "Programming Language :: Python :: 3", 19 | "Programming Language :: Python :: 3.3", 20 | "Programming Language :: Python :: 3.4", 21 | "Programming Language :: Python :: 3.5", 22 | "Programming Language :: Python :: 3.6", 23 | "Programming Language :: Python :: Implementation :: CPython", 24 | "Programming Language :: Python :: Implementation :: PyPy" 25 | ], 26 | "Requires-Dist": ["enum34 (>=1.1.6) ; python_version < \"3.4\""] 27 | }, 28 | "requires": [ 29 | "absl-py (>=0.7.0)", 30 | "astor (>=0.6.0)", 31 | "gast (==0.2.2)", 32 | "google-pasta (>=0.1.6)", 33 | "keras-applications (>=1.0.8)", 34 | "keras-preprocessing (>=1.0.5)", 35 | "numpy (<2.0,>=1.16.0)", 36 | "opt-einsum (>=2.3.2)", 37 | "six (>=1.10.0)", 38 | "protobuf (>=3.6.1)", 39 | "tensorboard (<2.1.0,>=2.0.0)", 40 | "tensorflow-estimator (<2.1.0,>=2.0.0)", 41 | "termcolor (>=1.1.0)", 42 | "wrapt (>=1.11.1)", 43 | "grpcio (>=1.8.6)", 44 | "wheel (>=0.26)", 45 | "backports.weakref (>=1.0rc1) ; python_version < \"3.4\"", 46 | "enum34 (>=1.1.6) ; python_version < \"3.4\"" 47 | ], 48 | "entry_points": [ 49 | { 50 | "name": "saved_model_cli", 51 | "value": "tensorflow.python.tools.saved_model_cli:main", 52 | "group": "console_scripts" 53 | }, 54 | {"name": "tensorboard", "value": "tensorboard.main:run_main", "group": "console_scripts"}, 55 | { 56 | "name": "tf_upgrade_v2", 57 | "value": "tensorflow.tools.compatibility.tf_upgrade_v2_main:main", 58 | "group": "console_scripts" 59 | }, 60 | {"name": "tflite_convert", "value": "tensorflow.lite.python.tflite_convert:main", "group": "console_scripts"}, 61 | {"name": "toco", "value": "tensorflow.lite.python.tflite_convert:main", "group": "console_scripts"}, 62 | { 63 | "name": "toco_from_protos", 64 | "value": "tensorflow.lite.toco.python.toco_from_protos:main", 65 | "group": "console_scripts" 66 | } 67 | ], 68 | "version": "2.0.0" 69 | } 70 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../README.rst 2 | 3 | Crossroad 4 | ========= 5 | 6 | * `Documentation for thamos <../thamos>`_ 7 | * `Documentation for thoth-adviser <../adviser>`_ 8 | * `Documentation for thoth-analyzer <../analyzer>`_ 9 | * `Documentation for thoth-common <../common>`_ 10 | * `Documentation for thoth-lab <../lab>`_ 11 | * `Documentation for thoth-package-analyzer <../package-analyzer>`_ 12 | * `Documentation for thoth-package-extract <../package-extract>`_ 13 | * `Documentation for thoth-python <../python>`_ 14 | * `Documentation for thoth-storages <../storages>`_ 15 | * `Documentation for kebechet <../kebechet>`_ 16 | * :ref:`genindex` 17 | * :ref:`modindex` 18 | * :ref:`search` 19 | 20 | .. toctree:: 21 | :maxdepth: 3 22 | 23 | thoth.solver 24 | 25 | This documentation corresponds to implementation in version |version|, 26 | documentation was generated on |today|. 27 | 28 | 29 | Creating New Solvers 30 | #################### 31 | 32 | A. Firstly identify the upstream image that you wish to develop a new solver from. Create an overlay for that new solver in [`thoth-station/s2i-thoth`](https://github.com/thoth-station/s2i-thoth). Each solver overlay should have 4 files. 33 | 1. A `Dockerfile` to build the image from. This should be based off of the other examples available in the (s2i-thoth-repo)[https://github.com/thoth-station/s2i-thoth]. 34 | 2. A `requirements.in` stating the required dependencies. 35 | 3. A `requirements.txt` which can be generated from pip compile using the following command once the `requirements.in` file is present: `pip-compile --generate-hashes requirements.in`. 36 | 4. An `s2i_assemble.patch` file. This will be used to patch the upstream image's s2i_assemble file with the dependencies required by thoth-station. 37 | - Documentation on custructing this patch file is already availabe [here](https://github.com/thoth-station/s2i-thoth/blob/master/README.rst#s2i-assemble-patches). 38 | B. Secondly head over to the [solver-repo][https://github.com/thoth-station/solver], and create an overlay for your new solver. This entails: 39 | 1. Creating the overlay directory in the solver-repo root, with a `Pipfile` and `Pipfile.lock` 40 | 2. Create a new overlay in the `.thoth.yaml` file [see example](https://github.com/thoth-station/solver/blob/master/.thoth.yaml#L15-L22) 41 | 3. Create a new overlay in the `.aicoe-ci.yaml` file [see example](https://github.com/thoth-station/solver/blob/master/.aicoe-ci.yaml#L50-L63) 42 | C. Third, create a deployment for the new solver image in `thoth-station/thoth-application`. 43 | 1. Add your solver image to the [base imagestream file](https://github.com/thoth-station/thoth-application/blob/master/solver/base/imagestreams.yaml) 44 | 2. Add your solver image to the imagestream file for the overlay you want to deploy it to. An example [here](https://github.com/thoth-station/thoth-application/blob/master/solver/overlays/test/imagestreamtag.yaml#L42-L55) shows the `f35-py310` overlay being deployed to the `test` overlay. 45 | D. Finally, create a PR in thoth-station/perscriptions to gerenate the prescriptions for the new solver overlay. The code used to generate these perscriptions is available on [this issue thread](https://github.com/thoth-station/adviser/issues/1961). 46 | -------------------------------------------------------------------------------- /thoth/solver/python/python_solver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 Pavel Odvody 4 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 5 | # 6 | # This program is free software: you can redistribute it and / or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | """Classes for resolving dependencies as specified in each ecosystem.""" 20 | 21 | import logging 22 | 23 | import attr 24 | from thoth.python import Source 25 | from packaging.requirements import Requirement 26 | 27 | from .base import DependencyParser 28 | from .base import ReleasesFetcher 29 | from .base import Solver 30 | 31 | from .._typing import MYPY_CHECK_RUNNING 32 | 33 | if MYPY_CHECK_RUNNING: # pragma: no cover 34 | from typing import List, Tuple 35 | 36 | 37 | _LOGGER = logging.getLogger(__name__) 38 | 39 | 40 | @attr.s(slots=True) 41 | class PythonReleasesFetcher(ReleasesFetcher): 42 | """A releases fetcher based on PEP compatible simple API (also supporting Warehouse API).""" 43 | 44 | source = attr.ib(type=Source, kw_only=True) 45 | 46 | def fetch_releases(self, package_name): # type: (str) -> Tuple[str, List[Tuple[str, str]]] 47 | """Fetch package and index_url for a package_name.""" 48 | package_name = self.source.normalize_package_name(package_name) # XXX 49 | releases = self.source.get_package_versions(package_name) 50 | releases_with_index_url = [(release, self.index_url) for release in releases] 51 | return package_name, releases_with_index_url 52 | 53 | @property 54 | def index_url(self): # type: () -> str 55 | """Get URL to package source index from where releases are fetched.""" 56 | url = self.source.url # type: str 57 | return url 58 | 59 | 60 | @attr.s(slots=True) 61 | class PythonDependencyParser(DependencyParser): 62 | """Python Dependency parsing.""" 63 | 64 | @staticmethod 65 | def parse_python(spec): # type: (str) -> Requirement 66 | """Parse PyPI specification of a single dependency. 67 | 68 | :param spec: str, for example "Django>=1.5,<1.8" 69 | :return: requirement for the Python package 70 | """ 71 | req = Requirement(spec) 72 | # We explictly allow pre-releases here as we want to handle them in resolver's pipeline units. 73 | req.specifier.prereleases = True 74 | return req 75 | 76 | def parse(self, specs): # type: (List[str]) -> List[Requirement] 77 | """Parse specs.""" 78 | return [self.parse_python(s) for s in specs] 79 | 80 | 81 | @attr.s(slots=True) 82 | class PythonSolver(Solver): 83 | """PyPI dependencies solver.""" 84 | 85 | dependency_parser = attr.ib(type=PythonDependencyParser, kw_only=True) 86 | releases_fetcher = attr.ib(type=PythonReleasesFetcher, kw_only=True) 87 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """Setup file.""" 3 | import os 4 | import sys 5 | from setuptools import setup 6 | from pathlib import Path 7 | from setuptools.command.test import test as TestCommand 8 | 9 | 10 | def get_requirements(): 11 | """Get requirements.""" 12 | with open("requirements.txt") as fd: 13 | return fd.read().splitlines() 14 | 15 | 16 | def get_version(): 17 | """Get version.""" 18 | with open(os.path.join("thoth", "solver", "__init__.py")) as f: 19 | content = f.readlines() 20 | 21 | for line in content: 22 | if line.startswith("__version__ ="): 23 | # dirty, remove trailing and leading chars 24 | return line.split(" = ")[1][1:-2] 25 | 26 | raise ValueError("No package version found") 27 | 28 | 29 | class Test(TestCommand): 30 | """Introduce test command to run testsuite using pytest.""" 31 | 32 | _IMPLICIT_PYTEST_ARGS = [ 33 | "--timeout=90", 34 | "--cov=./thoth", 35 | "--cov-report=xml", 36 | "--capture=no", 37 | "--mypy", 38 | "thoth", 39 | "--verbose", 40 | "-l", 41 | "-s", 42 | "-vv", 43 | "tests/", 44 | ] 45 | 46 | user_options = [("pytest-args=", "a", "Arguments to pass into py.test")] 47 | 48 | def initialize_options(self): 49 | """Initialize options.""" 50 | super().initialize_options() 51 | self.pytest_args = None 52 | 53 | def finalize_options(self): 54 | """Finalize options.""" 55 | super().finalize_options() 56 | self.test_args = [] 57 | self.test_suite = True 58 | 59 | def run_tests(self): 60 | """Run tests.""" 61 | import pytest 62 | 63 | passed_args = list(self._IMPLICIT_PYTEST_ARGS) 64 | 65 | if self.pytest_args: 66 | self.pytest_args = [arg for arg in self.pytest_args.split() if arg] 67 | passed_args.extend(self.pytest_args) 68 | 69 | sys.exit(pytest.main(passed_args)) 70 | 71 | 72 | VERSION = get_version() 73 | setup( 74 | name="thoth-solver", 75 | version=VERSION, 76 | entry_points={"console_scripts": ["thoth-solver=thoth.solver.cli:cli"]}, 77 | packages=["thoth.solver", "thoth.solver.python"], 78 | install_requires=get_requirements(), 79 | author="Fridolin Pokorny", 80 | author_email="fridolin@redhat.com", 81 | maintainer="Fridolin Pokorny", 82 | maintainer_email="fridolin@redhat.com", 83 | description="Tool and library for discovering package dependencies in PyPI world", 84 | long_description=Path("README.rst").read_text(), 85 | url="https://github.com/thoth-station/solver", 86 | license="GPLv3+", 87 | keywords="python dependency pypi dependencies tool library", 88 | zip_safe=False, 89 | classifiers=[ 90 | "Development Status :: 4 - Beta", 91 | "Programming Language :: Python :: 3", 92 | "Programming Language :: Python :: 3.4", 93 | "Programming Language :: Python :: 3.5", 94 | "Environment :: Console", 95 | "Intended Audience :: Developers", 96 | "License :: OSI Approved :: Apache Software License", 97 | "Operating System :: OS Independent", 98 | "Programming Language :: Python :: Implementation :: CPython", 99 | "Programming Language :: Python :: Implementation :: PyPy", 100 | ], 101 | command_options={"build_sphinx": {"version": ("setup.py", VERSION), "release": ("setup.py", VERSION)}}, 102 | package_data={"thoth.solver": ["py.typed"]}, 103 | cmdclass={"test": Test}, 104 | ) 105 | -------------------------------------------------------------------------------- /tests/data/metadata/click.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry_points": [], 3 | "metadata": { 4 | "Author": "Armin Ronacher", 5 | "Author-email": "armin.ronacher@active-4.com", 6 | "Classifier": [ 7 | "Development Status :: 5 - Production/Stable", 8 | "Intended Audience :: Developers", 9 | "License :: OSI Approved :: BSD License", 10 | "Operating System :: OS Independent", 11 | "Programming Language :: Python", 12 | "Programming Language :: Python :: 2", 13 | "Programming Language :: Python :: 2.7", 14 | "Programming Language :: Python :: 3", 15 | "Programming Language :: Python :: 3.4", 16 | "Programming Language :: Python :: 3.5", 17 | "Programming Language :: Python :: 3.6", 18 | "Programming Language :: Python :: 3.7" 19 | ], 20 | "Description": "\\$ click\\_\n==========\n\nClick is a Python package for creating beautiful command line interfaces\nin a composable way with as little code as necessary. It's the \"Command\nLine Interface Creation Kit\". It's highly configurable but comes with\nsensible defaults out of the box.\n\nIt aims to make the process of writing command line tools quick and fun\nwhile also preventing any frustration caused by the inability to\nimplement an intended CLI API.\n\nClick in three points:\n\n- Arbitrary nesting of commands\n- Automatic help page generation\n- Supports lazy loading of subcommands at runtime\n\n\nInstalling\n----------\n\nInstall and update using `pip`_:\n\n.. code-block:: text\n\n $ pip install click\n\nClick supports Python 3.4 and newer, Python 2.7, and PyPy.\n\n.. _pip: https://pip.pypa.io/en/stable/quickstart/\n\n\nA Simple Example\n----------------\n\nWhat does it look like? Here is an example of a simple Click program:\n\n.. code-block:: python\n\n import click\n\n @click.command()\n @click.option(\"--count\", default=1, help=\"Number of greetings.\")\n @click.option(\"--name\", prompt=\"Your name\",\n help=\"The person to greet.\")\n def hello(count, name):\n \"\"\"Simple program that greets NAME for a total of COUNT times.\"\"\"\n for _ in range(count):\n click.echo(\"Hello, %s!\" % name)\n\n if __name__ == '__main__':\n hello()\n\nAnd what it looks like when run:\n\n.. code-block:: text\n\n $ python hello.py --count=3\n Your name: Click\n Hello, Click!\n Hello, Click!\n Hello, Click!\n\n\nDonate\n------\n\nThe Pallets organization develops and supports Click and other popular\npackages. In order to grow the community of contributors and users, and\nallow the maintainers to devote more time to the projects, `please\ndonate today`_.\n\n.. _please donate today: https://palletsprojects.com/donate\n\n\nLinks\n-----\n\n* Website: https://palletsprojects.com/p/click/\n* Documentation: https://click.palletsprojects.com/\n* License: `BSD `_\n* Releases: https://pypi.org/project/click/\n* Code: https://github.com/pallets/click\n* Issue tracker: https://github.com/pallets/click/issues\n* Test status:\n\n * Linux, Mac: https://travis-ci.org/pallets/click\n * Windows: https://ci.appveyor.com/project/pallets/click\n\n* Test coverage: https://codecov.io/gh/pallets/click\n\n\n", 21 | "Home-page": "https://palletsprojects.com/p/click/", 22 | "License": "BSD", 23 | "Maintainer": "Pallets Team", 24 | "Maintainer-email": "contact@palletsprojects.com", 25 | "Metadata-Version": "2.1", 26 | "Name": "Click", 27 | "Platform": [ 28 | "UNKNOWN" 29 | ], 30 | "Project-URL": [ 31 | "Documentation, https://click.palletsprojects.com/", 32 | "Code, https://github.com/pallets/click", 33 | "Issue tracker, https://github.com/pallets/click/issues" 34 | ], 35 | "Requires-Python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", 36 | "Summary": "Composable command line interface toolkit", 37 | "Version": "7.0" 38 | }, 39 | "requires": null, 40 | "version": "7.0" 41 | } 42 | -------------------------------------------------------------------------------- /tests/data/metadata/delegator-py.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry_points": [], 3 | "metadata": { 4 | "Author": "Kenneth Reitz", 5 | "Author-email": "me@kennethreitz.com", 6 | "Classifier": [ 7 | "Programming Language :: Python", 8 | "Programming Language :: Python :: 2.6", 9 | "Programming Language :: Python :: 2.7", 10 | "Programming Language :: Python :: 3", 11 | "Programming Language :: Python :: 3.3", 12 | "Programming Language :: Python :: 3.4", 13 | "Programming Language :: Python :: 3.5", 14 | "Programming Language :: Python :: 3.6", 15 | "Programming Language :: Python :: Implementation :: CPython", 16 | "Programming Language :: Python :: Implementation :: PyPy" 17 | ], 18 | "Description": "\nDelegator.py \u2014\u00a0Subprocesses for Humans 2.0\n=======================================\n\n\n.. image:: https://img.shields.io/pypi/v/delegator.py.svg\n :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/l/delegator.py.svg\n :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/wheel/delegator.py.svg\n :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/pyversions/delegator.py.svg\n :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/badge/SayThanks.io-\u263c-1EAEDB.svg\n :target: https://saythanks.io/to/kennethreitz\n\n\n**Delegator.py** is a simple library for dealing with subprocesses, inspired\nby both `envoy `_ and `pexpect `_ (in fact, it depends on it!).\n\nThis module features two main functions ``delegator.run()`` and ``delegator.chain()``. One runs commands, blocking or non-blocking, and the other runs a chain of commands, separated by the standard unix pipe operator: ``|``.\n\nIf you're interested in financially supporting Kenneth Reitz open source, consider `visiting this link `_. Your support helps tremendously with sustainability of motivation, as Open Source is no longer part of my day job.\n\nBasic Usage\n-----------\n\nBasic run functionality:\n\n.. code:: pycon\n\n >>> c = delegator.run('ls')\n >>> print c.out\n README.rst delegator.py\n\n >>> c = delegator.run('long-running-process', block=False)\n >>> c.pid\n 35199\n >>> c.block()\n >>> c.return_code\n 0\n\nCommands can be passed in as lists as well (e.g. ``['ls', '-lrt']``), for parameterization.\n\nBasic chain functionality:\n\n.. code:: pycon\n\n # Can also be called with ([['fortune'], ['cowsay']]).\n # or, delegator.run('fortune').pipe('cowsay')\n\n >>> c = delegator.chain('fortune | cowsay')\n >>> print c.out\n _______________________________________\n / Our swords shall play the orators for \\\n | us. |\n | |\n \\ -- Christopher Marlowe /\n ---------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n\n\nExpect functionality is built-in too, on non-blocking commands:\n\n.. code:: pycon\n\n >>> c.expect('Password:')\n >>> c.send('PASSWORD')\n >>> c.block()\n\nOther functions:\n\n.. code:: pycon\n\n >>> c.kill()\n >>> c.send('SIGTERM', signal=True)\n\n # Only available when block=True, otherwise, use c.out.\n >>> c.err\n ''\n\n # Direct access to pipes.\n >>> c.std_err\n ', mode 'rU' at 0x10a5351e0>\n\n # Adjust environment variables for the command (existing will be overwritten).\n >>> c = delegator.chain('env | grep NEWENV', env={'NEWENV': 'FOO_BAR'})\n >>> c.out\n NEWENV=FOO_BAR\n\n\n\nInstallation\n------------\n\n::\n\n $ pip install delegator.py\n\n\u2728\ud83c\udf70\u2728\n\n\n", 19 | "Home-page": "https://github.com/kennethreitz/delegator", 20 | "License": "MIT", 21 | "Metadata-Version": "2.1", 22 | "Name": "delegator.py", 23 | "Platform": [ 24 | "UNKNOWN" 25 | ], 26 | "Requires-Dist": [ 27 | "pexpect (>=4.1.0)" 28 | ], 29 | "Summary": "Subprocesses for Humans 2.0.", 30 | "Version": "0.1.1" 31 | }, 32 | "requires": [ 33 | "pexpect (>=4.1.0)" 34 | ], 35 | "version": "0.1.1" 36 | } 37 | -------------------------------------------------------------------------------- /tests/python/python_solver_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2019 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # type: ignore 18 | 19 | """Test resolving versions given the version range in Python ecosystem.""" 20 | 21 | import pytest 22 | from tests.base_test import SolverTestCase 23 | 24 | from thoth.solver import get_ecosystem_solver 25 | 26 | 27 | class TestPythonSolver(SolverTestCase): 28 | """Test resolving version ranges in the Python ecosystem.""" 29 | 30 | _PYPI_SIMPLE_API_URL = "https://pypi.org/simple" 31 | 32 | _SELINON_VERSIONS_ALL = { 33 | "selinon": { 34 | ("0.1.0rc2", "https://pypi.org/simple"), 35 | ("0.1.0rc3", "https://pypi.org/simple"), 36 | ("0.1.0rc4", "https://pypi.org/simple"), 37 | ("0.1.0rc5", "https://pypi.org/simple"), 38 | ("0.1.0rc6", "https://pypi.org/simple"), 39 | ("0.1.0rc7", "https://pypi.org/simple"), 40 | ("0.1.0rc8", "https://pypi.org/simple"), 41 | ("0.1.0rc9", "https://pypi.org/simple"), 42 | ("1.0.0rc1", "https://pypi.org/simple"), 43 | ("1.0.0rc2", "https://pypi.org/simple"), 44 | ("1.0.0rc3", "https://pypi.org/simple"), 45 | ("1.0.0rc4", "https://pypi.org/simple"), 46 | ("1.0.0", "https://pypi.org/simple"), 47 | ("1.1.0", "https://pypi.org/simple"), 48 | }, 49 | } 50 | 51 | @pytest.mark.parametrize( 52 | "package_specification,resolved_versions", 53 | [ 54 | ( 55 | "selinon>=1.0.0rc1,<1.1.0", 56 | { 57 | "selinon": { 58 | ("1.0.0rc1", "https://pypi.org/simple"), 59 | ("1.0.0rc2", "https://pypi.org/simple"), 60 | ("1.0.0rc3", "https://pypi.org/simple"), 61 | ("1.0.0rc4", "https://pypi.org/simple"), 62 | ("1.0.0", "https://pypi.org/simple"), 63 | }, 64 | }, 65 | ), 66 | ( 67 | "selinon<=1.1.0", 68 | { 69 | "selinon": { 70 | ("0.1.0rc2", "https://pypi.org/simple"), 71 | ("0.1.0rc3", "https://pypi.org/simple"), 72 | ("0.1.0rc4", "https://pypi.org/simple"), 73 | ("0.1.0rc5", "https://pypi.org/simple"), 74 | ("0.1.0rc6", "https://pypi.org/simple"), 75 | ("0.1.0rc7", "https://pypi.org/simple"), 76 | ("0.1.0rc8", "https://pypi.org/simple"), 77 | ("0.1.0rc9", "https://pypi.org/simple"), 78 | ("1.0.0rc1", "https://pypi.org/simple"), 79 | ("1.0.0rc2", "https://pypi.org/simple"), 80 | ("1.0.0rc3", "https://pypi.org/simple"), 81 | ("1.0.0rc4", "https://pypi.org/simple"), 82 | ("1.0.0", "https://pypi.org/simple"), 83 | ("1.1.0", "https://pypi.org/simple"), 84 | }, 85 | }, 86 | ), 87 | ("tensorflow==2.0.0", {"tensorflow": {("2.0.0", "https://pypi.org/simple")}}), 88 | ], 89 | ) 90 | def test_solve_dependencies(self, package_specification, resolved_versions): 91 | """Test solve dependencies.""" 92 | solver = get_ecosystem_solver("pypi") 93 | test_resolved_versions = solver.solve([package_specification]) 94 | test_resolved_versions = {k: set(v) for k, v in test_resolved_versions.items()} 95 | assert test_resolved_versions == resolved_versions 96 | -------------------------------------------------------------------------------- /thoth/solver/python/base.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 Pavel Odvody 4 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 5 | # 6 | # This program is free software: you can redistribute it and / or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | """Classes for resolving dependencies as specified in each ecosystem.""" 20 | 21 | import logging 22 | 23 | import attr 24 | import abc 25 | 26 | from thoth.python import Source 27 | 28 | from ..exceptions import NoReleasesFound 29 | from ..exceptions import SolverException 30 | from .._typing import MYPY_CHECK_RUNNING 31 | 32 | if MYPY_CHECK_RUNNING: # pragma: no cover 33 | from typing import List, Tuple, Dict 34 | from packaging.requirements import Requirement 35 | 36 | 37 | _LOGGER = logging.getLogger(__name__) 38 | 39 | 40 | @attr.s(slots=True) 41 | class ReleasesFetcher: 42 | """A base class for fetching package releases.""" 43 | 44 | @abc.abstractmethod 45 | def fetch_releases(self, package): # type: (str) -> Tuple[str, List[Tuple[str, str]]] 46 | """Abstract method for getting list of releases versions.""" 47 | 48 | @abc.abstractmethod 49 | def index_url(self): # type: () -> str 50 | """Get URL to index from where releases are fetched.""" 51 | 52 | 53 | @attr.s(slots=True) 54 | class DependencyParser: 55 | """Base class for Dependency parsing.""" 56 | 57 | @abc.abstractmethod 58 | def parse(self, specs): # type: (List[str]) -> List[Requirement] 59 | """Abstract method for dependency parsing.""" 60 | 61 | 62 | @attr.s(slots=True) 63 | class Solver: 64 | """Base class for resolving dependencies.""" 65 | 66 | dependency_parser = attr.ib(type=DependencyParser, kw_only=True) 67 | releases_fetcher = attr.ib(type=ReleasesFetcher, kw_only=True) 68 | 69 | def solve(self, dependencies, graceful=True): # type: (List[str], bool) -> Dict[str, List[Tuple[str, str]]] 70 | """Solve `dependencies` against a repository.""" 71 | solved = {} # type: Dict[str, List[Tuple[str, str]]] 72 | for dep in self.dependency_parser.parse(dependencies): 73 | _LOGGER.debug("Fetching releases for: %r", dep) 74 | 75 | name, releases = self.releases_fetcher.fetch_releases(dep.name) 76 | 77 | if name in solved: 78 | raise SolverException("Dependency: {} is listed multiple times".format(name)) 79 | 80 | if not releases: 81 | if graceful: 82 | _LOGGER.info("No releases found for package %r", dep.name) 83 | continue 84 | else: 85 | raise NoReleasesFound("No releases found for package {!r}".format(dep.name)) 86 | 87 | solved[name] = [] 88 | for release in releases: 89 | if release[0] in dep.specifier: 90 | solved[name].append(release) 91 | 92 | _LOGGER.debug(" matching: %s", solved[name]) 93 | 94 | return solved 95 | 96 | 97 | def get_ecosystem_solver(ecosystem_name): # type: (str) -> Solver 98 | """Get Solver subclass instance for particular ecosystem. 99 | 100 | :param ecosystem_name: name of ecosystem for which solver should be get 101 | :return: Solver 102 | """ 103 | from .python_solver import PythonSolver 104 | from .python_solver import PythonReleasesFetcher 105 | from .python_solver import PythonDependencyParser 106 | 107 | if ecosystem_name.lower() == "pypi": 108 | source = Source(url="https://pypi.org/simple", warehouse_api_url="https://pypi.org/pypi", warehouse=True) 109 | 110 | return PythonSolver( 111 | dependency_parser=PythonDependencyParser(), releases_fetcher=PythonReleasesFetcher(source=source), 112 | ) 113 | 114 | raise NotImplementedError("Unknown ecosystem: {}".format(ecosystem_name)) 115 | -------------------------------------------------------------------------------- /tests/python/instrument_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2019 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # type: ignore 18 | 19 | """Test instrumentation inside a virtual environment.""" 20 | 21 | import json 22 | import os 23 | import pytest 24 | from tests.base_test import SolverTestCase 25 | 26 | from thoth.solver.python.instrument import find_distribution_name 27 | from thoth.solver.python.instrument import get_package_metadata 28 | from thoth.solver.python.instrument import execute_env_function 29 | 30 | 31 | def _func_err(): 32 | import sys 33 | 34 | print("this is error message", file=sys.stderr) 35 | print("this is another message", file=sys.stdout) 36 | sys.exit(1) 37 | 38 | 39 | def _func_json(param): 40 | import json 41 | 42 | print(json.dumps({"foo": param})) 43 | 44 | 45 | def _func_env(): 46 | import os 47 | 48 | print(os.environ["FOO"], end="") 49 | 50 | 51 | class TestInstrument(SolverTestCase): 52 | """Test instrumentation of running custom functions inside a virtual environment.""" 53 | 54 | @pytest.mark.parametrize( 55 | "package_version,package_name,distribution_name", 56 | [("selinon==1.1.0", "selinon", "selinon"), ("backports.weakref", "backports-weakref", "backports.weakref")], 57 | ) 58 | def test_find_distribution_name(self, venv, package_version, package_name, distribution_name): 59 | """Test distribution name lookup.""" 60 | venv.install(package_version) 61 | assert find_distribution_name(venv.python, package_name) == distribution_name 62 | 63 | @pytest.mark.parametrize( 64 | "package_name,package_version,metadata_file", 65 | [("delegator.py", "0.1.1", "delegator-py.json"), ("click", "7.0", "click.json")], 66 | ) 67 | def test_get_package_metadata(self, venv, package_version, package_name, metadata_file): 68 | """Test getting package metadata.""" 69 | with open(os.path.join(self.data_dir, "metadata", metadata_file)) as f: 70 | metadata = json.load(f) 71 | 72 | venv.install(f"{package_name}==={package_version}") 73 | discovered_metadata = get_package_metadata(venv.python, package_name) 74 | # Check the correct version is picked during the test run. 75 | assert discovered_metadata.get("version") == package_version 76 | # We don't care about files present now, just check we have some files in the output. 77 | assert "files" in discovered_metadata 78 | discovered_metadata.pop("files") 79 | assert discovered_metadata == metadata 80 | 81 | def test_package_clash(self, venv): 82 | """Test packages which are dependencies of this solver do not affect results of data gathering.""" 83 | import click 84 | 85 | assert click.__version__ != "3.0" 86 | venv.install("click===3.0") 87 | discovered_metadata = get_package_metadata(venv.python, "click") 88 | assert discovered_metadata.get("version") == "3.0" 89 | 90 | def test_execute_env_function_raise_on_error(self, venv): 91 | """Assert raising an error (error propagation turned on by default).""" 92 | with pytest.raises(ValueError) as exc: 93 | execute_env_function(venv.python, _func_err) 94 | assert str(exc).endswith("this is error message") 95 | 96 | def test_execute_env_function_json(self, venv): 97 | """Check parsing a JSON output produced when running a function.""" 98 | assert execute_env_function(venv.python, _func_json, is_json=True, param="bar") == {"foo": "bar"} 99 | 100 | def test_execute_env_function_env(self, venv): 101 | """Check propagation of environment variables to the underlying virtual environment.""" 102 | assert execute_env_function(venv.python, _func_env, is_json=False, env={"FOO": "BAR"}) == "BAR" 103 | -------------------------------------------------------------------------------- /tests/python/python_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2019 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # type: ignore 18 | 19 | """Test solver for Python ecosystem.""" 20 | 21 | import pytest 22 | import json 23 | from pathlib import Path 24 | from tests.base_test import SolverTestCase 25 | 26 | from thoth.solver.python.python import extract_metadata 27 | from thoth.solver.python.python import parse_requirement_str 28 | from thoth.solver.python.python import _pipdeptree as pipdeptree 29 | from thoth.solver.python.python import get_environment_packages 30 | 31 | 32 | class TestPython(SolverTestCase): 33 | """Test solving Python dependencies.""" 34 | 35 | _WINCERTSTORE_REQUIREMENT = { 36 | "package_name": "wincertstore", 37 | "normalized_package_name": "wincertstore", 38 | "specifier": "==0.2", 39 | "resolved_versions": [], 40 | "extras": [], 41 | "extra": ["ssl"], 42 | "marker": 'sys_platform == "win32" and sys_platform == "linux" and extra == "ssl"', 43 | "marker_evaluated": 'sys_platform == "win32" and sys_platform == "linux" and python_version >= "0.0"', 44 | "marker_evaluation_result": False, 45 | "marker_evaluation_error": None, 46 | } 47 | 48 | _XONSH_REQUIREMENT = { 49 | "package_name": "xonsh", 50 | "normalized_package_name": "xonsh", 51 | "specifier": None, 52 | "resolved_versions": [], 53 | "extras": [], 54 | "extra": [], 55 | "marker": 'python_version >= "2.0"', 56 | "marker_evaluated": 'python_version >= "2.0"', 57 | "marker_evaluation_result": True, 58 | "marker_evaluation_error": None, 59 | } 60 | 61 | _DELEGATOR_PY_REQUIREMENT = { 62 | "package_name": "delegator-py", 63 | "normalized_package_name": "delegator-py", 64 | "specifier": "<=0.0", 65 | "resolved_versions": [], 66 | "extras": [], 67 | "extra": [], 68 | "marker": None, 69 | "marker_evaluated": None, 70 | "marker_evaluation_result": True, 71 | "marker_evaluation_error": None, 72 | } 73 | 74 | _SELINON_REQUIREMENT = { 75 | "extra": ["workflow"], 76 | "extras": {"redis", "postgresql"}, 77 | "marker": 'extra == "workflow"', 78 | "marker_evaluated": 'python_version >= "0.0"', 79 | "marker_evaluation_error": None, 80 | "marker_evaluation_result": True, 81 | "normalized_package_name": "selinon", 82 | "package_name": "selinon", 83 | "resolved_versions": [], 84 | "specifier": "==1.1.0", 85 | } 86 | 87 | @pytest.mark.parametrize( 88 | "metadata_file_path,metadata_file_extracted_path", 89 | [("tensorflow.json", "tensorflow_extracted.json")], 90 | ) 91 | def test_extract_metadata(self, metadata_file_path, metadata_file_extracted_path): 92 | """Test extracted metadata.""" 93 | metadata = json.loads((Path(self.data_dir) / "metadata" / metadata_file_path).read_text()) 94 | metadata_extracted = json.loads((Path(self.data_dir) / "metadata" / metadata_file_extracted_path).read_text()) 95 | assert extract_metadata(metadata, "https://pypi.org/simple") == metadata_extracted 96 | 97 | @pytest.mark.parametrize( 98 | "requirement_str,expected_requirement", 99 | [ 100 | ( 101 | # Make disjoint platforms so we always evaluate the marker to False. 102 | 'wincertstore (==0.2) ; (sys_platform == "win32") and (sys_platform == "linux") and extra == \'ssl\'', 103 | _WINCERTSTORE_REQUIREMENT, 104 | ), 105 | ('xonsh ; (python_version >= "2.0")', _XONSH_REQUIREMENT), 106 | ("delegator-py (<=0.0)", _DELEGATOR_PY_REQUIREMENT), 107 | ("selinon[postgresql,redis] (==1.1.0); extra == 'workflow'", _SELINON_REQUIREMENT), 108 | ], 109 | ) 110 | def test_parse_requirement_str(self, requirement_str, expected_requirement): 111 | """Test parse requirement string.""" 112 | result = parse_requirement_str(requirement_str) 113 | if result.get("extras"): 114 | result["extras"] = set(result["extras"]) 115 | assert result == expected_requirement 116 | 117 | def test_pipdeptree_one(self, venv): 118 | """Test pipdetree one.""" 119 | venv.install("selinon==1.1.0") 120 | output = pipdeptree(venv.python, "selinon") 121 | assert "dependencies" in output 122 | output.pop("dependencies") 123 | assert output == {"package": {"package_name": "selinon", "key": "selinon", "installed_version": "1.1.0"}} 124 | 125 | def test_pipdeptree_multiple(self, venv): 126 | """Test pipdetree multiple.""" 127 | venv.install("selinon==1.1.0") 128 | output = pipdeptree(venv.python) 129 | assert len(output) > 1 130 | 131 | def test_get_environment_packages(self, venv): 132 | """Test get environment packages.""" 133 | venv.install("selinon==1.1.0") 134 | assert {"package_name": "selinon", "package_version": "1.1.0"} in get_environment_packages(venv.python) 135 | -------------------------------------------------------------------------------- /thoth/solver/cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # type: ignore 18 | 19 | """Thoth-solver CLI.""" 20 | 21 | import sys 22 | 23 | import click 24 | import logging 25 | import os 26 | import resource 27 | import time 28 | 29 | from thoth.analyzer import print_command_result 30 | from thoth.common import init_logging 31 | 32 | from thoth.solver import __title__ as analyzer_name 33 | from thoth.solver import __version__ as analyzer_version 34 | from thoth.solver.python import resolve as resolve_python 35 | 36 | init_logging() 37 | 38 | _LOG = logging.getLogger("thoth.solver") 39 | 40 | 41 | def _print_version(ctx, _, value): 42 | """Print solver version and exit.""" 43 | if not value or ctx.resilient_parsing: 44 | return 45 | click.echo(analyzer_version) 46 | ctx.exit() 47 | 48 | 49 | @click.group() 50 | @click.pass_context 51 | @click.option("-v", "--verbose", is_flag=True, envvar="THOTH_SOLVER_DEBUG", help="Be verbose about what's going on.") 52 | @click.option( 53 | "--version", 54 | is_flag=True, 55 | is_eager=True, 56 | callback=_print_version, 57 | expose_value=False, 58 | help="Print solver version and exit.", 59 | ) 60 | def cli(ctx=None, verbose=0): 61 | """Thoth solver command line interface.""" 62 | if ctx: 63 | ctx.auto_envvar_prefix = "THOTH_SOLVER" 64 | 65 | if verbose: 66 | _LOG.setLevel(logging.DEBUG) 67 | 68 | _LOG.info("Thoth Dependency Solver v%s", analyzer_version) 69 | _LOG.debug("Debug mode is on") 70 | 71 | 72 | def _limit_memory() -> None: 73 | """Limit memory to cgroup limit if we're inside a container. 74 | 75 | This turn OOM killer errors into python MemoryError exceptions. 76 | """ 77 | for file in [ 78 | '/sys/fs/cgroup/memory/memory.soft_limit_in_bytes', # cgroups v1 79 | '/sys/fs/cgroup/memory/memory.limit_in_bytes', 80 | '/sys/fs/cgroup/memory.high', # cgroups v2 81 | '/sys/fs/cgroup/memory.max', 82 | ]: 83 | try: 84 | with open(file) as limit: 85 | memory = limit.read() 86 | if memory == "max": # memory.high might contain "max" -> indicates to use the memory.max value 87 | continue 88 | value = int(memory) 89 | resource.setrlimit(resource.RLIMIT_AS, (value, value)) 90 | _LOG.info("Limiting memory to %i bytes based on cgroup limit", value) 91 | break 92 | except FileNotFoundError: 93 | pass 94 | 95 | 96 | @cli.command() 97 | @click.pass_context 98 | @click.option( 99 | "--requirements", 100 | "-r", 101 | type=str, 102 | envvar="THOTH_SOLVER_PACKAGES", 103 | required=True, 104 | help="Requirements to be solved.", 105 | ) 106 | @click.option( 107 | "--index", 108 | "-i", 109 | type=str, 110 | envvar="THOTH_SOLVER_INDEXES", 111 | show_default=True, 112 | default="https://pypi.org/simple", 113 | help="A comma separated list of Python indexes to be used when resolving version ranges.", 114 | ) 115 | @click.option( 116 | "--dependency-index", 117 | "-d", 118 | type=str, 119 | envvar="THOTH_SOLVER_DEPENDENCY_INDEXES", 120 | show_default=True, 121 | default=None, 122 | help="A comma separated list of Python indexes to be used when checking dependency versions, " 123 | "defaults to --index if not provided explicitly.", 124 | ) 125 | @click.option( 126 | "--output", 127 | "-o", 128 | type=str, 129 | envvar="THOTH_SOLVER_OUTPUT", 130 | default="-", 131 | help="Output file or remote API to print results to, in case of URL a POST request is issued.", 132 | ) 133 | @click.option("--no-pretty", "-P", is_flag=True, help="Do not print results nicely.") 134 | @click.option( 135 | "--exclude-packages", 136 | "-e", 137 | type=str, 138 | metavar="PKG1,PKG2", 139 | help="A comma separated list of packages that should be excluded from the final listing.", 140 | ) 141 | @click.option( 142 | "--no-transitive", 143 | "-T", 144 | is_flag=True, 145 | envvar="THOTH_SOLVER_NO_TRANSITIVE", 146 | help="Do not check transitive dependencies, run only on provided requirements.", 147 | ) 148 | @click.option( 149 | "--virtualenv", 150 | type=str, 151 | required=False, 152 | envvar="THOTH_SOLVER_VIRTUALENV", 153 | metavar="VENV", 154 | help="Virtual environment to be used - if not provided a new one is created in the current directory.", 155 | ) 156 | @click.option( 157 | "--limited-output", 158 | "-l", 159 | is_flag=True, 160 | envvar="THOTH_SOLVER_LIMITED_OUTPUT", 161 | help="Produce limited output that states only dependencies.", 162 | ) 163 | def python( 164 | click_ctx, 165 | requirements, 166 | index=None, 167 | dependency_index=None, 168 | python_version=3, 169 | exclude_packages=None, 170 | output=None, 171 | no_transitive=True, 172 | no_pretty=False, 173 | virtualenv=None, 174 | limited_output=False, 175 | ): 176 | """Manipulate with dependency requirements using PyPI.""" 177 | start_time = time.monotonic() 178 | requirements = [requirement.strip() for requirement in requirements.split("\\n") if requirement] 179 | 180 | if not requirements: 181 | _LOG.error("No requirements specified, exiting") 182 | sys.exit(1) 183 | 184 | _limit_memory() 185 | 186 | index_urls = index.split(",") if index else ("https://pypi.org/simple",) 187 | dependency_index_urls = dependency_index.split(",") if dependency_index else index_urls 188 | 189 | result = resolve_python( 190 | requirements, 191 | index_urls=index_urls, 192 | dependency_index_urls=dependency_index_urls, 193 | python_version=int(python_version), 194 | transitive=not no_transitive, 195 | exclude_packages=set(map(str.strip, (exclude_packages or "").split(","))), 196 | virtualenv=virtualenv, 197 | limited_output=limited_output, 198 | ) 199 | 200 | print_command_result( 201 | click_ctx, 202 | result, 203 | analyzer=analyzer_name, 204 | analyzer_version=analyzer_version, 205 | output=output or "-", 206 | duration=time.monotonic() - start_time, 207 | pretty=not no_pretty, 208 | ) 209 | 210 | 211 | if __name__ == "__main__": 212 | cli() 213 | -------------------------------------------------------------------------------- /thoth/solver/python/instrument.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2019 - 2021 Fridolin Pokorny 4 | # 5 | # This program is free software: you can redistribute it and / or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | """Functions which are executed inside virtual environment. 19 | 20 | These functions are used to gather characteristics about installed packages which are analyzed. 21 | 22 | All the functions are executed in a virtualenv - they should print information to stdout, if any error occurs 23 | they should print error messages to stderr and call sys.exit with non-zero value. All necessary functions should 24 | be either from standard virtualenv packages or from standard library to remove any dependency inference. 25 | """ 26 | 27 | import inspect 28 | import sys 29 | import shlex 30 | import logging 31 | 32 | from thoth.analyzer import run_command 33 | 34 | from .._typing import MYPY_CHECK_RUNNING 35 | 36 | if MYPY_CHECK_RUNNING: # pragma: no cover 37 | from typing import Dict, Any, Optional, Callable, Union, List 38 | 39 | 40 | _LOGGER = logging.getLogger(__name__) 41 | 42 | 43 | def _find_distribution_name(package_name): # type: (str) -> None 44 | """Find the given distribution based on package name and print out distribution's project name. 45 | 46 | For example, `backports-weakref' has distribution's project nmae `backports.weakref'. This is also 47 | applicable to all namespace'd packages - we need to find the actual name. based on distribution discovery. 48 | """ 49 | import sys 50 | import pkg_resources 51 | from pkg_resources._vendor.packaging.utils import canonicalize_name 52 | 53 | for path in sys.path: 54 | for distribution in pkg_resources.find_distributions(path): 55 | if canonicalize_name(distribution.project_name) == canonicalize_name(package_name): 56 | print(distribution.project_name, end="") 57 | sys.exit(0) 58 | 59 | print("No matching distribution found for ", package_name, file=sys.stderr, end="") 60 | sys.exit(1) 61 | 62 | 63 | def _get_importlib_metadata_metadata(package_name): # type: (str) -> None 64 | """Retrieve all the metadata for the given package.""" 65 | import sys 66 | try: 67 | import importlib_metadata 68 | except ImportError: 69 | import importlib.metadata as importlib_metadata # type: ignore 70 | import json 71 | 72 | result = dict(importlib_metadata.metadata(package_name).items()) # type: ignore 73 | 74 | # As metadata are encoded as email.message, it's not possible to implicitly expose information about which keys 75 | # keep multiple values and which are single-value. Let's explicitly maintain a list for metadata keys that 76 | # are arrays: 77 | # https://packaging.python.org/specifications/core-metadata 78 | keys = frozenset( 79 | ( 80 | "Platform", 81 | "Supported-Platform", 82 | "Classifier", 83 | "Provides-Dist", 84 | "Requires-Dist", 85 | "Requires-External", 86 | "Project-URL", 87 | "Provides-Extra", 88 | ), 89 | ) 90 | for key in keys: 91 | value = importlib_metadata.metadata(package_name).get_all(key) 92 | if value: 93 | # Override the previous one (single value) with array. 94 | result[key] = value 95 | 96 | print(json.dumps(result)) 97 | sys.exit(0) 98 | 99 | 100 | def _get_importlib_metadata_version(package_name): # type: (str) -> None 101 | """Retrieve version based on the given package.""" 102 | import sys 103 | try: 104 | import importlib_metadata 105 | except ImportError: 106 | import importlib.metadata as importlib_metadata # type: ignore 107 | 108 | print(importlib_metadata.version(package_name), end="") # type: ignore 109 | sys.exit(0) 110 | 111 | 112 | def _get_importlib_metadata_requires(package_name): # type: (str) -> None 113 | """Retrieve requires based on the given package.""" 114 | import sys 115 | try: 116 | import importlib_metadata 117 | except ImportError: 118 | import importlib.metadata as importlib_metadata # type: ignore 119 | import json 120 | 121 | print(json.dumps(importlib_metadata.requires(package_name))) # type: ignore 122 | sys.exit(0) 123 | 124 | 125 | def _get_importlib_metadata_entry_points(package_name): # type: (str) -> None 126 | """Retrieve information about entry-points for the given package.""" 127 | import sys 128 | try: 129 | import importlib_metadata 130 | except ImportError: 131 | import importlib.metadata as importlib_metadata # type: ignore 132 | import json 133 | 134 | entry_points = importlib_metadata.distribution(package_name).entry_points # type: ignore 135 | print(json.dumps([{"name": ep.name, "value": ep.value, "group": ep.group} for ep in entry_points])) 136 | sys.exit(0) 137 | 138 | 139 | def _get_importlib_metadata_files(package_name): # type: (str) -> None 140 | """Retrieve information about files present for the given package.""" 141 | import sys 142 | try: 143 | import importlib_metadata 144 | except ImportError: 145 | import importlib.metadata as importlib_metadata # type: ignore 146 | import json 147 | 148 | print( 149 | json.dumps( 150 | [ 151 | {"hash": f.hash.__dict__ if f.hash else None, "size": f.size, "path": str(f)} 152 | for f in importlib_metadata.files(package_name) # type: ignore 153 | ], 154 | ), 155 | ) 156 | sys.exit(0) 157 | 158 | 159 | def _get_import_path(): # type: () -> None 160 | """Get import path configured for the given Python interpreter.""" 161 | import json 162 | import sys 163 | 164 | json.dump({"path": sys.path}, sys.stdout) 165 | sys.exit(0) 166 | 167 | 168 | def execute_env_function( 169 | python_bin, # type: str 170 | function, # type: Union[Callable[[Any], None], Callable[[], None]] 171 | *, 172 | env=None, # type: Optional[Dict[str, str]] 173 | raise_on_error=True, # type: bool 174 | is_json=False, # type: bool 175 | **function_arguments, # type: Any 176 | ): # type: (...) -> Optional[Union[str, Dict[str, Any], List[str]]] 177 | """Execute the given function in Python interpreter.""" 178 | kwargs = "" 179 | for argument, value in function_arguments.items(): 180 | if kwargs: 181 | kwargs += "," 182 | 183 | kwargs += argument + '="' + value + '"' 184 | 185 | function_source = inspect.getsource(function) 186 | cmd = python_bin + " -c " + (shlex.quote(function_source + "\n\n" + function.__name__ + "(" + kwargs + ")")) 187 | _LOGGER.debug("Executing the following command in Python interpreter (env: %r): %r", env, cmd) 188 | res = run_command(cmd, env=env, is_json=is_json, raise_on_error=False) 189 | 190 | _LOGGER.debug("stderr during command execution: %s", res.stderr) 191 | 192 | if raise_on_error and res.return_code != 0: 193 | raise ValueError("Failed to successfully execute function in Python interpreter: {}".format(res.stderr)) 194 | 195 | _LOGGER.debug("stdout during command execution: %s", res.stdout) 196 | 197 | if res.return_code == 0: 198 | stdout = res.stdout # type: Union[str, Dict[str, Any]] 199 | return stdout 200 | 201 | _LOGGER.error("Failed to successfully execute function in Python interpreter: %r", res.stderr) 202 | return None 203 | 204 | 205 | def get_package_metadata(python_bin, package_name): 206 | # type: (str, str) -> Dict[str, Any] 207 | """Get metadata information from the installed package.""" 208 | # A simple trick when running importlib_metadata - importlib_metadata is present as 209 | # a dependency of this package, but it is not installed in the created virtual environment. 210 | # Inject the current path to the created environment. Note however, the path configured in 211 | # the virtual environment needs to take precedence. 212 | # 213 | # The reversed list is used to make tests happy as pytest-venv injects the current path at the 214 | # beginning. This *SHOULD NOT* affect how solver behaves when run as a data aggregation task in 215 | # the cluster. 216 | venv_path = [ 217 | f 218 | for f in reversed(execute_env_function(python_bin, _get_import_path, is_json=True)["path"]) # type: ignore 219 | if f and f not in sys.path 220 | ] 221 | 222 | return { 223 | "metadata": execute_env_function( 224 | python_bin, 225 | _get_importlib_metadata_metadata, 226 | env={"PYTHONPATH": ":".join(venv_path + sys.path)}, 227 | is_json=True, 228 | package_name=package_name, 229 | ), 230 | "requires": execute_env_function( 231 | python_bin, 232 | _get_importlib_metadata_requires, 233 | env={"PYTHONPATH": ":".join(venv_path + sys.path)}, 234 | is_json=True, 235 | package_name=package_name, 236 | ), 237 | "entry_points": execute_env_function( 238 | python_bin, 239 | _get_importlib_metadata_entry_points, 240 | env={"PYTHONPATH": ":".join(venv_path + sys.path)}, 241 | is_json=True, 242 | package_name=package_name, 243 | ), 244 | "files": execute_env_function( 245 | python_bin, 246 | _get_importlib_metadata_files, 247 | env={"PYTHONPATH": ":".join(venv_path + sys.path)}, 248 | is_json=True, 249 | package_name=package_name, 250 | ), 251 | "version": execute_env_function( 252 | python_bin, 253 | _get_importlib_metadata_version, 254 | env={"PYTHONPATH": ":".join(venv_path + sys.path)}, 255 | is_json=False, 256 | package_name=package_name, 257 | ), 258 | } 259 | 260 | 261 | def find_distribution_name(python_bin, package_name): # type: (str, str) -> str 262 | """Find distribution name based on the package name.""" 263 | result = str(execute_env_function(python_bin, _find_distribution_name, package_name=package_name)) 264 | return result 265 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Thoth Solver documentation build configuration file, created by 4 | # sphinx-quickstart on Thu Mar 14 19:00:10 2019. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | # If extensions (or modules to document with autodoc) are in another directory, 16 | # add these directories to sys.path here. If the directory is relative to the 17 | # documentation root, use os.path.abspath to make it absolute, like shown here. 18 | # 19 | # import os 20 | # import sys 21 | # sys.path.insert(0, os.path.abspath('.')) 22 | 23 | # -- General configuration ------------------------------------------------ 24 | 25 | # If your documentation needs a minimal Sphinx version, state it here. 26 | # 27 | # needs_sphinx = '1.0' 28 | 29 | # Add any Sphinx extension module names here, as strings. They can be 30 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 31 | # ones. 32 | """Thoth Solver documentation build configuration file.""" 33 | extensions = [ 34 | 'sphinx.ext.autodoc', 35 | 'sphinx.ext.intersphinx', 36 | 'sphinx.ext.todo', 37 | 'sphinx.ext.viewcode', 38 | ] 39 | 40 | # Add any paths that contain templates here, relative to this directory. 41 | templates_path = ['_templates'] 42 | 43 | # The suffix(es) of source filenames. 44 | # You can specify multiple suffix as a list of string: 45 | # 46 | # source_suffix = ['.rst', '.md'] 47 | source_suffix = '.rst' 48 | 49 | # The encoding of source files. 50 | # 51 | # source_encoding = 'utf-8-sig' 52 | 53 | # The master toctree document. 54 | master_doc = 'index' 55 | 56 | # General information about the project. 57 | project = 'Thoth Solver' 58 | copyright = '2019, Thoth team' 59 | author = 'Thoth team' 60 | 61 | # The version info for the project you're documenting, acts as replacement for 62 | # |version| and |release|, also used in various other places throughout the 63 | # built documents. 64 | # 65 | # The short X.Y version. 66 | version = 'NA' 67 | # The full version, including alpha/beta/rc tags. 68 | release = 'NA' 69 | 70 | # The language for content autogenerated by Sphinx. Refer to documentation 71 | # for a list of supported languages. 72 | # 73 | # This is also used if you do content translation via gettext catalogs. 74 | # Usually you set "language" from the command line for these cases. 75 | language = None 76 | 77 | # There are two options for replacing |today|: either, you set today to some 78 | # non-false value, then it is used: 79 | # 80 | # today = '' 81 | # 82 | # Else, today_fmt is used as the format for a strftime call. 83 | # 84 | # today_fmt = '%B %d, %Y' 85 | 86 | # List of patterns, relative to source directory, that match files and 87 | # directories to ignore when looking for source files. 88 | # This patterns also effect to html_static_path and html_extra_path 89 | exclude_patterns = [] 90 | 91 | # The reST default role (used for this markup: `text`) to use for all 92 | # documents. 93 | # 94 | # default_role = None 95 | 96 | # If true, '()' will be appended to :func: etc. cross-reference text. 97 | # 98 | # add_function_parentheses = True 99 | 100 | # If true, the current module name will be prepended to all description 101 | # unit titles (such as .. function::). 102 | # 103 | # add_module_names = True 104 | 105 | # If true, sectionauthor and moduleauthor directives will be shown in the 106 | # output. They are ignored by default. 107 | # 108 | # show_authors = False 109 | 110 | # The name of the Pygments (syntax highlighting) style to use. 111 | pygments_style = 'sphinx' 112 | 113 | # A list of ignored prefixes for module index sorting. 114 | # modindex_common_prefix = [] 115 | 116 | # If true, keep warnings as "system message" paragraphs in the built documents. 117 | # keep_warnings = False 118 | 119 | # If true, `todo` and `todoList` produce output, else they produce nothing. 120 | todo_include_todos = True 121 | 122 | 123 | # -- Options for HTML output ---------------------------------------------- 124 | 125 | # The theme to use for HTML and HTML Help pages. See the documentation for 126 | # a list of builtin themes. 127 | # 128 | import sphinx_nameko_theme 129 | 130 | html_theme_path = [sphinx_nameko_theme.get_html_theme_path()] 131 | html_theme = 'nameko' 132 | 133 | # Theme options are theme-specific and customize the look and feel of a theme 134 | # further. For a list of options available for each theme, see the 135 | # documentation. 136 | # 137 | # html_theme_options = {} 138 | 139 | # Add any paths that contain custom themes here, relative to this directory. 140 | # html_theme_path = [] 141 | 142 | # The name for this set of Sphinx documents. 143 | # " v documentation" by default. 144 | # 145 | # html_title = 'Thoth Solver vNA' 146 | 147 | # A shorter title for the navigation bar. Default is the same as html_title. 148 | # 149 | # html_short_title = None 150 | 151 | # The name of an image file (relative to this directory) to place at the top 152 | # of the sidebar. 153 | # 154 | # html_logo = None 155 | 156 | # The name of an image file (relative to this directory) to use as a favicon of 157 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 158 | # pixels large. 159 | # 160 | # html_favicon = None 161 | 162 | # Add any paths that contain custom static files (such as style sheets) here, 163 | # relative to this directory. They are copied after the builtin static files, 164 | # so a file named "default.css" will overwrite the builtin "default.css". 165 | html_static_path = ['_static'] 166 | 167 | # Add any extra paths that contain custom files (such as robots.txt or 168 | # .htaccess) here, relative to this directory. These files are copied 169 | # directly to the root of the documentation. 170 | # 171 | # html_extra_path = [] 172 | 173 | # If not None, a 'Last updated on:' timestamp is inserted at every page 174 | # bottom, using the given strftime format. 175 | # The empty string is equivalent to '%b %d, %Y'. 176 | # 177 | # html_last_updated_fmt = None 178 | 179 | # If true, SmartyPants will be used to convert quotes and dashes to 180 | # typographically correct entities. 181 | # 182 | # html_use_smartypants = True 183 | 184 | # Custom sidebar templates, maps document names to template names. 185 | # 186 | # html_sidebars = {} 187 | 188 | # Additional templates that should be rendered to pages, maps page names to 189 | # template names. 190 | # 191 | # html_additional_pages = {} 192 | 193 | # If false, no module index is generated. 194 | # 195 | # html_domain_indices = True 196 | 197 | # If false, no index is generated. 198 | # 199 | # html_use_index = True 200 | 201 | # If true, the index is split into individual pages for each letter. 202 | # 203 | # html_split_index = False 204 | 205 | # If true, links to the reST sources are added to the pages. 206 | # 207 | # html_show_sourcelink = True 208 | 209 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 210 | # 211 | # html_show_sphinx = True 212 | 213 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 214 | # 215 | # html_show_copyright = True 216 | 217 | # If true, an OpenSearch description file will be output, and all pages will 218 | # contain a tag referring to it. The value of this option must be the 219 | # base URL from which the finished HTML is served. 220 | # 221 | # html_use_opensearch = '' 222 | 223 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 224 | # html_file_suffix = None 225 | 226 | # Language to be used for generating the HTML full-text search index. 227 | # Sphinx supports the following languages: 228 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 229 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' 230 | # 231 | # html_search_language = 'en' 232 | 233 | # A dictionary with options for the search language support, empty by default. 234 | # 'ja' uses this config value. 235 | # 'zh' user can custom change `jieba` dictionary path. 236 | # 237 | # html_search_options = {'type': 'default'} 238 | 239 | # The name of a javascript file (relative to the configuration directory) that 240 | # implements a search results scorer. If empty, the default will be used. 241 | # 242 | # html_search_scorer = 'scorer.js' 243 | 244 | # Output file base name for HTML help builder. 245 | htmlhelp_basename = 'ThothSolverdoc' 246 | 247 | # -- Options for LaTeX output --------------------------------------------- 248 | 249 | latex_elements = { 250 | # The paper size ('letterpaper' or 'a4paper'). 251 | # 252 | # 'papersize': 'letterpaper', 253 | 254 | # The font size ('10pt', '11pt' or '12pt'). 255 | # 256 | # 'pointsize': '10pt', 257 | 258 | # Additional stuff for the LaTeX preamble. 259 | # 260 | # 'preamble': '', 261 | 262 | # Latex figure (float) alignment 263 | # 264 | # 'figure_align': 'htbp', 265 | } 266 | 267 | # Grouping the document tree into LaTeX files. List of tuples 268 | # (source start file, target name, title, 269 | # author, documentclass [howto, manual, or own class]). 270 | latex_documents = [ 271 | ( 272 | master_doc, 'ThothSolver.tex', 'Thoth Solver Documentation', 273 | 'Thoth team', 'manual', 274 | ), 275 | ] 276 | 277 | # The name of an image file (relative to this directory) to place at the top of 278 | # the title page. 279 | # 280 | # latex_logo = None 281 | 282 | # For "manual" documents, if this is true, then toplevel headings are parts, 283 | # not chapters. 284 | # 285 | # latex_use_parts = False 286 | 287 | # If true, show page references after internal links. 288 | # 289 | # latex_show_pagerefs = False 290 | 291 | # If true, show URL addresses after external links. 292 | # 293 | # latex_show_urls = False 294 | 295 | # Documents to append as an appendix to all manuals. 296 | # 297 | # latex_appendices = [] 298 | 299 | # It false, will not define \strong, \code, itleref, \crossref ... but only 300 | # \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added 301 | # packages. 302 | # 303 | # latex_keep_old_macro_names = True 304 | 305 | # If false, no module index is generated. 306 | # 307 | # latex_domain_indices = True 308 | 309 | 310 | # -- Options for manual page output --------------------------------------- 311 | 312 | # One entry per manual page. List of tuples 313 | # (source start file, name, description, authors, manual section). 314 | man_pages = [ 315 | ( 316 | master_doc, 'thothsolver', 'Thoth Solver Documentation', 317 | [author], 1, 318 | ), 319 | ] 320 | 321 | # If true, show URL addresses after external links. 322 | # 323 | # man_show_urls = False 324 | 325 | 326 | # -- Options for Texinfo output ------------------------------------------- 327 | 328 | # Grouping the document tree into Texinfo files. List of tuples 329 | # (source start file, target name, title, author, 330 | # dir menu entry, description, category) 331 | texinfo_documents = [ 332 | ( 333 | master_doc, 'ThothSolver', 'Thoth Solver Documentation', 334 | author, 'ThothSolver', 'One line description of project.', 335 | 'Miscellaneous', 336 | ), 337 | ] 338 | 339 | # Documents to append as an appendix to all manuals. 340 | # 341 | # texinfo_appendices = [] 342 | 343 | # If false, no module index is generated. 344 | # 345 | # texinfo_domain_indices = True 346 | 347 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 348 | # 349 | # texinfo_show_urls = 'footnote' 350 | 351 | # If true, do not generate a @detailmenu in the "Top" node's menu. 352 | # 353 | # texinfo_no_detailmenu = False 354 | 355 | 356 | # Example configuration for intersphinx: refer to the Python standard library. 357 | intersphinx_mapping = {'https://docs.python.org/': None} 358 | -------------------------------------------------------------------------------- /tests/data/metadata/tensorflow_extracted.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "package_name": "absl-py", 5 | "normalized_package_name": "absl-py", 6 | "specifier": ">=0.7.0", 7 | "resolved_versions": [], 8 | "extras": [], 9 | "extra": [], 10 | "marker": null, 11 | "marker_evaluated": null, 12 | "marker_evaluation_result": true, 13 | "marker_evaluation_error": null 14 | }, 15 | { 16 | "package_name": "astor", 17 | "normalized_package_name": "astor", 18 | "specifier": ">=0.6.0", 19 | "resolved_versions": [], 20 | "extras": [], 21 | "extra": [], 22 | "marker": null, 23 | "marker_evaluated": null, 24 | "marker_evaluation_result": true, 25 | "marker_evaluation_error": null 26 | }, 27 | { 28 | "package_name": "gast", 29 | "normalized_package_name": "gast", 30 | "specifier": "==0.2.2", 31 | "resolved_versions": [], 32 | "extras": [], 33 | "extra": [], 34 | "marker": null, 35 | "marker_evaluated": null, 36 | "marker_evaluation_result": true, 37 | "marker_evaluation_error": null 38 | }, 39 | { 40 | "package_name": "google-pasta", 41 | "normalized_package_name": "google-pasta", 42 | "specifier": ">=0.1.6", 43 | "resolved_versions": [], 44 | "extras": [], 45 | "extra": [], 46 | "marker": null, 47 | "marker_evaluated": null, 48 | "marker_evaluation_result": true, 49 | "marker_evaluation_error": null 50 | }, 51 | { 52 | "package_name": "keras-applications", 53 | "normalized_package_name": "keras-applications", 54 | "specifier": ">=1.0.8", 55 | "resolved_versions": [], 56 | "extras": [], 57 | "extra": [], 58 | "marker": null, 59 | "marker_evaluated": null, 60 | "marker_evaluation_result": true, 61 | "marker_evaluation_error": null 62 | }, 63 | { 64 | "package_name": "keras-preprocessing", 65 | "normalized_package_name": "keras-preprocessing", 66 | "specifier": ">=1.0.5", 67 | "resolved_versions": [], 68 | "extras": [], 69 | "extra": [], 70 | "marker": null, 71 | "marker_evaluated": null, 72 | "marker_evaluation_result": true, 73 | "marker_evaluation_error": null 74 | }, 75 | { 76 | "package_name": "numpy", 77 | "normalized_package_name": "numpy", 78 | "specifier": "<2.0,>=1.16.0", 79 | "resolved_versions": [], 80 | "extras": [], 81 | "extra": [], 82 | "marker": null, 83 | "marker_evaluated": null, 84 | "marker_evaluation_result": true, 85 | "marker_evaluation_error": null 86 | }, 87 | { 88 | "package_name": "opt-einsum", 89 | "normalized_package_name": "opt-einsum", 90 | "specifier": ">=2.3.2", 91 | "resolved_versions": [], 92 | "extras": [], 93 | "extra": [], 94 | "marker": null, 95 | "marker_evaluated": null, 96 | "marker_evaluation_result": true, 97 | "marker_evaluation_error": null 98 | }, 99 | { 100 | "package_name": "six", 101 | "normalized_package_name": "six", 102 | "specifier": ">=1.10.0", 103 | "resolved_versions": [], 104 | "extras": [], 105 | "extra": [], 106 | "marker": null, 107 | "marker_evaluated": null, 108 | "marker_evaluation_result": true, 109 | "marker_evaluation_error": null 110 | }, 111 | { 112 | "package_name": "protobuf", 113 | "normalized_package_name": "protobuf", 114 | "specifier": ">=3.6.1", 115 | "resolved_versions": [], 116 | "extras": [], 117 | "extra": [], 118 | "marker": null, 119 | "marker_evaluated": null, 120 | "marker_evaluation_result": true, 121 | "marker_evaluation_error": null 122 | }, 123 | { 124 | "package_name": "tensorboard", 125 | "normalized_package_name": "tensorboard", 126 | "specifier": "<2.1.0,>=2.0.0", 127 | "resolved_versions": [], 128 | "extras": [], 129 | "extra": [], 130 | "marker": null, 131 | "marker_evaluated": null, 132 | "marker_evaluation_result": true, 133 | "marker_evaluation_error": null 134 | }, 135 | { 136 | "package_name": "tensorflow-estimator", 137 | "normalized_package_name": "tensorflow-estimator", 138 | "specifier": "<2.1.0,>=2.0.0", 139 | "resolved_versions": [], 140 | "extras": [], 141 | "extra": [], 142 | "marker": null, 143 | "marker_evaluated": null, 144 | "marker_evaluation_result": true, 145 | "marker_evaluation_error": null 146 | }, 147 | { 148 | "package_name": "termcolor", 149 | "normalized_package_name": "termcolor", 150 | "specifier": ">=1.1.0", 151 | "resolved_versions": [], 152 | "extras": [], 153 | "extra": [], 154 | "marker": null, 155 | "marker_evaluated": null, 156 | "marker_evaluation_result": true, 157 | "marker_evaluation_error": null 158 | }, 159 | { 160 | "package_name": "wrapt", 161 | "normalized_package_name": "wrapt", 162 | "specifier": ">=1.11.1", 163 | "resolved_versions": [], 164 | "extras": [], 165 | "extra": [], 166 | "marker": null, 167 | "marker_evaluated": null, 168 | "marker_evaluation_result": true, 169 | "marker_evaluation_error": null 170 | }, 171 | { 172 | "package_name": "grpcio", 173 | "normalized_package_name": "grpcio", 174 | "specifier": ">=1.8.6", 175 | "resolved_versions": [], 176 | "extras": [], 177 | "extra": [], 178 | "marker": null, 179 | "marker_evaluated": null, 180 | "marker_evaluation_result": true, 181 | "marker_evaluation_error": null 182 | }, 183 | { 184 | "package_name": "wheel", 185 | "normalized_package_name": "wheel", 186 | "specifier": ">=0.26", 187 | "resolved_versions": [], 188 | "extras": [], 189 | "extra": [], 190 | "marker": null, 191 | "marker_evaluated": null, 192 | "marker_evaluation_result": true, 193 | "marker_evaluation_error": null 194 | }, 195 | { 196 | "package_name": "backports.weakref", 197 | "normalized_package_name": "backports-weakref", 198 | "specifier": ">=1.0rc1", 199 | "resolved_versions": [], 200 | "extras": [], 201 | "extra": [], 202 | "marker": "python_version < \"3.4\"", 203 | "marker_evaluated": "python_version < \"3.4\"", 204 | "marker_evaluation_result": false, 205 | "marker_evaluation_error": null 206 | }, 207 | { 208 | "package_name": "enum34", 209 | "normalized_package_name": "enum34", 210 | "specifier": ">=1.1.6", 211 | "resolved_versions": [], 212 | "extras": [], 213 | "extra": [], 214 | "marker": "python_version < \"3.4\"", 215 | "marker_evaluated": "python_version < \"3.4\"", 216 | "marker_evaluation_result": false, 217 | "marker_evaluation_error": null 218 | } 219 | ], 220 | "package_name": "tensorflow", 221 | "package_version": "2.0.0", 222 | "index_url": "https://pypi.org/simple", 223 | "importlib_metadata": { 224 | "metadata": { 225 | "Metadata-Version": "2.1", 226 | "Name": "tensorflow", 227 | "Version": "2.0.0", 228 | "Summary": "TensorFlow is an open source machine learning framework for everyone.", 229 | "Home-page": "https://www.tensorflow.org/", 230 | "Author": "Google Inc.", 231 | "Author-email": "packages@tensorflow.org", 232 | "License": "Apache 2.0", 233 | "Download-URL": "https://github.com/tensorflow/tensorflow/tags", 234 | "Keywords": "tensorflow tensor machine learning", 235 | "Platform": ["UNKNOWN"], 236 | "Classifier": [ 237 | "Programming Language :: Python", 238 | "Programming Language :: Python :: 2.6", 239 | "Programming Language :: Python :: 2.7", 240 | "Programming Language :: Python :: 3", 241 | "Programming Language :: Python :: 3.3", 242 | "Programming Language :: Python :: 3.4", 243 | "Programming Language :: Python :: 3.5", 244 | "Programming Language :: Python :: 3.6", 245 | "Programming Language :: Python :: Implementation :: CPython", 246 | "Programming Language :: Python :: Implementation :: PyPy" 247 | ], 248 | "Requires-Dist": ["enum34 (>=1.1.6) ; python_version < \"3.4\""] 249 | }, 250 | "requires": [ 251 | "absl-py (>=0.7.0)", 252 | "astor (>=0.6.0)", 253 | "gast (==0.2.2)", 254 | "google-pasta (>=0.1.6)", 255 | "keras-applications (>=1.0.8)", 256 | "keras-preprocessing (>=1.0.5)", 257 | "numpy (<2.0,>=1.16.0)", 258 | "opt-einsum (>=2.3.2)", 259 | "six (>=1.10.0)", 260 | "protobuf (>=3.6.1)", 261 | "tensorboard (<2.1.0,>=2.0.0)", 262 | "tensorflow-estimator (<2.1.0,>=2.0.0)", 263 | "termcolor (>=1.1.0)", 264 | "wrapt (>=1.11.1)", 265 | "grpcio (>=1.8.6)", 266 | "wheel (>=0.26)", 267 | "backports.weakref (>=1.0rc1) ; python_version < \"3.4\"", 268 | "enum34 (>=1.1.6) ; python_version < \"3.4\"" 269 | ], 270 | "entry_points": [ 271 | { 272 | "name": "saved_model_cli", 273 | "value": "tensorflow.python.tools.saved_model_cli:main", 274 | "group": "console_scripts" 275 | }, 276 | { 277 | "name": "tensorboard", 278 | "value": "tensorboard.main:run_main", 279 | "group": "console_scripts" 280 | }, 281 | { 282 | "name": "tf_upgrade_v2", 283 | "value": "tensorflow.tools.compatibility.tf_upgrade_v2_main:main", 284 | "group": "console_scripts" 285 | }, 286 | { 287 | "name": "tflite_convert", 288 | "value": "tensorflow.lite.python.tflite_convert:main", 289 | "group": "console_scripts" 290 | }, 291 | { 292 | "name": "toco", 293 | "value": "tensorflow.lite.python.tflite_convert:main", 294 | "group": "console_scripts" 295 | }, 296 | { 297 | "name": "toco_from_protos", 298 | "value": "tensorflow.lite.toco.python.toco_from_protos:main", 299 | "group": "console_scripts" 300 | } 301 | ], 302 | "version": "2.0.0" 303 | } 304 | } 305 | -------------------------------------------------------------------------------- /thoth/solver/python/python.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # thoth-solver 3 | # Copyright(C) 2018 Pavel Odvody 4 | # Copyright(C) 2018 - 2021 Fridolin Pokorny 5 | # 6 | # This program is free software: you can redistribute it and / or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | """Dependency requirements solving for Python ecosystem.""" 20 | 21 | from collections import deque 22 | from contextlib import contextmanager 23 | import logging 24 | import os 25 | from shlex import quote 26 | import sysconfig 27 | from urllib.parse import urlparse 28 | 29 | from packaging.markers import default_environment 30 | 31 | from thoth.analyzer import CommandError 32 | from thoth.analyzer import run_command 33 | from thoth.python import Source 34 | from thoth.python.exceptions import NotFoundError 35 | from thoth.python.exceptions import HTTPError 36 | from thoth.python.helpers import parse_requirement_str 37 | from thoth.license_solver import detect_license 38 | from .python_solver import PythonReleasesFetcher 39 | 40 | from .python_solver import PythonDependencyParser 41 | from .python_solver import PythonSolver 42 | from .instrument import get_package_metadata 43 | from .instrument import find_distribution_name 44 | 45 | from .._typing import MYPY_CHECK_RUNNING 46 | 47 | if MYPY_CHECK_RUNNING: # pragma: no cover 48 | from typing import List, Tuple, Dict, Generator, Optional, Any, Set, Deque 49 | 50 | _LOGGER = logging.getLogger(__name__) 51 | _RAISE_ON_SYSTEM_EXIT_CODE = bool(int(os.getenv("THOTH_SOLVER_RAISE_ON_SYSTEM_EXIT_CODES", 0))) 52 | _UNRESTRICTED_METADATA_KEYS = frozenset( 53 | { 54 | "classifier", 55 | "metadata-version", 56 | "name", 57 | "obsoletes-dist", 58 | "platform", 59 | "provides-dist", 60 | "provides-extra", 61 | "provides-extra", 62 | "requires-dist", 63 | "requires-dist", 64 | "requires-external", 65 | "requires-python", 66 | "supported-platform", 67 | "version", 68 | }, 69 | ) 70 | 71 | 72 | def get_environment_packages(python_bin): # type: (str) -> List[Dict[str, str]] 73 | """Get information about packages in environment where packages get installed.""" 74 | cmd = "{} -m pip freeze".format(python_bin) 75 | output = run_command(cmd, is_json=False).stdout.splitlines() 76 | 77 | result = [] 78 | for line in output: 79 | if line.startswith("thoth-solver"): 80 | # We do not report thoth-solver itself. The version information is 81 | # available in the report metadata produced and the split line can 82 | # cause issues when building thoth-solver in s2i. 83 | # see thoth-station/solver#684 84 | continue 85 | 86 | package_name, package_version = line.split("==", maxsplit=1) 87 | result.append({"package_name": package_name, "package_version": package_version}) 88 | 89 | return result 90 | 91 | 92 | @contextmanager 93 | def _install_requirement(python_bin, package, version=None, index_url=None, clean=True): 94 | # type: (str, str, Optional[str], Optional[str], bool) -> Generator[None, None, None] 95 | """Install requirements specified using suggested pip binary.""" 96 | previous_version = _pipdeptree(python_bin, package) 97 | 98 | try: 99 | cmd = "{} -m pip install --force-reinstall --no-cache-dir --no-deps {}".format(python_bin, quote(package)) 100 | if version: 101 | cmd += "==={}".format(quote(version)) 102 | if index_url: 103 | cmd += ' --index-url "{}" '.format(quote(index_url)) 104 | # Supply trusted host by default so we do not get errors - it safe to 105 | # do it here as package indexes are managed by Thoth. 106 | trusted_host = urlparse(index_url).netloc 107 | cmd += " --trusted-host {}".format(trusted_host) 108 | 109 | _LOGGER.debug("Installing requirement %r in version %r", package, version) 110 | result = run_command(cmd) 111 | _LOGGER.debug("Log during installation:\nstdout: %s\nstderr:%s", result.stdout, result.stderr) 112 | yield 113 | finally: 114 | if clean: 115 | _LOGGER.debug("Removing installed package %r", package) 116 | cmd = "{} -m pip uninstall --yes {}".format(python_bin, quote(package)) 117 | result = run_command(cmd, raise_on_error=False) 118 | 119 | if result.return_code != 0: 120 | _LOGGER.warning( 121 | "Failed to restore previous environment by removing package %r (installed version %r), " 122 | "the error is not fatal but can affect future actions: %s", 123 | package, 124 | version, 125 | result.stderr, 126 | ) 127 | 128 | _LOGGER.debug( 129 | "Restoring previous environment setup after installation of %r (%s)", 130 | package, 131 | previous_version, 132 | ) 133 | if previous_version: 134 | cmd = "{} -m pip install --force-reinstall --no-cache-dir --no-deps {}=={}".format( 135 | python_bin, 136 | quote(package), 137 | quote(previous_version["package"]["installed_version"]), 138 | ) 139 | _LOGGER.debug("Running %r", cmd) 140 | result = run_command(cmd, raise_on_error=False) 141 | 142 | if result.return_code != 0: 143 | _LOGGER.warning( 144 | "Failed to restore previous environment for package %r (installed version %r), " 145 | ", the error is not fatal but can affect future actions (previous version: %r): %s", 146 | package, 147 | version, 148 | previous_version, 149 | result.stderr, 150 | ) 151 | 152 | 153 | def _pipdeptree(python_bin, package_name=None, warn=False): 154 | # type: (str, Optional[str], bool) -> Any 155 | """Get pip dependency tree by executing pipdeptree tool.""" 156 | cmd = "{} -m pipdeptree --json".format(python_bin) 157 | 158 | _LOGGER.debug("Obtaining pip dependency tree using: %r", cmd) 159 | output = run_command(cmd, is_json=True).stdout # type: List[Dict[str, Any]] 160 | 161 | if not package_name: 162 | return output 163 | 164 | for entry in output: # type: Dict[str, Any] 165 | # In some versions pipdeptree does not work with --packages flag, do the logic on out own. 166 | # TODO: we should probably do difference of reference this output and original environment 167 | if entry["package"]["key"].lower() == package_name.lower(): 168 | return entry 169 | 170 | # The given package was not found. 171 | if warn: 172 | _LOGGER.warning("Package %r was not found in pipdeptree output %r", package_name, output) 173 | return None 174 | 175 | 176 | def extract_metadata(metadata, index_url): 177 | # type: (Dict[str, Any], str) -> Dict[str, Any] 178 | """Extract and enhance information from metadata.""" 179 | result = { 180 | "dependencies": [], 181 | "package_name": metadata["metadata"].get("Name"), 182 | "package_version": metadata["metadata"].get("Version"), 183 | "index_url": index_url, 184 | "importlib_metadata": metadata, 185 | } 186 | 187 | for requirement_str in metadata.get("requires") or []: 188 | result["dependencies"].append(parse_requirement_str(requirement_str)) 189 | 190 | return result 191 | 192 | 193 | def _resolve_versions(solver, package_name, version_spec): 194 | # type: (PythonSolver, str, str) -> List[str] 195 | try: 196 | resolved_versions = solver.solve([package_name + (version_spec or "")]) 197 | except NotFoundError: 198 | _LOGGER.info( 199 | "No versions were resolved for %r with version specification %r for package index %r", 200 | package_name, 201 | version_spec, 202 | solver.releases_fetcher.source.url, 203 | ) 204 | return [] 205 | except HTTPError: 206 | _LOGGER.info( 207 | "Forbidden index %r for package %r with version specification %r", 208 | solver.releases_fetcher.source.url, 209 | package_name, 210 | version_spec, 211 | ) 212 | return [] 213 | except Exception: # pylint: disable=broad-except 214 | _LOGGER.exception("Failed to resolve versions for %r with version spec %r", package_name, version_spec) 215 | return [] 216 | 217 | assert len(resolved_versions.keys()) <= 1, "Resolution of one package version ended with multiple packages." 218 | 219 | if not resolved_versions: 220 | return [] 221 | 222 | result = [] 223 | for item in list(resolved_versions.values())[0]: 224 | result.append(item[0]) # We remove information about indexes. 225 | 226 | return result 227 | 228 | 229 | def _fill_hashes(source, package_name, package_version, extracted_metadata): 230 | # type: (Source, str, str, Dict[str, Any]) -> None 231 | extracted_metadata["sha256"] = [] 232 | try: 233 | package_hashes = source.get_package_hashes(package_name, package_version) 234 | except NotFoundError: 235 | # Some older packages have different version on PyPI (considering simple API) than the ones 236 | # stated in metadata. 237 | package_hashes = source.get_package_hashes(package_name, extracted_metadata["version"]) 238 | for item in package_hashes: 239 | extracted_metadata["sha256"].append(item["sha256"]) 240 | 241 | if not extracted_metadata["sha256"]: 242 | raise ValueError(f"No artifact hashes were found for {package_name}=={package_version} on {source.url}") 243 | 244 | 245 | def _do_resolve_index(python_bin, solver, all_dependency_solvers, requirements, exclude_packages, transitive): 246 | # type: (str, PythonSolver, List[PythonSolver], List[str], Optional[Set[str]], bool) -> Dict[str, Any] 247 | """Perform resolution of requirements against the given solver.""" 248 | index_url = solver.releases_fetcher.index_url 249 | source = solver.releases_fetcher.source 250 | 251 | packages_seen = set() 252 | packages = [] 253 | errors = [] 254 | unresolved = [] 255 | unparsed = [] 256 | exclude_packages = exclude_packages or set() 257 | queue = deque() # type: Deque[Tuple[str, str]] 258 | 259 | for requirement in requirements: 260 | _LOGGER.debug("Parsing requirement %r", requirement) 261 | try: 262 | dependency = PythonDependencyParser.parse_python(requirement) 263 | except Exception as exc: 264 | _LOGGER.warning("Failed to parse requirement %r: %s", requirement, str(exc)) 265 | unparsed.append({"requirement": requirement, "details": str(exc)}) 266 | continue 267 | 268 | if dependency.name in exclude_packages: 269 | continue 270 | 271 | version_spec = str(dependency.specifier) 272 | _LOGGER.info( 273 | "Resolving package %r with version specifier %r from %r", 274 | dependency.name, 275 | version_spec, 276 | source.url, 277 | ) 278 | resolved_versions = _resolve_versions(solver, dependency.name, version_spec) 279 | if not resolved_versions: 280 | _LOGGER.warning("No versions were resolved for dependency %r in version %r", dependency.name, version_spec) 281 | error_report = { 282 | "package_name": dependency.name, 283 | "version_spec": version_spec, 284 | "index_url": index_url, 285 | "is_provided_package": source.provides_package(dependency.name), 286 | "is_provided_package_version": None, 287 | } 288 | if version_spec.startswith("=="): 289 | error_report["is_provided_package_version"] = source.provides_package_version( 290 | dependency.name, 291 | version_spec[len("==") :], 292 | ) 293 | 294 | unresolved.append(error_report) 295 | else: 296 | for version in resolved_versions: 297 | _LOGGER.info("Adding package %r in version %r for solving", dependency.name, version) 298 | entry = (dependency.name, version) 299 | packages_seen.add(entry) 300 | queue.append(entry) 301 | 302 | while queue: 303 | package_name, package_version = queue.pop() 304 | _LOGGER.info("Using index %r to discover package %r in version %r", index_url, package_name, package_version) 305 | try: 306 | with _install_requirement(python_bin, package_name, package_version, index_url): 307 | # Translate to distribution name - e.g. thoth-solver is actually distribution thoth.solver. 308 | package_name = find_distribution_name(python_bin, package_name) 309 | package_metadata = get_package_metadata(python_bin, package_name) 310 | extracted_metadata = extract_metadata(package_metadata, index_url) 311 | except (CommandError, Exception) as exc: 312 | _LOGGER.debug( 313 | "There was an error during package %r in version %r discovery from %r: %s", 314 | package_name, 315 | package_version, 316 | index_url, 317 | exc, 318 | ) 319 | if not isinstance(exc, CommandError): 320 | # Report any error happening during metadata aggregation so we know if there is a programming error. 321 | # An example reported message: 322 | # https://github.com/thoth-station/solver/issues/342 323 | _LOGGER.exception("An exception occurred during package metadata gathering") 324 | details = {"message": str(exc)} 325 | else: 326 | if _RAISE_ON_SYSTEM_EXIT_CODE and exc.return_code == -9: 327 | # Raise if the given exit code was a signal sent by the operating system. 328 | raise 329 | details = exc.to_dict() 330 | 331 | errors.append( 332 | { 333 | "package_name": package_name, 334 | "index_url": index_url, 335 | "package_version": package_version, 336 | "type": "command_error", 337 | "details": details, 338 | "is_provided_package": source.provides_package(package_name), 339 | "is_provided_package_version": source.provides_package_version(package_name, package_version), 340 | }, 341 | ) 342 | continue 343 | 344 | # license solver 345 | extracted_metadata["package_license"] = detect_license( 346 | extracted_metadata["importlib_metadata"]["metadata"], 347 | package_name=package_name, 348 | package_version=package_version, 349 | raise_on_error=False, 350 | ) 351 | 352 | _LOGGER.debug( 353 | "Resolved license for package %r in version %r is %r", 354 | package_name, 355 | package_version, 356 | extracted_metadata["package_license"], 357 | ) 358 | 359 | packages.append(extracted_metadata) 360 | if package_version != extracted_metadata["package_version"]: 361 | _LOGGER.warning( 362 | "Requested to install package %r in version %r but installed version is %r", 363 | package_name, 364 | package_version, 365 | extracted_metadata["package_version"], 366 | ) 367 | 368 | extracted_metadata["package_version_requested"] = package_version 369 | _fill_hashes(source, package_name, package_version, extracted_metadata) 370 | 371 | for dependency in extracted_metadata["dependencies"]: 372 | dependency_name, dependency_specifier = ( 373 | dependency["normalized_package_name"], # type: ignore 374 | dependency["specifier"], # type: ignore 375 | ) 376 | 377 | for dep_solver in all_dependency_solvers: 378 | _LOGGER.info( 379 | "Resolving dependency versions for %r with range %r from %r", 380 | dependency_name, 381 | dependency_specifier, 382 | dep_solver.releases_fetcher.index_url, 383 | ) 384 | resolved_versions = _resolve_versions( 385 | dep_solver, 386 | dependency_name, 387 | dependency_specifier or "", 388 | ) 389 | _LOGGER.debug( 390 | "Resolved versions for package %r with range specifier %r: %s", 391 | dependency_name, 392 | dependency_specifier, 393 | resolved_versions, 394 | ) 395 | dependency["resolved_versions"].append( # type: ignore 396 | {"versions": resolved_versions, "index": dep_solver.releases_fetcher.index_url}, 397 | ) 398 | 399 | if not transitive: 400 | continue 401 | 402 | for version in resolved_versions: 403 | # Did we check this package already - do not check indexes, we manually insert them. 404 | seen_entry = (dependency_name, version) 405 | if seen_entry not in packages_seen: 406 | _LOGGER.debug( 407 | "Adding package %r in version %r for next resolution round", 408 | dependency_name, 409 | version, 410 | ) 411 | packages_seen.add(seen_entry) 412 | queue.append((dependency_name, version)) 413 | 414 | return {"tree": packages, "errors": errors, "unparsed": unparsed, "unresolved": unresolved} 415 | 416 | 417 | def resolve( 418 | requirements, 419 | *, 420 | index_urls, 421 | dependency_index_urls, 422 | python_version, 423 | exclude_packages, 424 | transitive, 425 | virtualenv, 426 | limited_output=True, 427 | ): 428 | # type: (List[str], List[str], Optional[List[str]], int, Optional[Set[str]], bool, Optional[str], bool) -> Dict[str, Any] 429 | """Resolve given requirements for the given Python version.""" 430 | assert python_version in (2, 3), "Unknown Python version" 431 | 432 | python_bin = "python3" if python_version == 3 else "python2" 433 | if not virtualenv: 434 | run_command("virtualenv -p " + python_bin + " venv") 435 | python_bin = os.path.join("venv", "bin", python_bin) 436 | run_command("{} -m pip install pipdeptree".format(python_bin)) 437 | else: 438 | python_bin = os.path.join(virtualenv, "bin", python_bin) 439 | 440 | environment_packages = get_environment_packages(python_bin) 441 | 442 | result = { 443 | "tree": [], 444 | "errors": [], 445 | "unparsed": [], 446 | "unresolved": [], 447 | "environment": default_environment(), 448 | "environment_packages": environment_packages, 449 | "platform": sysconfig.get_platform(), 450 | } # type: Dict[str, Any] 451 | 452 | all_solvers = [] 453 | for index_url in index_urls: 454 | all_solvers.append( 455 | PythonSolver( 456 | dependency_parser=PythonDependencyParser(), 457 | releases_fetcher=PythonReleasesFetcher(source=Source(index_url)), 458 | ), 459 | ) 460 | 461 | all_dependency_solvers = [] 462 | if dependency_index_urls: 463 | for index_url in dependency_index_urls: 464 | all_dependency_solvers.append( 465 | PythonSolver( 466 | dependency_parser=PythonDependencyParser(), 467 | releases_fetcher=PythonReleasesFetcher(source=Source(index_url)), 468 | ), 469 | ) 470 | else: 471 | all_dependency_solvers = all_solvers 472 | 473 | for solver in all_solvers: 474 | solver_result = _do_resolve_index( 475 | python_bin=python_bin, 476 | solver=solver, 477 | all_dependency_solvers=all_dependency_solvers, 478 | requirements=requirements, 479 | exclude_packages=exclude_packages, 480 | transitive=transitive, 481 | ) 482 | 483 | result["tree"].extend(solver_result["tree"]) 484 | result["errors"].extend(solver_result["errors"]) 485 | result["unparsed"].extend(solver_result["unparsed"]) 486 | result["unresolved"].extend(solver_result["unresolved"]) 487 | 488 | for item in result["tree"]: 489 | packages = [] 490 | for file_info in item.get("importlib_metadata", {}).get("files") or []: 491 | path = file_info["path"] 492 | parts = path.split(os.path.sep) 493 | if parts[-1] == "__init__.py": 494 | packages.append(".".join(parts[:-1])) 495 | 496 | packages.sort(key=lambda p: (p.count("."), p)) 497 | item["packages"] = packages 498 | 499 | if limited_output: 500 | for entry in result["tree"]: 501 | importlib_metadata = entry["importlib_metadata"] 502 | importlib_metadata.pop("files", None) 503 | 504 | # Drop any metadata such as author, home page, contact e-mail that can be sensitive. 505 | for key in list(importlib_metadata["metadata"].keys()): 506 | if key.lower() not in _UNRESTRICTED_METADATA_KEYS: 507 | _LOGGER.debug("Removing %r from output based on limited output option", key) 508 | importlib_metadata["metadata"].pop(key) 509 | 510 | return result 511 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Thoth Solver 2 | ------------ 3 | 4 | Python dependency solver used in `Thoth project 5 | `__. 6 | 7 | As Python is a dynamic programming language, Thoth runs several types of 8 | solvers that differ in software environment (operating system, native packages 9 | present, system symbols and their versions and Python interpreter version). An 10 | example can be a solver which is running raw RHEL 8.0 with Python 3.6, another 11 | example can be a solver with Fedora 33 with Python 3.9 installed with different 12 | version of glibc and some of the ABI symbols of native libraries provided by 13 | operating system (see also Python manylinux standards and devtools for more 14 | info). 15 | 16 | See the listing built solvers used in Thoth: 17 | 18 | * `quay.io/thoth-station/solver-rhel-8-py38 `__ 19 | 20 | * `quay.io/thoth-station/solver-rhel-8-py36 `__ 21 | 22 | * `quay.io/thoth-station/solver-fedora-34-py39 `__ 23 | 24 | For a `detailed explanation see this blog post 25 | `__. 26 | 27 | This solver is run in different environments (different operating systems with 28 | various native packages provided) to obtain dependency information about Python 29 | packages. An important information is also the fact whether the given Python 30 | package is installable into the environment (e.g. dependencies on native 31 | packages being present in the environment). An example could be UBI 8 specific 32 | solver running Python 3.8 or UBI 8 running Python 3.6 with gcc tooling for 33 | building native extensions. 34 | 35 | The source code is based on the original solver code that was implemented by 36 | Pavel Odvody in project CuCoS. 37 | 38 | Project Scope 39 | ============= 40 | 41 | The aim of this project is to answer a simple question - what packages will be 42 | installed (resolved by pip or any Python compliant dependency resolver) for the 43 | provided stack? 44 | 45 | Imagine you have an application that has one dependency: 46 | 47 | .. code-block:: console 48 | 49 | tensorflow 50 | 51 | Tool provided by this project will tell you what dependencies will be 52 | considered during resolution (the whole dependency graph): 53 | 54 | .. code-block:: console 55 | 56 | thoth-solver --verbose python -r tensorflow 57 | 58 | The output of this solver is a dependency analysis for the given software stack 59 | - in the example above, package ``tensorflow`` in any release with analysis of 60 | its all dependencies (direct and indirect ones) with additional information 61 | from Python ecosystem needed for a Python resolver to perform the actual 62 | ``tensorflow`` resolution. 63 | 64 | The tool also allows specifying custom Python package indexes which conform to 65 | `PEP-503 `__ - see the ``--index`` 66 | option for analyzing your custom Python packages provided by your repositories. 67 | 68 | It is also possible to restrict version using standard Python version range 69 | specifiers and/or limit the output just to direct dependencies. 70 | 71 | Produced output 72 | =============== 73 | 74 | This tool (unless ``--no-transitive`` is specified) recursively analyzes all 75 | the dependencies of the desired package inside a specific environment. 76 | Dependencies to be analyzed can be defined in similar to ``requirements.txt`` 77 | file or as a string in a form of: 78 | 79 | .. code-block:: console 80 | 81 | 82 | 83 | Where ```` is the analyzed package name (as present on PyPI for 84 | example), part ```` is optional and creates 85 | version specifier for the given package (if not specified, all versions are 86 | considered). 87 | 88 | An example output shown bellow can be reproduced by running the tool with the 89 | following arguments (with an example of produced log): 90 | 91 | .. code-block:: console 92 | 93 | $ thoth-solver python --requirements 'tensorflow==2.0.0' --index https://pypi.org/simple --no-transitive 94 | 2019-10-01 14:01:02,756 [31432] INFO root:128: Logging to a Sentry instance is turned off 95 | 2019-10-01 14:01:02,756 [31432] INFO root:150: Logging to rsyslog endpoint is turned off 96 | 2019-10-01 14:01:06,838 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'tensorflow==2.0.0' 97 | 2019-10-01 14:01:07,003 [31432] INFO thoth.solver.python.python:356: Using index 'https://pypi.org/simple' to discover package 'tensorflow' in version '2.0.0' 98 | 2019-10-01 14:01:40,568 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'absl-py' with range '>=0.7.0' from 'https://pypi.org/simple' 99 | 2019-10-01 14:01:40,568 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'absl-py>=0.7.0' 100 | 2019-10-01 14:01:40,689 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'astor' with range '>=0.6.0' from 'https://pypi.org/simple' 101 | 2019-10-01 14:01:40,689 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'astor>=0.6.0' 102 | 2019-10-01 14:01:40,841 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'gast' with range '==0.2.2' from 'https://pypi.org/simple' 103 | 2019-10-01 14:01:40,841 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'gast==0.2.2' 104 | 2019-10-01 14:01:40,984 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'google-pasta' with range '>=0.1.6' from 'https://pypi.org/simple' 105 | 2019-10-01 14:01:40,985 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'google-pasta>=0.1.6' 106 | 2019-10-01 14:01:41,104 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'keras-applications' with range '>=1.0.8' from 'https://pypi.org/simple' 107 | 2019-10-01 14:01:41,104 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'keras-applications>=1.0.8' 108 | 2019-10-01 14:01:41,273 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'keras-preprocessing' with range '>=1.0.5' from 'https://pypi.org/simple' 109 | 2019-10-01 14:01:41,274 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'keras-preprocessing>=1.0.5' 110 | 2019-10-01 14:01:41,443 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'numpy' with range '<2.0,>=1.16.0' from 'https://pypi.org/simple' 111 | 2019-10-01 14:01:41,443 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'numpy<2.0,>=1.16.0' 112 | 2019-10-01 14:01:41,723 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'opt-einsum' with range '>=2.3.2' from 'https://pypi.org/simple' 113 | 2019-10-01 14:01:41,723 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'opt-einsum>=2.3.2' 114 | 2019-10-01 14:01:41,828 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'six' with range '>=1.10.0' from 'https://pypi.org/simple' 115 | 2019-10-01 14:01:41,828 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'six>=1.10.0' 116 | 2019-10-01 14:01:41,942 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'protobuf' with range '>=3.6.1' from 'https://pypi.org/simple' 117 | 2019-10-01 14:01:41,943 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'protobuf>=3.6.1' 118 | 2019-10-01 14:01:42,095 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'tensorboard' with range '<2.1.0,>=2.0.0' from 'https://pypi.org/simple' 119 | 2019-10-01 14:01:42,095 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'tensorboard<2.1.0,>=2.0.0' 120 | 2019-10-01 14:01:42,286 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'tensorflow-estimator' with range '<2.1.0,>=2.0.0' from 'https://pypi.org/simple' 121 | 2019-10-01 14:01:42,287 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'tensorflow-estimator<2.1.0,>=2.0.0' 122 | 2019-10-01 14:01:42,411 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'termcolor' with range '>=1.1.0' from 'https://pypi.org/simple' 123 | 2019-10-01 14:01:42,411 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'termcolor>=1.1.0' 124 | 2019-10-01 14:01:42,580 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'wrapt' with range '>=1.11.1' from 'https://pypi.org/simple' 125 | 2019-10-01 14:01:42,581 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'wrapt>=1.11.1' 126 | 2019-10-01 14:01:42,693 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'grpcio' with range '>=1.8.6' from 'https://pypi.org/simple' 127 | 2019-10-01 14:01:42,693 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'grpcio>=1.8.6' 128 | 2019-10-01 14:01:43,007 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'wheel' with range '>=0.26' from 'https://pypi.org/simple' 129 | 2019-10-01 14:01:43,008 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'wheel>=0.26' 130 | 2019-10-01 14:01:43,116 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'backports-weakref' with range '>=1.0rc1' from 'https://pypi.org/simple' 131 | 2019-10-01 14:01:43,117 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'backports-weakref>=1.0rc1' 132 | 2019-10-01 14:01:43,262 [31432] INFO thoth.solver.python.python:405: Resolving dependency versions for 'enum34' with range '>=1.1.6' from 'https://pypi.org/simple' 133 | 2019-10-01 14:01:43,262 [31432] INFO thoth.solver.python.python_solver:113: Parsing dependency 'enum34>=1.1.6' 134 | 135 | An the output can be pretty verbose, the following section describes some most 136 | interesting parts of the output using JSONPath: 137 | 138 | * ``.metadata`` - metadata assigned to the solver run - these metadata are especially useful within project Thoth, where analyzer is run in a cluster, the purpose of metadata is to capture information which could be beneficial when debugging issues which arise in the cluster due to different container environment (e.g. Python version) 139 | * ``.result`` - the actual result as produced by this tool 140 | * ``.result.unparsed`` - a list of requirements that failed to be parsed (wrong dependency specification not conforming to Python standards) 141 | * ``.result.unresolved`` - a list of requirements that failed to be resolved - the reason behind failure can be for example non-existing package or its version on the given Python package index, or for example incompatibility of package distribution with the solver's software environment (Python version, environment markers, ...), or bogus distribution (e.g. forgotten ``requirements.txt`` in the distribution required by ``setup.py`` on package build). 142 | * ``.result.tree`` - the actual serialized dependency tree (broken dependency graph as cyclic dependencies are possible in Python ecosystem) 143 | * ``.result.tree[*].package_name`` - name of the analyzed package 144 | * ``.result.tree[*].package_version`` - version of the analyzed package 145 | * ``.result.tree[*].sha256`` - sha256 digests of artifacts present on the given Python package index 146 | * ``.result.tree[*].importlib_metadata`` - metadata associated with the given package, these metadata are obtained using `importlib-metadata `__, fallback to standard `importlib.metadata `__ on Python3.9+ 147 | 148 | * ``.result.tree[*].importlib_metadata.metadata`` - package metadata - see `packaging docs for more info `__ 149 | * ``.result.tree[*].importlib_metadata.requires`` - raw strings which declare the given Python package requirements as obtained by ``importlib_metadata.requires`` 150 | * ``.result.tree[*].importlib_metadata.version`` - version as obtained by ``importlib_metadata.requires`` 151 | * ``.result.tree[*].importlib_metadata.files`` - file information about the given package (additionally parsed to provide digest, file size and path) as obtained by ``importlib_metadata.files`` 152 | * ``.result.tree[*].importlib_metadata.entry_points`` - entry points as obtained by ``importlib_metadata.entry_points`` (additionally parsed to provide entry point name, group and value) 153 | 154 | .. code-block:: json 155 | 156 | { 157 | "entry_points": [ 158 | { 159 | "group": "console_scripts", 160 | "name": "saved_model_cli", 161 | "value": "tensorflow.python.tools.saved_model_cli:main" 162 | }, 163 | { 164 | "group": "console_scripts", 165 | "name": "tensorboard", 166 | "value": "tensorboard.main:run_main" 167 | }, 168 | { 169 | "group": "console_scripts", 170 | "name": "tf_upgrade_v2", 171 | "value": "tensorflow.tools.compatibility.tf_upgrade_v2_main:main" 172 | }, 173 | { 174 | "group": "console_scripts", 175 | "name": "tflite_convert", 176 | "value": "tensorflow.lite.python.tflite_convert:main" 177 | }, 178 | { 179 | "group": "console_scripts", 180 | "name": "toco", 181 | "value": "tensorflow.lite.python.tflite_convert:main" 182 | }, 183 | { 184 | "group": "console_scripts", 185 | "name": "toco_from_protos", 186 | "value": "tensorflow.lite.toco.python.toco_from_protos:main" 187 | } 188 | ], 189 | "files": [ 190 | { 191 | "hash": { 192 | "mode": "sha256", 193 | "value": "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU" 194 | }, 195 | "path": "tensorflow_core/tools/pip_package/__init__.py", 196 | "size": 0 197 | } 198 | ], 199 | "metadata": { 200 | "Author": "Google Inc.", 201 | "Author-email": "packages@tensorflow.org", 202 | "Classifier": [ 203 | "Development Status :: 5 - Production/Stable", 204 | "Intended Audience :: Developers", 205 | "Intended Audience :: Education", 206 | "Intended Audience :: Science/Research", 207 | "License :: OSI Approved :: Apache Software License", 208 | "Programming Language :: Python :: 2", 209 | "Programming Language :: Python :: 2.7", 210 | "Programming Language :: Python :: 3", 211 | "Programming Language :: Python :: 3.4", 212 | "Programming Language :: Python :: 3.5", 213 | "Programming Language :: Python :: 3.6", 214 | "Programming Language :: Python :: 3.7", 215 | "Topic :: Scientific/Engineering", 216 | "Topic :: Scientific/Engineering :: Mathematics", 217 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 218 | "Topic :: Software Development", 219 | "Topic :: Software Development :: Libraries", 220 | "Topic :: Software Development :: Libraries :: Python Modules" 221 | ], 222 | "Download-URL": "https://github.com/tensorflow/tensorflow/tags", 223 | "Home-page": "https://www.tensorflow.org/", 224 | "Keywords": "tensorflow tensor machine learning", 225 | "License": "Apache 2.0", 226 | "Metadata-Version": "2.1", 227 | "Name": "tensorflow", 228 | "Platform": [ 229 | "UNKNOWN" 230 | ], 231 | "Requires-Dist": [ 232 | "absl-py (>=0.7.0)", 233 | "astor (>=0.6.0)", 234 | "gast (==0.2.2)", 235 | "google-pasta (>=0.1.6)", 236 | "keras-applications (>=1.0.8)", 237 | "keras-preprocessing (>=1.0.5)", 238 | "numpy (<2.0,>=1.16.0)", 239 | "opt-einsum (>=2.3.2)", 240 | "six (>=1.10.0)", 241 | "protobuf (>=3.6.1)", 242 | "tensorboard (<2.1.0,>=2.0.0)", 243 | "tensorflow-estimator (<2.1.0,>=2.0.0)", 244 | "termcolor (>=1.1.0)", 245 | "wrapt (>=1.11.1)", 246 | "grpcio (>=1.8.6)", 247 | "wheel (>=0.26)", 248 | "backports.weakref (>=1.0rc1) ; python_version < \"3.4\"", 249 | "enum34 (>=1.1.6) ; python_version < \"3.4\"" 250 | ], 251 | "Summary": "TensorFlow is an open source machine learning framework for everyone.", 252 | "Version": "2.0.0" 253 | }, 254 | "requires": [ 255 | "absl-py (>=0.7.0)", 256 | "astor (>=0.6.0)", 257 | "gast (==0.2.2)", 258 | "google-pasta (>=0.1.6)", 259 | "keras-applications (>=1.0.8)", 260 | "keras-preprocessing (>=1.0.5)", 261 | "numpy (<2.0,>=1.16.0)", 262 | "opt-einsum (>=2.3.2)", 263 | "six (>=1.10.0)", 264 | "protobuf (>=3.6.1)", 265 | "tensorboard (<2.1.0,>=2.0.0)", 266 | "tensorflow-estimator (<2.1.0,>=2.0.0)", 267 | "termcolor (>=1.1.0)", 268 | "wrapt (>=1.11.1)", 269 | "grpcio (>=1.8.6)", 270 | "wheel (>=0.26)", 271 | "backports.weakref (>=1.0rc1) ; python_version < \"3.4\"", 272 | "enum34 (>=1.1.6) ; python_version < \"3.4\"" 273 | ], 274 | "version": "2.0.0" 275 | } 276 | 277 | The example above shows data associated with ``tensorflow==2.0.0``. The ``files`` 278 | section is intentionally snipped, the file digest is signed as described in 279 | `PEP-427 `__. 280 | 281 | * ``.result.tree[*].dependencies`` - a list of dependencies which can be resolved given requirements specification of the analyzed package 282 | * ``.result.tree[*].dependencies[*].extras`` - name of extras signalizing the given package should be installed with extras as specified in `PEP-508 in extras section `__ 283 | * ``.result.tree[*].dependencies[*].extra`` - name of extra which should be required to take into account this dependency as specified `PEP-508 in extras section `__ 284 | * ``.result.tree[*].dependencies[*].marker`` - a full specification of the environment marker as described in `PEP-508 in environment markers section `__ 285 | * ``.result.tree[*].dependencies[*].marker_evaluation_error`` - a string capturing error information when marker evaluation failed in the run software environment, otherwise ``null`` 286 | * ``.result.tree[*].dependencies[*].marker_evaluated`` - marker defined by the package, but additionally adjusted for evaluation for the current environment (see notes bellow). 287 | * ``.result.tree[*].dependencies[*].marker_evaluation_result`` - a boolean representing if the given marker evaluation was evaluated as ``true`` (the given environment accepts marker) or ``false`` (marker not accepted), a special value of `null` signalizes marker evaluation error (see ``marker_evaluation_error`` for more info) 288 | * ``.result.tree[*].dependencies[*].normalized_package_name`` - a string representing normalized package name as described in `PEP-503 in normalized names section `__ 289 | * ``.result.tree[*].dependencies[*].specifier`` - a version range specifier which was declared by package which depends on the given dependency conforming to `PEP-440 `__ 290 | * ``.result.tree[*].dependencies[*].resolved_versions`` - a list of versions which were resolved given the version range specifier and specified Python package indexes (passed ``--index`` option can specify multiple indexes which causes package discovery on each of them) 291 | 292 | An example of a dependency entry (an entry from one of ``.result.tree[*].dependencies``: 293 | 294 | .. code-block:: json 295 | 296 | { 297 | "extras": [], 298 | "extra": [], 299 | "marker": "python_version < \"3.4\"", 300 | "marker_evaluated": "python_version < \"3.4\"", 301 | "marker_evaluation_error": null, 302 | "marker_evaluation_result": false, 303 | "normalized_package_name": "backports-weakref", 304 | "package_name": "backports.weakref", 305 | "parsed_markers": [ 306 | { 307 | "op": "<", 308 | "value": "3.4", 309 | "variable": "python_version" 310 | } 311 | ], 312 | "resolved_versions": [ 313 | { 314 | "index": "https://pypi.org/simple", 315 | "versions": [ 316 | "1.0rc1", 317 | "1.0.post1" 318 | ] 319 | } 320 | ], 321 | "specifier": ">=1.0rc1" 322 | } 323 | 324 | To evaluate environment markers inside solver environment, there was a need to 325 | adjust marker so that it can be evaluated in the solver environment - see 326 | `PEP-508 in environment markers section 327 | `__ 328 | specification, specifically the following section: 329 | 330 | .. code-block:: 331 | 332 | The "extra" variable is special. It is used by wheels to signal which 333 | specifications apply to a given extra in the wheel METADATA file, but since 334 | the METADATA file is based on a draft version of PEP-426, there is no current 335 | specification for this. Regardless, outside of a context where this special 336 | handling is taking place, the "extra" variable should result in an error like 337 | all other unknown variables. 338 | 339 | Installation and Deployment 340 | =========================== 341 | 342 | This project is also released on `PyPI 343 | `__, so the latest release can be 344 | installed via pip or `Pipenv `__: 345 | 346 | .. code-block:: console 347 | 348 | pipenv install thoth-solver 349 | 350 | Solver is run in `project Thoth `__ to gather 351 | information about package dependencies. Check `thoth-station/thoth-application 352 | `__ repository for 353 | deployment and installation instructions. 354 | 355 | Running solver locally 356 | ====================== 357 | 358 | To run solver locally, first clone the repo and install the project: 359 | 360 | .. code-block:: console 361 | 362 | git clone git@github.com:thoth-station/solver.git thoth-solver 363 | cd thoth-solver 364 | pipenv install --dev 365 | PYTHONPATH='.' ./thoth-solver-cli --help 366 | 367 | Now you can run the solver: 368 | 369 | .. code-block:: console 370 | 371 | pipenv run python3 ./thoth-solver --verbose python -r 'selinon==1.0.0' -i https://pypi.org/simple --no-transitive 372 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------