Skip to content

Commit a264e81

Browse files
author
Maxim Avanov
committed
Initial
1 parent 19ce38a commit a264e81

21 files changed

+590
-0
lines changed

.circleci/config.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
working_directory: ~/
9+
10+
docker:
11+
# specify the version you desire here
12+
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
13+
- image: python:3.7.0-alpine3.8
14+
15+
# Specify service dependencies here if necessary
16+
# CircleCI maintains a library of pre-built images
17+
# documented at https://circleci.com/docs/2.0/circleci-images/
18+
19+
steps:
20+
- checkout
21+
# https://circleci.com/docs/2.0/building-docker-images/#overview
22+
- setup_remote_docker
23+
24+
# Download and cache dependencies
25+
- restore_cache:
26+
keys:
27+
- v1-dependencies-{{ checksum "requirements/minimal.txt" }}
28+
- v1-dependencies-{{ checksum "requirements/local.txt" }}
29+
- v1-dependencies-{{ checksum "requirements/test.txt" }}
30+
31+
- run:
32+
name: install dependencies
33+
command: |
34+
python3 -m venv venv
35+
. venv/bin/activate
36+
apk update
37+
apk add --virtual build-deps gcc make python-dev musl-dev
38+
apk add postgresql-dev
39+
pip install -r ./requirements/minimal.txt
40+
pip install -r ./requirements/test.txt
41+
pip install coveralls
42+
- save_cache:
43+
paths:
44+
- ./venv
45+
key: v1-dependencies-{{ checksum "requirements/minimal.txt" }}
46+
47+
# run tests!
48+
# this example uses Django's built-in test-runner
49+
# other common Python testing frameworks include pytest and nose
50+
# https://pytest.org
51+
# https://nose.readthedocs.io
52+
- run:
53+
name: run tests
54+
command: |
55+
. venv/bin/activate
56+
py.test
57+
- store_artifacts:
58+
path: test-reports
59+
destination: test-reports

.github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [avanov]

.github/workflows/pythonpackage.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: GitHub CI
5+
6+
on:
7+
push:
8+
branches: [ master, develop ]
9+
pull_request:
10+
branches: [ master, develop ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.7, 3.8]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v1
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements/minimal.txt
30+
pip install -r requirements/test.txt
31+
pip install -r requirements/local.txt
32+
- name: Test with pytest
33+
run: |
34+
pytest

.gitignore

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.[oa]
2+
*~
3+
.py[co]
4+
__pycache__/
5+
.doit.db
6+
.idea/
7+
.cache/
8+
.pytest_cache/
9+
.mypy_cache/
10+
11+
build/
12+
dist/
13+
*.egg-info/
14+
.DS_Store
15+
16+
.venv/
17+
.local/
18+
19+
docs/_build
20+
21+
*nose*
22+
*node_modules*
23+
# Ignore all test-related files (see setup.py -> setup(tests_require=[]))
24+
*coverage*
25+
# but keep the .coveragerc (for TravisCI/Coveralls services)
26+
!.coveragerc
27+
28+
# Ignore vagrant box meta files
29+
.vagrant/
30+
*-console.log
31+
32+
# Compass/Sass cache
33+
.sass-cache/
34+
35+
# compiled pacific configs
36+
*.pconf
37+
38+
# do not track contents of private directories
39+
*_priv/
40+
41+
# ansible temporary files
42+
deploy/*.retry

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
dist: xenial
3+
sudo: false
4+
language: python
5+
cache: pip
6+
7+
install:
8+
- pip install -r ./requirements/test.txt
9+
- pip install coveralls
10+
- pip install -e ./
11+
python:
12+
- "3.7"
13+
- "3.8"
14+
15+
# --source specifies what packages to cover, you probably want to use that option
16+
script:
17+
# - make typecheck
18+
- pytest --cov=graphql_dsl
19+
20+
after_success: coveralls

CHANGES.rst

Whitespace-only changes.

MANIFEST.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# https://docs.python.org/3/distutils/sourcedist.html#manifest
2+
include README.rst CHANGES.rst LICENSE
3+
recursive-include requirements *.txt
4+
recursive-include graphql_dsl
5+
exclude requirements/test.txt
6+
prune tests

README.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _badges:
2+
3+
.. image:: https://github.com/avanov/graphql-dsl/workflows/GitHub%20CI/badge.svg?branch=develop
4+
:target: https://github.com/avanov/graphql-dsl/actions?query=workflow%3A%22GitHub+CI%22
5+
6+
.. image:: https://travis-ci.org/avanov/graphql-dsl.svg?branch=develop
7+
:target: https://travis-ci.org/avanov/graphql-dsl
8+
9+
.. image:: https://circleci.com/gh/avanov/graphql-dsl/tree/develop.svg?style=svg
10+
:target: https://circleci.com/gh/avanov/graphql-dsl/tree/develop
11+
12+
.. image:: https://coveralls.io/repos/github/avanov/graphql-dsl/badge.svg?branch=develop
13+
:target: https://coveralls.io/github/avanov/graphql-dsl?branch=develop
14+
15+
.. image:: https://requires.io/github/avanov/graphql-dsl/requirements.svg?branch=develop
16+
:target: https://requires.io/github/avanov/graphql-dsl/requirements/?branch=develop
17+
:alt: Requirements Status
18+
19+
.. image:: https://readthedocs.org/projects/graphql-dsl/badge/?version=develop
20+
:target: http://graphql-dsl.readthedocs.org/en/develop/
21+
:alt: Documentation Status
22+
23+
.. image:: http://img.shields.io/pypi/v/graphql-dsl.svg
24+
:target: https://pypi.python.org/pypi/graphql-dsl
25+
:alt: Latest PyPI Release
26+
27+
Compose GraphQL queries by defining Python types
28+
================================================
29+
30+
.. code-block:: bash
31+
32+
pip install graphql-dsl
33+
34+
Find out more from `Official Documentation <https://graphql-dsl.readthedocs.io/en/develop/>`_.

graphql_dsl/__init__.py

Whitespace-only changes.

graphql_dsl/translator.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from typing import Type, Any, Generator, Mapping
2+
3+
from typeit import TypeConstructor
4+
from typeit.tokenizer import iter_tokens, Token
5+
6+
7+
translate_begin_type = lambda x: f'{x.python_name} {{'
8+
translate_begin_type_inner = lambda x: '{'
9+
translate_end_type = lambda x: '}'
10+
translate_begin_attribute = lambda x: f'{x.wire_name}'
11+
translate_end_attribute = lambda x: ' '
12+
13+
14+
translation_map: Mapping[Token, str] = {
15+
Token.BeginType: translate_begin_type,
16+
Token.EndType: translate_end_type,
17+
Token.BeginAttribute: translate_begin_attribute,
18+
Token.EndAttribute: translate_end_attribute,
19+
}
20+
21+
22+
def translate_tokens_to_graphql(typ: Type[Any]) -> Generator[str, None, None]:
23+
""" for graphql queries BeginType should be translated only once - for the topmost type
24+
"""
25+
query_type_began = False
26+
for token in iter_tokens(typ, typer=TypeConstructor):
27+
for token_type, do_translate in translation_map.items():
28+
if isinstance(token, token_type):
29+
if token_type is Token.BeginType:
30+
if query_type_began:
31+
yield translate_begin_type_inner(token)
32+
else:
33+
query_type_began = True
34+
yield do_translate(token)
35+
else:
36+
yield do_translate(token)
37+
break
38+
else:
39+
raise ValueError(f'Unhandled token: {token}')
40+
41+
42+
def translate(typ: Type[Any]) -> str:
43+
return ''.join(translate_tokens_to_graphql(typ))

pytest.ini

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Can also be defined in setup.cfg or tox.ini files, but
2+
# searching stops when the first [pytest] section is found in any of these files.
3+
# There is no merging of configuration values from multiple files.
4+
# Read more on https://pytest.org/latest/customize.html
5+
# -------------------------------------------------------------------------------
6+
[pytest]
7+
# This would tell py.test to not recurse into typical sphinx-build directories or
8+
# into any tmp prefixed directory.
9+
#https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
10+
norecursedirs = _build build dist tmp* *.egg* frontend* docs* deploy*
11+
12+
# One or more Glob-style file patterns determining which python files are considered
13+
# as test modules.
14+
python_files = test_*.py *_test.py *_tests.py *_t.py
15+
16+
# https://docs.pytest.org/en/latest/reference.html#confval-python_classes
17+
python_classes =
18+
Test*
19+
*Tests
20+
21+
# https://docs.pytest.org/en/latest/reference.html#confval-testpaths
22+
testpaths =
23+
tests
24+
25+
# use coverage plugin
26+
addopts = -s

requirements/local.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Sphinx>=3.0.1,<3.1
2+
wheel>=0.34.2,<0.35

requirements/minimal.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/avanov/typeit/archive/master.zip#egg=typeit

requirements/test.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pytest>=5.4.1,<5.5
2+
coverage>=5.1,<5.2
3+
pytest-cov>=2.8.1,<2.9
4+
mypy==0.770
5+
requests>=2.23.0
6+
vcrpy>=4.0.2

setup.cfg

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[mypy]
2+
warn_unused_ignores = true
3+
follow_imports = normal
4+
show_error_context = true
5+
warn_incomplete_stub = true
6+
ignore_missing_imports = true
7+
check_untyped_defs = true
8+
cache_dir = /dev/null
9+
warn_redundant_casts = true
10+
warn_unused_configs = true
11+
strict_optional = true
12+
strict_equality = true
13+
14+
[coverage:report]
15+
# Regexes for lines to exclude from consideration
16+
exclude_lines =
17+
# Have to re-enable the standard pragma
18+
pragma: no cover
19+
20+
ignore_errors = True
21+
22+
[coverage:run]
23+
source =
24+
graphql_dsl

setup.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from pathlib import Path
2+
from setuptools import setup
3+
from setuptools import find_packages
4+
5+
6+
HERE = Path(__file__).absolute().parent
7+
8+
with (HERE / 'README.rst').open() as f:
9+
README = f.read()
10+
11+
with (HERE / 'requirements' / 'minimal.txt').open() as f:
12+
rows = f.read().strip().split('\n')
13+
requires = []
14+
for row in rows:
15+
row = row.strip()
16+
if row and not (row.startswith('#') or row.startswith('https')):
17+
requires.append(row)
18+
19+
20+
# Setup
21+
# ----------------------------
22+
23+
setup(name='graphql-dsl',
24+
version='0.0.1',
25+
description='GraphQL DSL',
26+
long_description=README,
27+
classifiers=[
28+
'Development Status :: 1 - Planning',
29+
'Intended Audience :: Developers',
30+
'License :: OSI Approved',
31+
'License :: OSI Approved :: MIT License',
32+
'Programming Language :: Python',
33+
'Programming Language :: Python :: 3',
34+
'Operating System :: POSIX',
35+
'Topic :: Internet :: WWW/HTTP',
36+
],
37+
author='Maxim Avanov',
38+
author_email='[email protected]',
39+
url='https://maximavanov.com/',
40+
keywords='web',
41+
packages=find_packages(exclude=['tests', 'tests.*']),
42+
include_package_data=True,
43+
zip_safe=False,
44+
test_suite='tests',
45+
tests_require=['pytest', 'coverage'],
46+
install_requires=requires,
47+
entry_points={}
48+
)

0 commit comments

Comments
 (0)