Skip to content

Commit

Permalink
Remove support for Mercurial repos.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Sep 27, 2021
1 parent 5a13206 commit 75f9ca5
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 94 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,12 @@ jobs:
git clone --depth 1 https://github.com/aibasel/downward-benchmarks ${DOWNWARD_BENCHMARKS}
echo "DOWNWARD_BENCHMARKS=${DOWNWARD_BENCHMARKS}" >> $GITHUB_ENV
- name: Clone Fast Downward Mercurial
working-directory: ../deps
run: |
sudo apt-get -y install cmake g++ git make python3
export HG_DOWNWARD_REPO=`realpath fast-downward`
hg clone http://hg.fast-downward.org ${HG_DOWNWARD_REPO}
echo "HG_DOWNWARD_REPO=${HG_DOWNWARD_REPO}" >> $GITHUB_ENV
- name: Clone Fast Downward Git
working-directory: ../deps
run: |
export GIT_DOWNWARD_REPO=`realpath fast-downward-git`
git clone --depth 1 https://github.com/aibasel/downward.git ${GIT_DOWNWARD_REPO}
echo "GIT_DOWNWARD_REPO=${GIT_DOWNWARD_REPO}" >> $GITHUB_ENV
export DOWNWARD_REPO=`realpath fast-downward-git`
git clone --depth 1 https://github.com/aibasel/downward.git ${DOWNWARD_REPO}
echo "DOWNWARD_REPO=${DOWNWARD_REPO}" >> $GITHUB_ENV
- name: Download example Singularity image
working-directory: ../deps
Expand All @@ -123,10 +115,7 @@ jobs:
export DOWNWARD_REVISION_CACHE="${GITHUB_WORKSPACE}/revision-cache"
echo CACHE: ${DOWNWARD_REVISION_CACHE}
export DOWNWARD_REPO=${HG_DOWNWARD_REPO}
time tox -e py
export DOWNWARD_REPO=${GIT_DOWNWARD_REPO}
export DOWNWARD_REPO=${DOWNWARD_REPO}
time tox -e py
- name: Test installation with pip
Expand Down
12 changes: 12 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

v7.0 (unreleased)
-----------------

Lab
^^^
* Remove support for Mercurial repositories (Jendrik Seipp).

Downward Lab
^^^^^^^^^^^^
* None so far.


v6.5 (2021-09-27)
-----------------

Expand Down
4 changes: 1 addition & 3 deletions downward/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,9 @@ def add_algorithm(
Example experiment setup:
>>> import os
>>> from lab.cached_revision import get_version_control_system, MERCURIAL
>>> exp = FastDownwardExperiment()
>>> repo = os.environ["DOWNWARD_REPO"]
>>> vcs = get_version_control_system(repo)
>>> rev = "default" if vcs == MERCURIAL else "main"
>>> rev = "main"
Run iPDB using the latest revision on the main branch:
Expand Down
4 changes: 2 additions & 2 deletions examples/downward/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def get_repo_base() -> Path:
"""Get base directory of the repository, as an absolute path.
Search upwards in the directory tree from the main script until a
directory with a subdirectory named ".git" or ".hg" is found.
directory with a subdirectory named ".git" is found.
Abort if the repo base cannot be found."""
path = Path(tools.get_script_path())
while path.parent != path:
if any((path / d).is_dir() for d in [".git", ".hg"]):
if (path / ".git").is_dir():
return path
path = path.parent
sys.exit("repo base could not be found")
Expand Down
4 changes: 1 addition & 3 deletions examples/lmcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from downward.experiment import FastDownwardExperiment
from downward.reports.absolute import AbsoluteReport
from downward.reports.scatter import ScatterPlotReport
from lab import cached_revision
from lab.environments import BaselSlurmEnvironment, LocalEnvironment


Expand All @@ -28,8 +27,7 @@
BENCHMARKS_DIR = os.environ["DOWNWARD_BENCHMARKS"]
# If REVISION_CACHE is None, the default ./data/revision-cache is used.
REVISION_CACHE = os.environ.get("DOWNWARD_REVISION_CACHE")
VCS = cached_revision.get_version_control_system(REPO)
REV = "default" if VCS == cached_revision.MERCURIAL else "main"
REV = "main"

exp = FastDownwardExperiment(environment=ENV, revision_cache=REVISION_CACHE)

Expand Down
5 changes: 2 additions & 3 deletions examples/showcase-options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from downward.reports.compare import ComparativeReport
from downward.reports.scatter import ScatterPlotReport
from downward.reports.taskwise import TaskwiseReport
from lab import cached_revision, reports
from lab import reports
from lab.environments import BaselSlurmEnvironment, LocalEnvironment
from lab.reports import Attribute
from lab.reports.filter import FilterReport
Expand All @@ -31,8 +31,7 @@
REPO = os.environ["DOWNWARD_REPO"]
BENCHMARKS_DIR = os.environ["DOWNWARD_BENCHMARKS"]
REV_CACHE = os.environ.get("DOWNWARD_REVISION_CACHE")
VCS = cached_revision.get_version_control_system(REPO)
REV = "default" if VCS == cached_revision.MERCURIAL else "main"
REV = "main"


# See FAQs in docs for how to use the filters.
Expand Down
84 changes: 16 additions & 68 deletions lab/cached_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
from lab import tools


GIT = "git"
MERCURIAL = "hg"
VERSION_CONTROL_SYSTEMS = [GIT, MERCURIAL]


@functools.lru_cache(maxsize=None)
def _get_id(cmd):
p = subprocess.run(cmd, stdout=subprocess.PIPE)
Expand All @@ -25,14 +20,6 @@ def _get_id(cmd):
return tools.get_string(p.stdout).strip()


def hg_id(repo, args=None, rev=None):
args = args or []
if rev:
args.extend(["-r", str(rev)])
cmd = ["hg", "id", "--repository", repo] + args
return _get_id(tuple(cmd))


def git_id(repo, args=None, rev=None):
args = args or []
if rev:
Expand All @@ -46,34 +33,8 @@ def git_id(repo, args=None, rev=None):
return _get_id(tuple(cmd))


def _raise_unknown_vcs_error(vcs):
raise AssertionError(f'Unknown version control system "{vcs}".')


def get_version_control_system(repo):
vcs = [
x
for x in VERSION_CONTROL_SYSTEMS
if os.path.exists(os.path.join(repo, f".{x}"))
]
if len(vcs) == 1:
return vcs[0]
else:
dirs = ", ".join(f".{x}" for x in VERSION_CONTROL_SYSTEMS)
logging.critical(
f"Repo {repo} must contain exactly one of the following "
f"subdirectories: {dirs}"
)


def get_global_rev(repo, rev=None):
vcs = get_version_control_system(repo)
if vcs == MERCURIAL:
return hg_id(repo, args=["-i"], rev=rev)
elif vcs == GIT:
return git_id(repo, rev=rev)
else:
_raise_unknown_vcs_error(vcs)
return git_id(repo, rev=rev)


def _compute_md5_hash(mylist):
Expand Down Expand Up @@ -111,12 +72,10 @@ def __init__(self, repo, rev, build_cmd, exclude=None):
transparently for you.
>>> import os
>>> from lab.cached_revision import get_version_control_system, MERCURIAL
>>> repo = os.environ["DOWNWARD_REPO"]
>>> revision_cache = os.environ.get("DOWNWARD_REVISION_CACHE")
>>> if revision_cache:
... vcs = get_version_control_system(repo)
... rev = "default" if vcs == MERCURIAL else "main"
... rev = "main"
... cr = CachedRevision(repo, rev, ["./build.py"], exclude=["experiments"])
... # cr.cache(revision_cache) # Uncomment to actually cache the code.
Expand Down Expand Up @@ -159,31 +118,20 @@ def cache(self, revision_cache):
)
else:
tools.makedirs(self.path)
vcs = get_version_control_system(self.repo)
if vcs == MERCURIAL:
retcode = tools.run_command(
["hg", "archive", "-r", self.global_rev]
+ [f"-X{d}" for d in self.exclude]
+ [self.path],
cwd=self.repo,
)
elif vcs == GIT:
tar_archive = os.path.join(self.path, "solver.tgz")
cmd = ["git", "archive", "--format", "tar", self.global_rev]
with open(tar_archive, "w") as f:
retcode = tools.run_command(cmd, stdout=f, cwd=self.repo)

if retcode == 0:
with tarfile.open(tar_archive) as tf:
tf.extractall(self.path)
tools.remove_path(tar_archive)

for exclude_dir in self.exclude:
path = os.path.join(self.path, exclude_dir)
if os.path.exists(path):
tools.remove_path(path)
else:
_raise_unknown_vcs_error(vcs)
tar_archive = os.path.join(self.path, "solver.tgz")
cmd = ["git", "archive", "--format", "tar", self.global_rev]
with open(tar_archive, "w") as f:
retcode = tools.run_command(cmd, stdout=f, cwd=self.repo)

if retcode == 0:
with tarfile.open(tar_archive) as tf:
tf.extractall(self.path)
tools.remove_path(tar_archive)

for exclude_dir in self.exclude:
path = os.path.join(self.path, exclude_dir)
if os.path.exists(path):
tools.remove_path(path)

if retcode != 0:
shutil.rmtree(self.path)
Expand Down

0 comments on commit 75f9ca5

Please sign in to comment.