Skip to content

migrate to Poetry #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on:
pull_request:
push:
branches: [master]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/[email protected]

- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Bootstrap poetry
shell: bash
run: curl -sSL https://install.python-poetry.org | python3 -

- name: Configure poetry
shell: bash
run: poetry config virtualenvs.in-project true

- name: Install dependencies
shell: bash
run: poetry install

- name: Run pytest
shell: bash
run: poetry run python -m phabricator.tests.test_phabricator
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
build/
dist/
.idea
poetry.lock
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

43 changes: 20 additions & 23 deletions phabricator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
import socket
import pkgutil
import time
from typing import MutableMapping
import requests
from requests.adapters import HTTPAdapter, Retry

from ._compat import (
MutableMapping, iteritems, string_types, urlencode,
)


__all__ = ['Phabricator']

Expand Down Expand Up @@ -71,7 +68,7 @@
ARCRC = {}
for conf in ARC_CONFIGS:
if os.path.exists(conf):
with open(conf, 'r') as fobj:
with open(conf) as fobj:
ARCRC.update(json.load(fobj))


Expand Down Expand Up @@ -100,11 +97,11 @@
'pair': tuple,

# str types
'str': string_types,
'string': string_types,
'phid': string_types,
'guids': string_types,
'type': string_types,
'str': str,
'string': str,
'phid': str,
'guids': str,
'type': str,
}

TYPE_INFO_COMMENT_RE = re.compile(r'\s*\([^)]+\)\s*$')
Expand Down Expand Up @@ -133,9 +130,9 @@ def map_param_type(param_type):
if sub_match:
sub_type = sub_match.group(1).lower()

return [PARAM_TYPE_MAP.setdefault(sub_type, string_types)]
return [PARAM_TYPE_MAP.setdefault(sub_type, str)]

return PARAM_TYPE_MAP.setdefault(main_type, string_types)
return PARAM_TYPE_MAP.setdefault(main_type, str)


def parse_interfaces(interfaces):
Expand All @@ -146,7 +143,7 @@ def parse_interfaces(interfaces):
"""
parsed_interfaces = collections.defaultdict(dict)

for m, d in iteritems(interfaces):
for m, d in interfaces.items():
app, func = m.split('.', 1)

method = parsed_interfaces[app][func] = {}
Expand All @@ -158,7 +155,7 @@ def parse_interfaces(interfaces):
method['optional'] = {}
method['required'] = {}

for name, type_info in iteritems(dict(d['params'])):
for name, type_info in dict(d['params']).items():
# Set the defaults
optionality = 'required'
param_type = 'string'
Expand Down Expand Up @@ -194,7 +191,7 @@ def __init__(self, code, message):
self.message = message

def __str__(self):
return '%s: %s' % (self.code, self.message)
return f'{self.code}: {self.message}'


class Result(MutableMapping):
Expand All @@ -219,10 +216,10 @@ def __len__(self):
return len(self.response)

def __repr__(self):
return '<%s: %s>' % (type(self).__name__, repr(self.response))
return f'<{type(self).__name__}: {repr(self.response)}>'


class Resource(object):
class Resource:
def __init__(self, api, interface=None, endpoint=None, method=None, nested=False):
self.api = api
self._interface = interface or copy.deepcopy(parse_interfaces(INTERFACES))
Expand All @@ -244,7 +241,7 @@ def __getattr__(self, attr):
return getattr(self, attr)
interface = self._interface
if self.nested:
attr = "%s.%s" % (self.endpoint, attr)
attr = f"{self.endpoint}.{attr}"
submethod_exists = False
submethod_match = attr + '.'
for key in interface.keys():
Expand Down Expand Up @@ -283,8 +280,8 @@ def validate_kwarg(key, target):
raise ValueError('Wrong argument type: %s is not a list' % key)
elif not validate_kwarg(kwargs.get(key), val):
if isinstance(val, list):
raise ValueError('Wrong argument type: %s is not a list of %ss' % (key, val[0]))
raise ValueError('Wrong argument type: %s is not a %s' % (key, val))
raise ValueError(f'Wrong argument type: {key} is not a list of {val[0]}s')
raise ValueError(f'Wrong argument type: {key} is not a {val}')

conduit = self.api._conduit

Expand Down Expand Up @@ -313,13 +310,13 @@ def validate_kwarg(key, target):
}

# TODO: Use HTTP "method" from interfaces.json
path = '%s%s.%s' % (self.api.host, self.method, self.endpoint)
path = f'{self.api.host}{self.method}.{self.endpoint}'
response = self.session.post(path, data=body, headers=headers, timeout=self.api.timeout)

# Make sure we got a 2xx response indicating success
if not response.status_code >= 200 or not response.status_code < 300:
raise requests.exceptions.HTTPError(
'Bad response status: {0}'.format(response.status_code)
f'Bad response status: {response.status_code}'
)

data = self._parse_response(response.text)
Expand Down Expand Up @@ -366,7 +363,7 @@ def __init__(self, username=None, certificate=None, host=None,
self.clientDescription = socket.gethostname() + ':python-phabricator'
self._conduit = None

super(Phabricator, self).__init__(self, **kwargs)
super().__init__(self, **kwargs)

def _request(self, **kwargs):
raise SyntaxError('You cannot call the Conduit API without a resource.')
Expand Down
26 changes: 0 additions & 26 deletions phabricator/_compat.py

This file was deleted.

2 changes: 1 addition & 1 deletion phabricator/tests/test_phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_endpoint_shadowing(self):
self.assertEqual(
shadowed_endpoints,
[],
"The following endpoints are shadowed: {}".format(shadowed_endpoints)
f"The following endpoints are shadowed: {shadowed_endpoints}"
)

if __name__ == '__main__':
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tool.poetry]
name = "phabricator"
version = "0.10.0"
authors = ["Disqus <[email protected]>"]
repository = "http://github.com/disqus/python-phabricator"
description = "Phabricator API Bindings"
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Operating System :: OS Independent',
'Topic :: Software Development',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
]

[tool.poetry.dependencies]
python = "^3.7"

[tool.poetry.dev-dependencies]
responses = "^0.18.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

41 changes: 0 additions & 41 deletions setup.py

This file was deleted.