Skip to content

Commit

Permalink
Update run-tests.yml (#284)
Browse files Browse the repository at this point in the history
- Test on Python 3.11
- Test on macos
- Generate coverage artifact
- Fix flake8 errors (but do not touch the regexes)
  • Loading branch information
itziakos authored Aug 28, 2024
1 parent 50e00f3 commit 40f1561
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 60 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[run]
branch = True
source = simplesat
relative_files = True

[report]
omit = *test*
Expand Down
77 changes: 62 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
name: Run tests
name: simplesat

on: [pull_request, workflow_dispatch]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
run-tests:
strategy:
matrix:
runtime: ['2.7', '3.6', '3.8', 'pypy3.8']
os: ['ubuntu-latest', 'windows-latest']

runtime: [3.8, 3.11, pypy3.8]
os: [ubuntu-latest, macos-12, macos-latest, windows-latest]
include:
- os: ubuntu-20.04
runtime: 3.6
runs-on: ${{ matrix.os }}

needs: code-lint
steps:
- name: Clone the source
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.runtime }}
- name: Install dev dependencies
run: python -m pip install -r dev_requirements.txt
- name: Install sat-solver
run: python -m pip install .
run: python -m pip install -e .
- name: Run tests
run: haas simplesat

run: coverage run -p -m haas simplesat
- name: Upload Coverage info
uses: actions/upload-artifact@v4
with:
name: coverage-${{matrix.os}}-${{matrix.runtime}}
path: .coverage.*
build-docs:
runs-on: ubuntu-latest

needs: run-tests
steps:
- name: Clone the source
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4
- name: Install necessary apt-get packages
run: |
sudo apt-get update
sudo apt-get install graphviz
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install doc dependencies
Expand All @@ -45,3 +56,39 @@ jobs:
run: python -m pip install .
- name: Build docs
run: cd docs && make html
coverage:
runs-on: ubuntu-latest
needs: run-tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- name: Install coverage
run: pip install coverage
- name: Generate coverage report
run: |
pip install -e .
coverage combine
coverage report
coverage html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/*
code-lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.6
uses: actions/setup-python@v5
with:
python-version: 3.6
- name: Install flake8
run: python -m pip install flake8
- name: Lint codebase
run: python -m flake8 simplesat/
15 changes: 15 additions & 0 deletions simplesat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@
__is_released__ = False
__version__ = __git_revision__ = "unknown"
__version_info__ = (0, 0, 0, "unknown", 0)


__all__ = [
'Requirement',
'InstallRequirement',
'PackageMetadata',
'RepositoryPackageMetadata',
'RepositoryInfo',
'Pool',
'Repository',
'JobType',
'Request',
'__is_released__',
'__version__',
'__version_info__']
8 changes: 8 additions & 0 deletions simplesat/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
from .constraint_modifiers import (
ConstraintModifiers, modify_requirement,
)

__all__ = [
'PrettyPackageStringParser',
'Requirement',
'ConflictRequirement',
'InstallRequirement',
'ConstraintModifiers',
'modify_requirement']
2 changes: 1 addition & 1 deletion simplesat/constraints/package_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_VERSION_RS = "(?P<version>{})".format(_VERSION_R)
_CONSTRAINT_RS = "(?P<constraint>[^,]*)"

CONSTRAINT_BLOCK_RC = re.compile("(?P<kind>\w+)\s*\((?P<constraints>.*?)\)")
CONSTRAINT_BLOCK_RC = re.compile("(?P<kind>\w+)\s*\((?P<constraints>.*?)\)") # noqa
PACKAGE_RC = re.compile(_DISTRIBUTION_RS + _WS_RS + _VERSION_RS)
CONSTRAINT_RC = re.compile(_DISTRIBUTION_RS + _MAYBE_WS_RS + _CONSTRAINT_RS)

Expand Down
2 changes: 1 addition & 1 deletion simplesat/constraints/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(?P<name>{})
(?:-|\s+)
(?P<version>{})
$""".format(_DISTRIBUTION_NAME_R, _VERSION_R),
$""".format(_DISTRIBUTION_NAME_R, _VERSION_R), # noqa
re.VERBOSE)


Expand Down
1 change: 0 additions & 1 deletion simplesat/constraints/tests/test_package_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import unittest

from okonomiyaki.versions import EnpkgVersion
Expand Down
1 change: 0 additions & 1 deletion simplesat/constraints/tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import unittest

from okonomiyaki.versions import EnpkgVersion
Expand Down
2 changes: 1 addition & 1 deletion simplesat/constraints/tests/test_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from okonomiyaki.versions import EnpkgVersion

from simplesat.errors import (
InvalidConstraint, InvalidDependencyString, SolverException
InvalidConstraint, InvalidDependencyString
)

from ..kinds import Equal
Expand Down
9 changes: 5 additions & 4 deletions simplesat/dependency_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ def __init__(self, pool, remote_repositories, installed_repository,
if isinstance(remote_repositories, Repository):
raise ValueError(
u"remote_repositories should be a sequence of "
"repositories, not a repository"
)
u"repositories, not a repository")

self._remote_repositories = remote_repositories
self._last_rules_time = timed_context("Generate Rules")
Expand Down Expand Up @@ -459,7 +458,8 @@ def callback(jobs):
return True
except SatisfiabilityError:
return False
conflicting_jobs = minimal_unsatisfiable_subset(request.jobs, callback)
conflicting_jobs = minimal_unsatisfiable_subset(
request.jobs, callback)
raise SatisfiabilityErrorWithHint(exc.unsat, conflicting_jobs)

def _create_rules_and_initialize_policy(self, request):
Expand Down Expand Up @@ -531,7 +531,8 @@ def _convert_upgrade_request_if_needed(request, remote_repositories,

for p in latest_packages:
upgrade_request.install(
InstallRequirement._from_string("{} == {}".format(p.name, p.version))
InstallRequirement._from_string(
"{} == {}".format(p.name, p.version))
)

return upgrade_request
Expand Down
3 changes: 2 additions & 1 deletion simplesat/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, unsat, conflicting_jobs):
def hint_pretty_string(self):
return (
u"The following jobs are conflicting:\n{}".format(
u"\n".join(" {}".format(str(job)) for job in self.conflicting_jobs)
u"\n".join(
" {}".format(str(job)) for job in self.conflicting_jobs)
)
)
2 changes: 1 addition & 1 deletion simplesat/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, name, version, install_requires=None, conflicts=None,
For example, consider a package that depends on the following:
- nose
- six (> 1.2, <= 1.2.3), or >= 1.2.5-2
Written as intervals, (1.2, 1.2.3] or [1.2.5-2, \infty)
Written as intervals, (1.2, 1.2.3] or [1.2.5-2, \\infty)
- MKL >= 10.1, < 11
The constraint tuple representing this would be:
Expand Down
7 changes: 4 additions & 3 deletions simplesat/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _Job(object):
def __attrs_post_init__(self):
if self.requirement is None and self.kind != JobType.upgrade:
raise ValueError(
u"_Job requirement cannot be none if kind != {}",format(
u"_Job requirement cannot be none if kind != {}".format(
JobType.upgrade
)
)
Expand Down Expand Up @@ -91,8 +91,9 @@ def allow_older(self, package_name):

def _add_job(self, requirement, job_type):
if len(self.jobs) > 0:
if (job_type is JobType.upgrade or
any(job.kind == JobType.upgrade for job in self.jobs)
if (
any(job.kind == JobType.upgrade for job in self.jobs)
or job_type is JobType.upgrade
):
raise ValueError(
u"Requests with upgrade job can only have one job")
Expand Down
4 changes: 2 additions & 2 deletions simplesat/sat/clause.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def rewatch(self, assignments, lit):
def calculate_reason(self, p=None):
"""For a conflicting clause, return the reason for propagating p.
For example, if the clause is x \/ y \/ z, then the reason for
propagating x is -y /\ -z. By convention, f the literal p does not
For example, if the clause is x \\/ y \\/ z, then the reason for
propagating x is -y /\\ -z. By convention, f the literal p does not
occur in the clause, the negative of the whole clause is returned.
"""
Expand Down
2 changes: 1 addition & 1 deletion simplesat/sat/minisat.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, conflict_clause, learned_clause, trails,
self._conflict_paths.extend(paths)

def _key(self, clause):
return tuple(sorted(l for l in clause.lits))
return tuple(sorted(l for l in clause.lits)) # noqa

def _find_conflict_paths(self, end_clauses, relevant_clauses):
""" Return a tuple of paths representing conflicts between a set of
Expand Down
6 changes: 6 additions & 0 deletions simplesat/sat/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
)

InstalledFirstPolicy = LoggedUndeterminedClausePolicy

__all__ = [
'DefaultPolicy',
'LoggedUndeterminedClausePolicy',
'UndeterminedClausePolicy',
'InstalledFirstPolicy']
2 changes: 1 addition & 1 deletion simplesat/sat/policy/policy_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def pkg_key(pkg_id):
for (i, sugg) in enumerate(ids):
pretty = self._log_pretty_pkg_id(sugg)
R = 'R' if sugg in required else ' '
I = 'I' if sugg in installed else ' '
I = 'I' if sugg in installed else ' ' # noqa
change_str = ""
try:
items = self._log_assignment_changes[i + 1].items()
Expand Down
4 changes: 2 additions & 2 deletions simplesat/sat/policy/undetermined_clause_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def _best_candidate(self, package_ids, assignments, update=False):
def _refresh_decision_set(self, assignments, clauses):
assignments.consume_changelog()

all_ids = {abs(l) for c in clauses for l in c.lits}
all_ids = {abs(l) for c in clauses for l in c.lits} # noqa
all_ids.update(self._prefer_installed_pkg_ids)
self._all_ids = all_ids

unsatisfied_clauses = {
clause for clause in clauses
if not any(assignments.value(l) for l in clause.lits)
if not any(assignments.value(l) for l in clause.lits) # noqa
}
self._decision_set.clear()
self._decision_set.update(
Expand Down
15 changes: 10 additions & 5 deletions simplesat/tests/test_dependency_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_constraint_modifiers(self):
# When/Then
result = requirements_are_satisfiable(packages, requirements)
self.assertFalse(result.is_satisfiable)
result = requirements_are_satisfiable(packages, requirements, modifiers)
result = requirements_are_satisfiable(
packages, requirements, modifiers)
self.assertTrue(result.is_satisfiable)


Expand All @@ -99,7 +100,8 @@ def test_simple(self):
packages = packages_from_definition(packages_definition)

def callback(requirements):
return requirements_are_satisfiable(packages, requirements).is_satisfiable
return requirements_are_satisfiable(
packages, requirements).is_satisfiable

r_min_unsat = [
Requirement._from_string("numpy < 1.10"),
Expand Down Expand Up @@ -129,7 +131,8 @@ def test_conflicting_dependencies(self):
packages = packages_from_definition(packages_definition)

def callback(requirements):
return requirements_are_satisfiable(packages, requirements).is_satisfiable
return requirements_are_satisfiable(
packages, requirements).is_satisfiable

r_min_unsat = [
Requirement._from_string("MKL < 11"),
Expand Down Expand Up @@ -174,7 +177,8 @@ def test_conflicting_dependencies2(self):
requirements = requirements_from_definition(requirements_definition)

def callback(requirements):
return requirements_are_satisfiable(packages, requirements).is_satisfiable
return requirements_are_satisfiable(
packages, requirements).is_satisfiable

r_min_unsat = [R("MKL == 11.1.4-1"), R("pandas == 0.12.0-1")]

Expand Down Expand Up @@ -205,7 +209,8 @@ def test_more_than_2_clauses(self):
requirements = requirements_from_definition(requirements_definition)

def callback(requirements):
return requirements_are_satisfiable(packages, requirements).is_satisfiable
return requirements_are_satisfiable(
packages, requirements).is_satisfiable

r_min_unsat = [R("P"), R("Q"), R("R")]

Expand Down
Loading

0 comments on commit 40f1561

Please sign in to comment.