Skip to content

Commit

Permalink
add mypy stubs
Browse files Browse the repository at this point in the history
since this is a big change, take the opportunity to apply black, linters to code base
  • Loading branch information
minrk committed Nov 25, 2020
1 parent 1d7c8bc commit 4d9d025
Show file tree
Hide file tree
Showing 167 changed files with 3,777 additions and 2,152 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude = .git,dist,docs,zmq/eventloop/minitornado
ignore = E, F401, F403, F811, F841, W
25 changes: 23 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,31 @@ env:
FORCE_COLOR: "1"

jobs:
lint:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: install dependencies
run: |
pip install --upgrade pip wheel
pip install cython -r test-requirements.txt
- name: flake8
run: flake8 zmq

- name: mypy
run: mypy zmq

test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
timeout-minutes: 10

env:
MACOSX_DEPLOYMENT_TARGET: "10.14"
Expand Down Expand Up @@ -58,7 +80,6 @@ jobs:
python: 3.9
arch: x64


steps:
- uses: actions/checkout@v2

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ jobs:
before_all: "true"
environment: "ZMQ_PREFIX="


- os: windows-2019
name: win_amd64
cibw:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ win-dist
.ipynb_checkpoints
venv
*.code-workspace
.vscode
.vscode
.mypy_cache
43 changes: 26 additions & 17 deletions RELICENSE/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
'7b1ac07a3bbffe70af3adcd663c0cbe6f2a724f7',
'ce97f46881168c4c05d7885dc48a430c520a9683',
'14c16a97ffa95bf645ab27bf5b06c3eabda30e5e',

# accidental swapfile
'93150feb4a80712c6a379f79d561fbc87405ade8',
}


def get_all_commits():
return chain(
repo.iter_commits('master', 'zmq/backend/cython'),
repo.iter_commits(LAST_CORE_COMMIT, 'zmq/core'),
repo.iter_commits(PRE_CORE_COMMIT, ['zmq/_zmq.*']),
)


mailmap = {}
email_names = {}

Expand All @@ -43,46 +44,54 @@ def get_all_commits():
continue
dest, src = pat.findall(line)
mailmap[src] = dest
email_names[dest] = line[:line.index('<')].strip()
email_names[dest] = line[: line.index('<')].strip()

author_commits = defaultdict(lambda : [])
author_commits = defaultdict(lambda: [])

for commit in get_all_commits():

# exclude some specific commits (e.g. docstring typos)
if commit.hexsha in EXCLUDED:
continue
# exclude commits that only touch generated pxi files in backend/cython
backend_cython_files = {
f for f in commit.stats.files
if f.startswith('zmq/backend/cython')
f for f in commit.stats.files if f.startswith('zmq/backend/cython')
}
if backend_cython_files and backend_cython_files.issubset({
'zmq/backend/cython/constant_enums.pxi',
'zmq/backend/cython/constants.pxi',
}):
if backend_cython_files and backend_cython_files.issubset(
{
'zmq/backend/cython/constant_enums.pxi',
'zmq/backend/cython/constants.pxi',
}
):
continue

email = commit.author.email
email = mailmap.get(email, email)
name = email_names.setdefault(email, commit.author.name)
author_commits[email].append(commit)


def sort_key(email_commits):
commits = email_commits[1]
return (len(commits), commits[0].authored_date)


for email, commits in sorted(author_commits.items(), key=sort_key, reverse=True):
if len(commits) <= 2:
msg = '%s (%s)' % (' '.join(c.hexsha[:12] for c in commits), commits[0].authored_datetime.year)
msg = '%s (%s)' % (
' '.join(c.hexsha[:12] for c in commits),
commits[0].authored_datetime.year,
)
else:
msg = "{commits} commits ({start}-{end})".format(
commits=len(commits),
start=commits[-1].authored_datetime.year,
end=commits[0].authored_datetime.year,
)
print("- [ ] {name} {email}: {msg}".format(
name=email_names[email],
email=email,
msg=msg,
))
print(
"- [ ] {name} {email}: {msg}".format(
name=email_names[email],
email=email,
msg=msg,
)
)
2 changes: 1 addition & 1 deletion buildutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .detect import *
from .bundle import *
from .misc import *
from .patch import *
from .patch import *
66 changes: 39 additions & 27 deletions buildutils/bundle.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""utilities for fetching build dependencies."""

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
#
# This bundling code is largely adapted from pyzmq-static's get.sh by
# Brandon Craig-Rhodes, which is itself BSD licensed.
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


import os
Expand All @@ -28,9 +28,9 @@

pjoin = os.path.join

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

bundled_version = (4, 3, 3)
vs = '%i.%i.%i' % bundled_version
Expand All @@ -46,34 +46,38 @@
HERE = os.path.dirname(__file__)
ROOT = os.path.dirname(HERE)

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Utilities
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


def untgz(archive):
return archive.replace('.tar.gz', '')


def localpath(*args):
"""construct an absolute path from a list relative to the root pyzmq directory"""
plist = [ROOT] + list(args)
return os.path.abspath(pjoin(*plist))


def checksum_file(scheme, path):
"""Return the checksum (hex digest) of a file"""
h = getattr(hashlib, scheme)()

with open(path, 'rb') as f:
chunk = f.read(65535)
while chunk:
h.update(chunk)
chunk = f.read(65535)
return h.hexdigest()


def fetch_archive(savedir, url, fname, checksum, force=False):
"""download an archive to a specific location"""
dest = pjoin(savedir, fname)
scheme, digest_ref = checksum.split(':')

if os.path.exists(dest) and not force:
info("already have %s" % dest)
digest = checksum_file(scheme, fname)
Expand All @@ -82,7 +86,7 @@ def fetch_archive(savedir, url, fname, checksum, force=False):
else:
warn("but checksum %s != %s, redownloading." % (digest, digest_ref))
os.remove(fname)

info("fetching %s into %s" % (url, savedir))
if not os.path.exists(savedir):
os.makedirs(savedir)
Expand All @@ -91,13 +95,17 @@ def fetch_archive(savedir, url, fname, checksum, force=False):
f.write(req.read())
digest = checksum_file(scheme, dest)
if digest != digest_ref:
fatal("%s %s mismatch:\nExpected: %s\nActual : %s" % (
dest, scheme, digest_ref, digest))
fatal(
"%s %s mismatch:\nExpected: %s\nActual : %s"
% (dest, scheme, digest_ref, digest)
)
return dest

#-----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# libzmq
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


def fetch_libzmq(savedir):
"""download and extract libzmq"""
Expand All @@ -113,6 +121,7 @@ def fetch_libzmq(savedir):
# remove version suffix:
shutil.move(with_version, dest)


def stage_platform_hpp(zmqroot):
"""stage platform.hpp into libzmq sources
Expand Down Expand Up @@ -162,39 +171,42 @@ def stage_platform_hpp(zmqroot):

def copy_and_patch_libzmq(ZMQ, libzmq):
"""copy libzmq into source dir, and patch it if necessary.
This command is necessary prior to running a bdist on Linux or OS X.
"""
if sys.platform.startswith('win'):
return
# copy libzmq into zmq for bdist
local = localpath('zmq',libzmq)
local = localpath('zmq', libzmq)
if not ZMQ and not os.path.exists(local):
fatal("Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
"or copy libzmq into zmq/ manually prior to running bdist.")
fatal(
"Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
"or copy libzmq into zmq/ manually prior to running bdist."
)
try:
# resolve real file through symlinks
lib = os.path.realpath(pjoin(ZMQ, 'lib', libzmq))
print ("copying %s -> %s"%(lib, local))
print("copying %s -> %s" % (lib, local))
shutil.copy(lib, local)
except Exception:
if not os.path.exists(local):
fatal("Could not copy libzmq into zmq/, which is necessary for bdist. "
"Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
"or copy libzmq into zmq/ manually.")

fatal(
"Could not copy libzmq into zmq/, which is necessary for bdist. "
"Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
"or copy libzmq into zmq/ manually."
)

if sys.platform == 'darwin':
# chmod u+w on the lib,
# which can be user-read-only for some reason
mode = os.stat(local).st_mode
os.chmod(local, mode | stat.S_IWUSR)
# patch install_name on darwin, instead of using rpath
cmd = ['install_name_tool', '-id', '@loader_path/../%s'%libzmq, local]
cmd = ['install_name_tool', '-id', '@loader_path/../%s' % libzmq, local]
try:
p = Popen(cmd, stdout=PIPE,stderr=PIPE)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
except OSError:
fatal("install_name_tool not found, cannot patch libzmq for bundling.")
out,err = p.communicate()
out, err = p.communicate()
if p.returncode:
fatal("Could not patch bundled libzmq install_name: %s"%err, p.returncode)

fatal("Could not patch bundled libzmq install_name: %s" % err, p.returncode)
Loading

0 comments on commit 4d9d025

Please sign in to comment.