Skip to content

Commit

Permalink
drop git support, since archive fetching is good enough
Browse files Browse the repository at this point in the history
  • Loading branch information
fox4u committed Oct 15, 2023
1 parent 74027fd commit 3b922f5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 58 deletions.
42 changes: 6 additions & 36 deletions buildutils/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
from urllib.parse import urlparse
from urllib.request import urlopen

from git import Repo
from git.exc import InvalidGitRepositoryError, NoSuchPathError
from gitdb.exc import BadName

from .msg import fatal, info, warn

pjoin = os.path.join
Expand Down Expand Up @@ -181,49 +177,23 @@ def handle_remove_readonly(func, path, exc):
raise


def fetch_libzmq_repo_zip(savedir, url):
def fetch_libzmq_archive(savedir, url):
"""fetch libzmq from archive zip"""
dest = pjoin(savedir, 'zeromq')

fetch_path = urlparse(url)
fetch_name = os.path.basename(fetch_path.path)
dest = pjoin(savedir, 'zeromq')
fname_file = pjoin(dest, fetch_name)
# checks for a file with the name of the zip archive
if os.path.exists(fname_file):
info("already have extracted sources from repo archive %s" % fetch_name)
return
else:
if os.path.exists(dest):
shutil.rmtree(dest, ignore_errors=False, onerror=handle_remove_readonly)
fetch_and_extract(savedir, 'zeromq', url=url, fname=fetch_name, checksum=None)
open(fname_file, 'a') # touch the file with the name of the zip archive


def fetch_libzmq_repo(savedir, url, ref):
"""fetch libzmq from repo"""
dest = pjoin(savedir, 'zeromq')

if url.endswith('.zip'):
fetch_libzmq_repo_zip(savedir, url)
else:
try:
repo = Repo(dest)
except (InvalidGitRepositoryError, NoSuchPathError):
info("invalid local repo, clone from %s" % url)
if os.path.exists(dest):
shutil.rmtree(dest, ignore_errors=False, onerror=handle_remove_readonly)
repo = Repo.clone_from(url, dest)

if ref:
try:
commit = repo.commit(ref)
except BadName:
warn("invalid ref %s" % ref)
else:
if repo.head.commit != commit:
info("checking out %s" % ref)
repo.head.reference = commit
repo.head.reset(index=True, working_tree=True)
else:
info("repo head is already %s" % ref)
with open(fname_file, 'a'): # touch the file with the name of the zip archive
pass

# get repo version
zmq_hdr = pjoin(dest, 'include', 'zmq.h')
Expand Down
20 changes: 3 additions & 17 deletions buildutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,12 @@ def config_from_prefix(prefix):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = True
settings['no_libzmq_extension'] = False
settings['zmq_repo_url'] = None
settings['zmq_repo_ref'] = None
elif prefix_lower.startswith('git@'):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = True
settings['no_libzmq_extension'] = False

prefix_split = prefix.split('@', 2)
settings['zmq_repo_url'] = prefix_split[1]
if len(prefix_split) > 2:
settings['zmq_repo_ref'] = prefix_split[2]
else:
settings['zmq_repo_ref'] = None
settings['zmq_archive_url'] = None
elif prefix_lower.startswith('https://') and prefix_lower.endswith('.zip'):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = True
settings['no_libzmq_extension'] = False
settings['zmq_repo_url'] = prefix_lower
settings['zmq_repo_ref'] = None
settings['zmq_archive_url'] = prefix_lower
else:
settings['zmq_prefix'] = os.path.abspath(prefix)
settings['libzmq_extension'] = False
Expand Down Expand Up @@ -177,8 +164,7 @@ def discover_settings(conf_base=None):
'build_ext': {},
'bdist_egg': {},
'win_ver': None,
'zmq_repo_url': None,
'zmq_repo_ref': None,
'zmq_archive_url': None,
}
if sys.platform.startswith('win'):
settings['have_sys_un_h'] = False
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ requires = [
"setuptools_scm[toml]",
"wheel",
"packaging",
"GitPython",
"cffi; implementation_name == 'pypy'",
"cython>=0.29; implementation_name == 'cpython'",
"cython>=0.29.35; implementation_name == 'cpython' and python_version >= '3.12'",
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
discover_settings,
fatal,
fetch_libzmq,
fetch_libzmq_archive,
fetch_libzmq_dll,
fetch_libzmq_repo,
info,
line,
localpath,
Expand Down Expand Up @@ -538,9 +538,9 @@ def bundle_libzmq_extension(self):
if not os.path.exists(bundledir):
os.makedirs(bundledir)

if self.config['zmq_repo_url']:
repo_version = fetch_libzmq_repo(
bundledir, self.config['zmq_repo_url'], self.config['zmq_repo_ref']
if self.config['zmq_archive_url']:
repo_version = fetch_libzmq_archive(
bundledir, self.config['zmq_archive_url']
)
if repo_version and repo_version != bundled_version:
bundled_version = repo_version
Expand Down

0 comments on commit 3b922f5

Please sign in to comment.