Skip to content

Commit

Permalink
Merge pull request #7 from Stoops-ML/poetry
Browse files Browse the repository at this point in the history
Poetry + updates
  • Loading branch information
Stoops-ML authored Mar 14, 2024
2 parents 46385ff + 4160a3c commit 258986d
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 208 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [windows-latest]
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v2
Expand All @@ -23,4 +23,4 @@ jobs:
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
run: tox
58 changes: 30 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
default_language_version:
python: python3.10
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.5.0
hooks:
# - id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -18,31 +12,18 @@ repos:
- id: debug-statements
language_version: python3

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.12.0
hooks:
- id: flake8
language_version: python3

# - repo: https://github.com/asottile/reorder_python_imports
# rev: v3.9.0
# hooks:
# - id: reorder-python-imports
# args: [--py36-plus]
- id: reorder-python-imports
args: [--py36-plus]

- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py36-plus]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.960
# hooks:
# - id: mypy
# files: ^src/
# args: []

- repo: local
hooks:
- id: pytest-check
Expand All @@ -51,9 +32,30 @@ repos:
language: system
pass_filenames: false
always_run: true

- repo: local
hooks:
- id: black
name: black
entry: black .
language: system
pass_filenames: false
always_run: true
- id: mypy
name: mypy
entry: mypy . --install-types --non-interactive
language: system
pass_filenames: false
always_run: true
- id: flake8
name: flake8
entry: flake8
language: system
pass_filenames: false
always_run: true
- id: poetry types
name: poetry types
entry: poetry types update
language: system
pass_filenames: false
always_run: true
- id: tox-check
name: tox
entry: tox
Expand Down
21 changes: 0 additions & 21 deletions Pipfile

This file was deleted.

85 changes: 81 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
[tool.poetry]
name = "refers"
version = "0.0.3"
description = "Reference code to improve explainability"
authors = ["Daniel Stoops <[email protected]>"]
readme = "README.md"
license = "MIT"

[tool.poetry.dependencies]
python = "^3.11"
toml = "^0.10.2"
black = "^24.2.0"

[tool.poetry.group.dev.dependencies]
tox = "^4.14.1"
flake8 = "^7.0.0"
mypy = "^1.9.0"
pre-commit = "^3.6.2"
types-toml = "^0.10.8.20240310"
pytest = "^8.1.1"
reorder-python-imports = "^3.12.0"
pytest-cov = "^4.1.0"
flake8-pyproject = "^1.2.3"
poetry-types = "^0.5.0"

[tool.poetry.group.types.dependencies]
types-toml = "^0.10.8.20240310"

[build-system]
requires = ["setuptools>=42.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
refers = "refers.cli:run"

[tool.mypy]
mypy_path = "src"
mypy_path = "refers"
check_untyped_defs = true
disallow_any_generics = true
ignore_missing_imports = true
Expand All @@ -14,4 +45,50 @@ warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
no_implicit_reexport = true
no_implicit_reexport = true

[tool.pytest.ini_options]
testpaths = "tests"
addopts = [
"--cov=refers",
"--cov-fail-under=75",
"--cov-report=term-missing",
"--cov-report=term",
"--cov-report="
]

[tool.tox]
legacy_tox_ini = """
[tox]
envlist =
py{311}
lint
isolated_build = true
[testenv]
deps =
pytest>=8.1.1
pytest-cov>=4.1.0
setenv =
PYTHONPATH = {toxinidir}
commands =
python -c "import sys; print(sys.version_info)"
python -m pytest --basetemp={envtmpdir}
[testenv:lint]
deps =
flake8>=7.0.0
flake8-pyproject>=1.2.3
mypy>=1.9.0
black>=24.2.0
commands =
python -m flake8 refers/ tests/
python -m mypy --install-types --non-interactive
python -m mypy .
python -m black --check --diff .
"""

[tool.flake8]
ignore = ['E203', 'E501', 'W503']
max-line-length = 88
count = true
File renamed without changes.
1 change: 1 addition & 0 deletions src/refers/cli.py → refers/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse

from refers.refers import format_doc


Expand Down
22 changes: 9 additions & 13 deletions src/refers/compromise_black.py → refers/compromise_black.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""sorry black, you've been compromised"""
from functools import partial
from typing import Iterator
from typing import Set
from typing import TypeVar
from typing import Union

from black.comments import generate_comments
from black.linegen import Line # type:ignore
from black.mode import Mode
from black.nodes import ASSIGNMENTS
from black.nodes import is_name_token
Expand All @@ -14,22 +15,16 @@
from black.nodes import syms
from black.nodes import Visitor
from black.nodes import WHITESPACE
from blib2to3.pgen2 import token
from blib2to3.pytree import Leaf
from blib2to3.pytree import Node

"""sorry black, you've been compromised"""

# types
T = TypeVar("T")
Index = int
LeafID = int


from blib2to3.pgen2 import token

from typing import (
Union,
)

from blib2to3.pytree import Node, Leaf # type: ignore
from black.linegen import normalize_prefix, Line

LN = Union[Leaf, Node]


Expand Down Expand Up @@ -85,7 +80,8 @@ def visit_default(self, node: LN) -> Iterator[Line]:
self.current_line.append(comment)
yield from self.line()

normalize_prefix(node, inside_brackets=any_open_brackets)
if any_open_brackets:
node.prefix = ""
# if self.mode.string_normalization and node.type == token.STRING:
# node.value = normalize_string_prefix(node.value)
# node.value = normalize_string_quotes(node.value)
Expand Down
File renamed without changes.
File renamed without changes.
54 changes: 22 additions & 32 deletions src/refers/refers.py → refers/refers.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
import re
from pathlib import Path
from typing import List
from typing import Optional
from typing import (
TypeVar,
)
from typing import Union

import black
import toml
from black import nodes
from black.parsing import lib2to3_parse
from blib2to3.pytree import Leaf
from blib2to3.pytree import Node

from refers.compromise_black import LineGenerator
from refers.definitions import CODE_RE_TAG
from refers.definitions import DOC_OUT_ID
from refers.definitions import DOC_RE_TAG
from refers.definitions import LIBRARY_NAME
from refers.errors import MultipleTagsInOneLine
from refers.errors import OptionNotFoundError
from refers.errors import PyprojectNotFound
from refers.errors import TagNotFoundError
from refers.tags import Tag
from refers.tags import Tags

# types
T = TypeVar("T")
Index = int
LeafID = int

from typing import (
List,
Optional,
TypeVar,
Union,
)

from blib2to3.pytree import Node, Leaf # type: ignore

LN = Union[Leaf, Node]
T = TypeVar("T")
from refers.tags import Tag, Tags


import black
from black.parsing import lib2to3_parse

from refers.errors import (
MultipleTagsInOneLine,
TagNotFoundError,
PyprojectNotFound,
OptionNotFoundError,
)
import re
from pathlib import Path
from refers.definitions import (
CODE_RE_TAG,
DOC_RE_TAG,
DOC_OUT_ID,
LIBRARY_NAME,
)
import toml
from refers.compromise_black import LineGenerator


def get_files(
Expand Down
Loading

0 comments on commit 258986d

Please sign in to comment.