Skip to content

Commit

Permalink
bump minimum python version to 3.8, bump deps, fix derived issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
barbieri committed Sep 10, 2024
1 parent fcde902 commit 11a91f9
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 321 deletions.
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]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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@v4
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
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
641 changes: 338 additions & 303 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 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,8 @@ include = [
sgqlc-codegen = 'sgqlc.codegen:main'

[tool.poetry.dependencies]
python = '^3.7'
graphql-core = '^3.1.7'
python = '^3.8'
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__()

0 comments on commit 11a91f9

Please sign in to comment.