Skip to content
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

Deprecate py versions #246

Merged
merged 3 commits into from
Sep 10, 2024
Merged
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
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ per-file-ignores =
# RST303: literalinclude is supported by sphinx
# N999: ignore dashes in the name (ideally only disabled for examples/)
# W503: old coding style (new PEP8 is enforced by W504)
ignore = I801,RST303,RST304,N999,W503
# A005: the module is shadowing a Python builtin module (http, uuid, datetime, types)
ignore = I801,RST303,RST304,N999,W503,A005
max-complexity = 10
max-line-length = 79
known-modules = websocket-client:[websocket],graphql-core:[graphql]
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
if: github.event.pull_request.draft != true
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: "Install Poetry"
run: "pip install poetry"
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Install dependencies
run: "poetry install --no-interaction --all-extras --with dev"
- run: "pip install pre-commit"
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ default_install_hook_types: [pre-commit, pre-push, pre-merge-commit]

repos:
- repo: https://github.com/python/black
rev: 23.3.0
rev: 24.8.0
hooks:
- id: black
exclude: "^(docs/|examples/.*(schema|operations)[.]py)"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
Expand All @@ -24,7 +24,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pycqa/flake8
rev: 5.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
Expand Down
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: 2
formats: all

build:
os: ubuntu-22.04
os: ubuntu-24.04
tools:
python: '3.11'
python: '3.12'
jobs:
post_create_environment:
- pip install poetry
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Run the tests (one of the below):

Keep 100% coverage. You can look at the coverage report at
``cover/index.html``. To do that, prefer
`doctest <https://docs.python.org/3.7/library/doctest.html>`_
`doctest <https://docs.python.org/3.12/library/doctest.html>`_
so it serves as
both documentation and test. However we use
`pytest <https://docs.pytest.org/>`_ to write explicit tests that would be
Expand Down
647 changes: 341 additions & 306 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.black]
line-length = 79
skip-string-normalization = true
target-version = ['py37']
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
force-exclude = '/(doc/|examples/.*(schema|operations)[.]py)'

[tool.pytest.ini_options]
Expand Down Expand Up @@ -59,8 +59,9 @@ include = [
sgqlc-codegen = 'sgqlc.codegen:main'

[tool.poetry.dependencies]
python = '^3.7'
graphql-core = '^3.1.7'
# <3.13 is to enable coveralls 4, which requires python >=3.8,<3.13
python = '>=3.8,<3.13'
graphql-core = '^3.2.4'
websocket-client = { version = '*', optional = true }
requests = { version = '*', optional = true }

Expand Down
20 changes: 12 additions & 8 deletions sgqlc/codegen/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ def graphql_type_to_str(t):


builtin_types_import = 'sgqlc.types'
builtin_scalar_imports = {
k: builtin_types_import
for k in ('Int', 'Float', 'String', 'Boolean', 'ID')
}
datetime_scalar_imports = {
k: 'sgqlc.types.datetime' for k in ('DateTime', 'Date', 'Time')
}
relay_imports = {k: 'sgqlc.types.relay' for k in ('Node', 'PageInfo')}
builtin_scalar_imports = dict.fromkeys(
('Int', 'Float', 'String', 'Boolean', 'ID'),
builtin_types_import,
)
datetime_scalar_imports = dict.fromkeys(
('DateTime', 'Date', 'Time'),
'sgqlc.types.datetime',
)
relay_imports = dict.fromkeys(
('Node', 'PageInfo'),
'sgqlc.types.relay',
)

default_type_imports = {
**builtin_scalar_imports,
Expand Down
2 changes: 1 addition & 1 deletion sgqlc/operation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@
>>> op.repository(id='repo2', __alias__='alias').issues.title()
title
>>> type(op['repository']) # it's the selector, not a selection!
<class 'sgqlc.operation.__init__.Selector'>
<class 'sgqlc.operation.Selector'>
>>> op['repository'].__selection__() # default selection
repository(id: "repo1") {
issues {
Expand Down
29 changes: 29 additions & 0 deletions sgqlc/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
Examples
--------
Let's start our examples/doctest by restoring the ``gloal_schema`` to the
original schema after ``sgqlc.types`` was loaded the first time
(ie: ``pytest`` shares execution, so if ``sgqlc.operation`` was
loaded before ``sgqlc.types``, we need to restore to the initial snapshot):
>>> global_schema.__snapshot_restore__(__types_schema_snapshot__)
Common Usage
~~~~~~~~~~~~
Expand Down Expand Up @@ -668,6 +675,23 @@ def __init__(self, base_schema=None):
for k, v in base_schema.__kinds.items():
self.__kinds.setdefault(k, ODict()).update(v)

def __snapshot_create__(self):
state = (
self.__all,
self.__kinds,
self.__cache__,
)
import copy

return copy.deepcopy(state)

def __snapshot_restore__(self, state):
import copy

# yet another copy, so we don't modify the snapshot!
state = copy.deepcopy(state)
self.__all, self.__kinds, self.__cache__ = state

def __contains__(self, key):
'''Checks if the type name is known in this schema.
Expand Down Expand Up @@ -2930,3 +2954,8 @@ class UnknownType(Type):
bool: Boolean,
id: ID,
}


# Save the global schema snapshot, used in doctest and possible by
# some external users that need to remove temporary types
__types_schema_snapshot__ = global_schema.__snapshot_create__()
Loading