From f110e306cb607b53dbe8d3b535f47770f714f28e Mon Sep 17 00:00:00 2001 From: Luca Sbardella Date: Thu, 12 May 2016 07:34:30 +0100 Subject: [PATCH] removed agile scripts, everything in setup.py --- agileplay.py | 4 -- pulsar/__init__.py | 5 +- pulsar/apps/http/__init__.py | 21 +++++---- pulsar_config.py | 61 ------------------------- pulsar_test/__init__.py | 4 +- setup.py | 88 +++++++++++++++++++++++++++++++----- tests/http/base.py | 8 ++-- 7 files changed, 94 insertions(+), 97 deletions(-) delete mode 100644 agileplay.py delete mode 100644 pulsar_config.py diff --git a/agileplay.py b/agileplay.py deleted file mode 100644 index 4785bfdd..00000000 --- a/agileplay.py +++ /dev/null @@ -1,4 +0,0 @@ -from agile import AgileManager - -if __name__ == '__main__': - AgileManager(description='Release manager for pulsar').start() diff --git a/pulsar/__init__.py b/pulsar/__init__.py index e415e8b6..96640a32 100644 --- a/pulsar/__init__.py +++ b/pulsar/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 - -'''Event driven concurrent framework for Python''' +"""Event driven concurrent framework for Python""" import os from .utils.version import get_version @@ -34,7 +34,4 @@ from .utils.config import * # noqa from .async import * # noqa from .apps import * # noqa - -del get_version -# Import data stores from .apps.data import data_stores # noqa diff --git a/pulsar/apps/http/__init__.py b/pulsar/apps/http/__init__.py index 688a38f3..1a243084 100644 --- a/pulsar/apps/http/__init__.py +++ b/pulsar/apps/http/__init__.py @@ -253,7 +253,7 @@ def __init__(self, client, url, method, inp_params=None, headers=None, if auth and not isinstance(auth, Auth): auth = HTTPBasicAuth(*auth) self.auth = auth - self.headers = client.get_headers(self, headers) + self.headers = client._get_headers(headers) self.url = self._full_url(url, params) self.body = self._encode_body(data, files, json) self._set_proxy(proxies, ignored) @@ -496,7 +496,7 @@ def _set_proxy(self, proxies, ignored): self.unredirected_headers['host'] = host_no_default_port(url.scheme, url.netloc) if url.scheme in tls_schemes: - self._ssl = self.client.ssl_context(verify=self.verify, **ignored) + self._ssl = self.client._ssl_context(verify=self.verify, **ignored) request_proxies = self.client.proxies.copy() if proxies: @@ -783,15 +783,15 @@ class HttpClient(AbstractClient): It can be overwritten on :meth:`request`. """ - DEFAULT_HTTP_HEADERS = Headers([ + DEFAULT_HTTP_HEADERS = Headers(( ('Connection', 'Keep-Alive'), ('Accept', '*/*'), ('Accept-Encoding', 'deflate'), - ('Accept-Encoding', 'gzip')], + ('Accept-Encoding', 'gzip')), kind='client') - DEFAULT_TUNNEL_HEADERS = Headers([ + DEFAULT_TUNNEL_HEADERS = Headers(( ('Connection', 'Keep-Alive'), - ('Proxy-Connection', 'Keep-Alive')], + ('Proxy-Connection', 'Keep-Alive')), kind='client') request_parameters = ('max_redirects', 'decompress', 'websocket_handler', 'version', @@ -843,6 +843,7 @@ def __init__(self, proxies=None, headers=None, verify=True, self.bind_event('on_headers', handle_cookies) self.bind_event('post_request', Redirect()) + # API def connect(self, address): if isinstance(address, tuple): address = ':'.join(('%s' % v for v in address)) @@ -974,7 +975,7 @@ async def _request(self, method, url, **params): response = await self._request(method, url, **params) return response - def get_headers(self, request, headers=None): + def _get_headers(self, headers=None): # Returns a :class:`Header` obtained from combining # :attr:`headers` with *headers*. Can handle websocket requests. d = self.headers.copy() @@ -982,9 +983,9 @@ def get_headers(self, request, headers=None): d.override(headers) return d - def ssl_context(self, verify=True, cert_reqs=None, - check_hostname=False, certfile=None, keyfile=None, - cafile=None, capath=None, cadata=None, **kw): + def _ssl_context(self, verify=True, cert_reqs=None, + check_hostname=False, certfile=None, keyfile=None, + cafile=None, capath=None, cadata=None, **kw): assert ssl, 'SSL not supported' cafile = cafile or DEFAULT_CA_BUNDLE_PATH diff --git a/pulsar_config.py b/pulsar_config.py deleted file mode 100644 index cb24c0e6..00000000 --- a/pulsar_config.py +++ /dev/null @@ -1,61 +0,0 @@ -import os -import sys -import json -import subprocess - - -def setup(params, package=None): - if package: - path = os.path.dirname(__file__) - meta = sh('%s %s package_info %s %s' - % (sys.executable, __file__, package, path)) - params.update(json.loads(meta)) - - return params - - -def read(name): - filename = os.path.join(os.path.dirname(__file__), name) - with open(filename) as fp: - return fp.read() - - -def requirements(name): - install_requires = [] - dependency_links = [] - - for line in read(name).split('\n'): - if line.startswith('-e '): - link = line[3:].strip() - if link == '.': - continue - dependency_links.append(link) - line = link.split('=')[1] - line = line.strip() - if line: - install_requires.append(line) - - return install_requires, dependency_links - - -def sh(command): - return subprocess.Popen(command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=True, - universal_newlines=True).communicate()[0] - - -if __name__ == '__main__': - if len(sys.argv) >= 3 and sys.argv[1] == 'package_info': - package = sys.argv[2] - if len(sys.argv) > 3: - sys.path.append(sys.argv[3]) - os.environ['package_info'] = package - pkg = __import__(package) - print(json.dumps(dict(version=pkg.__version__, - description=pkg.__doc__))) - else: - from agile import AgileManager - - AgileManager(description='Release manager for pulsar').start() diff --git a/pulsar_test/__init__.py b/pulsar_test/__init__.py index 80f37e02..9a49adc8 100644 --- a/pulsar_test/__init__.py +++ b/pulsar_test/__init__.py @@ -6,7 +6,7 @@ class Test(orig.test): test_suite = True - start_coverate = False + start_coverage = False list_options = set(['log-level=', 'test-plugins=', 'test-modules=', 'pulsar-args=']) user_options = [ @@ -38,7 +38,7 @@ def finalize_options(self): self.test_args = self.pulsar_args or [] def run_tests(self): - if self.coverage and self.start_coverate: + if self.coverage and self.start_coverage: import coverage from coverage.monkey import patch_multiprocessing p = current_process() diff --git a/setup.py b/setup.py index d727dcd4..b16aedb4 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,61 @@ #!/usr/bin/env python +import sys +import os +import json +import subprocess + from setuptools import setup, find_packages from extensions import ext -import pulsar_config as config import pulsar_test +class PulsarTest(pulsar_test.Test): + start_coverage = True + + +def extend(params, package=None): + if package: + path = os.path.dirname(__file__) + data = sh('%s %s package_info %s %s' + % (sys.executable, __file__, package, path)) + params.update(json.loads(data)) + + return params + + +def read(name): + filename = os.path.join(os.path.dirname(__file__), name) + with open(filename) as fp: + return fp.read() + + +def requirements(name): + install_requires = [] + dependency_links = [] + + for line in read(name).split('\n'): + if line.startswith('-e '): + link = line[3:].strip() + if link == '.': + continue + dependency_links.append(link) + line = link.split('=')[1] + line = line.strip() + if line: + install_requires.append(line) + + return install_requires, dependency_links + + +def sh(command): + return subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True, + universal_newlines=True).communicate()[0] + + meta = dict( name='pulsar', author="Luca Sbardella", @@ -13,7 +63,7 @@ maintainer_email="luca@quantmind.com", url="https://github.com/quantmind/pulsar", license="BSD", - long_description=config.read('README.rst'), + long_description=read('README.rst'), include_package_data=True, setup_requires=['wheel'], packages=find_packages(include=['pulsar', 'pulsar.*', 'pulsar_test']), @@ -43,22 +93,36 @@ ) -class PulsarTest(pulsar_test.Test): - start_coverate = True - - def run_setup(with_cext): params = ext.params() if with_cext else {} params.update(meta) cmdclass = params.get('cmdclass', {}) cmdclass['test'] = PulsarTest params['cmdclass'] = cmdclass - setup(**config.setup(params, 'pulsar')) + setup(**extend(params, 'pulsar')) + + +def package_info(): + package = sys.argv[2] + if len(sys.argv) > 3: + sys.path.append(sys.argv[3]) + os.environ['package_info'] = package + pkg = __import__(package) + print(json.dumps(dict(version=pkg.__version__, + description=pkg.__doc__))) if __name__ == '__main__': - try: - run_setup(True) - except ext.BuildFailed as exc: - print('WARNING: C extensions could not be compiled: %s' % exc.msg) - run_setup(False) + command = sys.argv[1] if len(sys.argv) > 1 else None + if command == 'package_info': + package_info() + elif command == 'agile': + from agile import AgileManager + AgileManager(description='Release manager for pulsar', + argv=sys.argv[2:]).start() + else: + try: + run_setup(True) + except ext.BuildFailed as exc: + print('WARNING: C extensions could not be compiled: %s' % exc.msg) + run_setup(False) diff --git a/tests/http/base.py b/tests/http/base.py index a05421a0..717e7519 100644 --- a/tests/http/base.py +++ b/tests/http/base.py @@ -351,7 +351,7 @@ def test_http11_close(self): http = self.client() self.assertEqual(http.version, 'HTTP/1.1') response = yield from http.get( - self.httpbin(), headers=[('connection', 'close')]) + self.httpbin(), headers={'connection': 'close'}) self.assertEqual(response.headers['connection'], 'close') self._check_pool(http, response, available=0) @@ -653,7 +653,7 @@ def test_media_file(self): # Test if modified since response = yield from http.get( self.httpbin('media/httpbin.js'), - headers=[('If-modified-since', modified)]) + headers={'If-modified-since': modified}) self.assertEqual(response.status_code, 304) self.assertFalse('Content-length' in response.headers) @@ -758,7 +758,7 @@ def test_pool_400(self): def test_415(self): http = self._client response = yield from http.get( - self.httpbin(''), headers=[('accept', 'application/json')]) + self.httpbin(''), headers={'accept': 'application/json'}) self.assertEqual(response.status_code, 415) @unittest.skipUnless(linux, 'Test in linux platform only') @@ -826,7 +826,7 @@ def gen(): fut._loop.call_later(0.5, fut.set_result, result) response = yield from http.post( self.httpbin('post_chunks'), - headers=[('content-type', 'text/plain')], + headers={'content-type': 'text/plain'}, data=gen()) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.content), 300)