Skip to content

Commit c972620

Browse files
committed
bump minimum python version to 3.8, bump deps, fix derived issues
bump minimum python version to 3.8 since 3.7 was EoL on June 27th 2023. also bump deps, including flake8 and others, which caused some new issues that were fixed: - dict.fromkeys() instead of dict comprehensions (C420) - repr sgqlc.operation.__init__.Selector is now sgqlc.operation.Selector - sgqlc.operation doctest was polluting sgqlc.types, save a snapshot and restore it so it always works
1 parent fcde902 commit c972620

File tree

9 files changed

+394
-324
lines changed

9 files changed

+394
-324
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ per-file-ignores =
2323
# RST303: literalinclude is supported by sphinx
2424
# N999: ignore dashes in the name (ideally only disabled for examples/)
2525
# W503: old coding style (new PEP8 is enforced by W504)
26-
ignore = I801,RST303,RST304,N999,W503
26+
# A005: the module is shadowing a Python builtin module (http, uuid, datetime, types)
27+
ignore = I801,RST303,RST304,N999,W503,A005
2728
max-complexity = 10
2829
max-line-length = 79
2930
known-modules = websocket-client:[websocket],graphql-core:[graphql]

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
if: github.event.pull_request.draft != true
2121
strategy:
2222
matrix:
23-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
23+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
2424

2525
steps:
2626
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ default_install_hook_types: [pre-commit, pre-push, pre-merge-commit]
55

66
repos:
77
- repo: https://github.com/python/black
8-
rev: 23.3.0
8+
rev: 24.8.0
99
hooks:
1010
- id: black
1111
exclude: "^(docs/|examples/.*(schema|operations)[.]py)"
1212

1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.4.0
14+
rev: v4.6.0
1515
hooks:
1616
- id: check-shebang-scripts-are-executable
1717
- id: check-merge-conflict
@@ -24,7 +24,7 @@ repos:
2424
- id: trailing-whitespace
2525

2626
- repo: https://github.com/pycqa/flake8
27-
rev: 5.0.0
27+
rev: 7.1.1
2828
hooks:
2929
- id: flake8
3030
additional_dependencies:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ Run the tests (one of the below):
507507

508508
Keep 100% coverage. You can look at the coverage report at
509509
``cover/index.html``. To do that, prefer
510-
`doctest <https://docs.python.org/3.7/library/doctest.html>`_
510+
`doctest <https://docs.python.org/3.12/library/doctest.html>`_
511511
so it serves as
512512
both documentation and test. However we use
513513
`pytest <https://docs.pytest.org/>`_ to write explicit tests that would be

poetry.lock

Lines changed: 341 additions & 306 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.black]
22
line-length = 79
33
skip-string-normalization = true
4-
target-version = ['py37']
4+
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
55
force-exclude = '/(doc/|examples/.*(schema|operations)[.]py)'
66

77
[tool.pytest.ini_options]
@@ -59,8 +59,9 @@ include = [
5959
sgqlc-codegen = 'sgqlc.codegen:main'
6060

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

sgqlc/codegen/schema.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,18 @@ def graphql_type_to_str(t):
137137

138138

139139
builtin_types_import = 'sgqlc.types'
140-
builtin_scalar_imports = {
141-
k: builtin_types_import
142-
for k in ('Int', 'Float', 'String', 'Boolean', 'ID')
143-
}
144-
datetime_scalar_imports = {
145-
k: 'sgqlc.types.datetime' for k in ('DateTime', 'Date', 'Time')
146-
}
147-
relay_imports = {k: 'sgqlc.types.relay' for k in ('Node', 'PageInfo')}
140+
builtin_scalar_imports = dict.fromkeys(
141+
('Int', 'Float', 'String', 'Boolean', 'ID'),
142+
builtin_types_import,
143+
)
144+
datetime_scalar_imports = dict.fromkeys(
145+
('DateTime', 'Date', 'Time'),
146+
'sgqlc.types.datetime',
147+
)
148+
relay_imports = dict.fromkeys(
149+
('Node', 'PageInfo'),
150+
'sgqlc.types.relay',
151+
)
148152

149153
default_type_imports = {
150154
**builtin_scalar_imports,

sgqlc/operation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@
14921492
>>> op.repository(id='repo2', __alias__='alias').issues.title()
14931493
title
14941494
>>> type(op['repository']) # it's the selector, not a selection!
1495-
<class 'sgqlc.operation.__init__.Selector'>
1495+
<class 'sgqlc.operation.Selector'>
14961496
>>> op['repository'].__selection__() # default selection
14971497
repository(id: "repo1") {
14981498
issues {

sgqlc/types/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@
126126
Examples
127127
--------
128128
129+
Let's start our examples/doctest by restoring the ``gloal_schema`` to the
130+
original schema after ``sgqlc.types`` was loaded the first time
131+
(ie: ``pytest`` shares execution, so if ``sgqlc.operation`` was
132+
loaded before ``sgqlc.types``, we need to restore to the initial snapshot):
133+
134+
>>> global_schema.__snapshot_restore__(__types_schema_snapshot__)
135+
129136
Common Usage
130137
~~~~~~~~~~~~
131138
@@ -668,6 +675,23 @@ def __init__(self, base_schema=None):
668675
for k, v in base_schema.__kinds.items():
669676
self.__kinds.setdefault(k, ODict()).update(v)
670677

678+
def __snapshot_create__(self):
679+
state = (
680+
self.__all,
681+
self.__kinds,
682+
self.__cache__,
683+
)
684+
import copy
685+
686+
return copy.deepcopy(state)
687+
688+
def __snapshot_restore__(self, state):
689+
import copy
690+
691+
# yet another copy, so we don't modify the snapshot!
692+
state = copy.deepcopy(state)
693+
self.__all, self.__kinds, self.__cache__ = state
694+
671695
def __contains__(self, key):
672696
'''Checks if the type name is known in this schema.
673697
@@ -2930,3 +2954,8 @@ class UnknownType(Type):
29302954
bool: Boolean,
29312955
id: ID,
29322956
}
2957+
2958+
2959+
# Save the global schema snapshot, used in doctest and possible by
2960+
# some external users that need to remove temporary types
2961+
__types_schema_snapshot__ = global_schema.__snapshot_create__()

0 commit comments

Comments
 (0)