Skip to content

Commit

Permalink
Wheels6 (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 25, 2020
1 parent 3140299 commit 23662e6
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 198 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build wheel
name: Build wheels

on: [push, pull_request]

Expand All @@ -9,9 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest]
env:
CIBW_SKIP: "pp*win32"
CIBW_TEST_COMMAND: python -u -Wa {project}/psutil/tests/runner.py
CIBW_TEST_COMMAND_MACOS: LC_ALL='en_US.utf8' python -Wa {project}/psutil/tests/runner.py
CIBW_TEST_EXTRAS: test
Expand All @@ -27,10 +26,10 @@ jobs:
run: |
choco install vcpython27 -f -y
- name: "install cibuildwheel"
- name: Install cibuildwheel
run: pip install cibuildwheel==1.4.1

- name: build wheel
- name: Build wheels
run: cibuildwheel .

- name: Upload wheels
Expand Down
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@ include scripts/internal/bench_oneshot.py
include scripts/internal/bench_oneshot_2.py
include scripts/internal/check_broken_links.py
include scripts/internal/clinter.py
include scripts/internal/download_wheels.py
include scripts/internal/download_wheels_appveyor.py
include scripts/internal/download_wheels_github.py
include scripts/internal/fix_flake8.py
include scripts/internal/generate_manifest.py
include scripts/internal/git_pre_commit.py
include scripts/internal/print_access_denied.py
include scripts/internal/print_announce.py
include scripts/internal/print_api_speed.py
include scripts/internal/print_timeline.py
include scripts/internal/print_wheels.py
include scripts/internal/purge_installation.py
include scripts/internal/tidelift.py
include scripts/internal/win_download_wheels.py
include scripts/internal/winmake.py
include scripts/iotop.py
include scripts/killall.py
Expand Down
34 changes: 22 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,25 @@ install-git-hooks: ## Install GIT pre-commit hook.
ln -sf ../../scripts/internal/git_pre_commit.py .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

# ===================================================================
# Wheels
# ===================================================================

download-wheels-appveyor: ## Download latest wheels hosted on appveyor.
$(PYTHON) scripts/internal/download_wheels_appveyor.py --user giampaolo --project psutil

download-wheels-github: ## Download latest wheels hosted on github.
$(PYTHON) scripts/internal/download_wheels_github.py --user=giampaolo --project=psutil --tokenfile=~/.github.token

download-wheels: ## Download wheels from github and appveyor
rm -rf dist
${MAKE} download-wheels-appveyor
${MAKE} download-wheels-github
${MAKE} print-wheels

print-wheels: ## Print downloaded wheels
$(PYTHON) scripts/internal/print_wheels.py

# ===================================================================
# Distribution
# ===================================================================
Expand All @@ -219,20 +238,11 @@ sdist: ## Create tar.gz source distribution.
${MAKE} generate-manifest
$(PYTHON) setup.py sdist

wheel: ## Generate wheel.
$(PYTHON) setup.py bdist_wheel

win-download-wheels: ## Download latest wheels hosted on appveyor.
$(PYTHON) scripts/internal/win_download_wheels.py --user giampaolo --project psutil

download-wheels: ## Download latest wheels hosted on github.
$(PYTHON) scripts/internal/download_wheels.py --user=giampaolo --project=psutil --tokenfile=~/.github.token

upload-src: ## Upload source tarball on https://pypi.org/project/psutil/
${MAKE} sdist
$(PYTHON) setup.py sdist upload
$(PYTHON) -m twine upload dist/*.tar.gz

upload-win-wheels: ## Upload wheels in dist/* directory on PyPI.
upload-wheels: ## Upload wheels in dist/* directory on PyPI.
$(PYTHON) -m twine upload dist/*.whl

# --- others
Expand All @@ -253,7 +263,7 @@ pre-release: ## Check if we're ready to produce a new release.
${MAKE} install
${MAKE} generate-manifest
git diff MANIFEST.in > /dev/null # ...otherwise 'git diff-index HEAD' will complain
${MAKE} win-download-wheels
${MAKE} download-wheels
${MAKE} sdist
$(PYTHON) -c \
"from psutil import __version__ as ver; \
Expand Down
154 changes: 0 additions & 154 deletions scripts/internal/download_wheels.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
from __future__ import print_function
import argparse
import concurrent.futures
import errno
import os
import requests
import shutil
import sys

from psutil import __version__ as PSUTIL_VERSION
Expand All @@ -29,33 +27,12 @@
BASE_URL = 'https://ci.appveyor.com/api'
PY_VERSIONS = ['2.7', '3.5', '3.6', '3.7', '3.8']
TIMEOUT = 30
COLORS = True


def safe_makedirs(path):
try:
os.makedirs(path)
except OSError as err:
if err.errno == errno.EEXIST:
if not os.path.isdir(path):
raise
else:
raise


def safe_rmtree(path):
def onerror(fun, path, excinfo):
exc = excinfo[1]
if exc.errno != errno.ENOENT:
raise

shutil.rmtree(path, onerror=onerror)


def download_file(url):
local_fname = url.split('/')[-1]
local_fname = os.path.join('dist', local_fname)
safe_makedirs('dist')
os.makedirs('dist', exist_ok=True)
r = requests.get(url, stream=True, timeout=TIMEOUT)
tot_bytes = 0
with open(local_fname, 'wb') as f:
Expand Down Expand Up @@ -102,7 +79,6 @@ def rename_27_wheels():


def run(options):
safe_rmtree('dist')
urls = get_file_urls(options)
completed = 0
exc = None
Expand Down
81 changes: 81 additions & 0 deletions scripts/internal/download_wheels_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3

# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Script which downloads wheel files hosted on GitHub:
https://github.com/giampaolo/psutil/actions
It needs an access token string generated from personal GitHub profile:
https://github.com/settings/tokens
The token must be created with at least "public_repo" scope/rights.
If you lose it, just generate a new token.
REST API doc:
https://developer.github.com/v3/actions/artifacts/
"""

import argparse
import json
import os
import requests
import zipfile

from psutil._common import bytes2human
from psutil.tests import safe_rmpath


USER = ""
PROJECT = ""
TOKEN = ""
OUTFILE = "wheels-github.zip"


def get_artifacts():
base_url = "https://api.github.com/repos/%s/%s" % (USER, PROJECT)
url = base_url + "/actions/artifacts"
res = requests.get(url=url, headers={"Authorization": "token %s" % TOKEN})
res.raise_for_status()
data = json.loads(res.content)
return data


def download_zip(url):
print("downloading: " + url)
res = requests.get(url=url, headers={"Authorization": "token %s" % TOKEN})
res.raise_for_status()
totbytes = 0
with open(OUTFILE, 'wb') as f:
for chunk in res.iter_content(chunk_size=16384):
f.write(chunk)
totbytes += len(chunk)
print("got %s, size %s)" % (OUTFILE, bytes2human(totbytes)))


def run():
data = get_artifacts()
download_zip(data['artifacts'][0]['archive_download_url'])
os.makedirs('dist', exist_ok=True)
with zipfile.ZipFile(OUTFILE, 'r') as zf:
zf.extractall('dist')


def main():
global USER, PROJECT, TOKEN
parser = argparse.ArgumentParser(description='GitHub wheels downloader')
parser.add_argument('--user', required=True)
parser.add_argument('--project', required=True)
parser.add_argument('--tokenfile', required=True)
args = parser.parse_args()
USER = args.user
PROJECT = args.project
with open(os.path.expanduser(args.tokenfile)) as f:
TOKEN = f.read().strip()
try:
run()
finally:
safe_rmpath(OUTFILE)


if __name__ == '__main__':
main()
Loading

0 comments on commit 23662e6

Please sign in to comment.