Migrate to pyproject.toml for the core project. (#5373)

This commit is contained in:
Alan Cruickshank
2023-11-06 17:24:25 +00:00
committed by GitHub
parent e7715718c6
commit ef7ac7ac20
12 changed files with 307 additions and 276 deletions

View File

@@ -1,14 +0,0 @@
version = 1
test_patterns = [
'test/**',
]
exclude_patterns = [
'docs/**',
'util.py', # not part of the core sqlfluff code
]
[[ analyzers ]]
name = 'python'
enabled = true

View File

@@ -1,18 +0,0 @@
extend-select = ["I", "D"]
# D105: Missing docstring in magic method
# D107: Missing docstring in __init__
# D418: Function/ Method decorated with @overload shouldnt contain a docstring
ignore = ["D107", "D105", "D418"]
[isort]
# Mark sqlfluff, test and it's plugins as known first party
known-first-party = [
"sqlfluff",
"sqlfluff_plugin_example",
"sqlfluff_templater_dbt",
"test",
]
[pydocstyle]
convention = "google"

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 Alan Cruickshank
Copyright (c) 2023 Alan Cruickshank
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -5,10 +5,15 @@ list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""
import configparser
import os
import sys
# tomllib is only in the stdlib from 3.11+
if sys.version_info >= (3, 11):
import tomllib
else: # pragma: no cover
import toml as tomllib
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
@@ -19,9 +24,9 @@ sys.path.append(os.path.abspath("./_ext"))
# Get the global config info as currently stated
# (we use the config file to avoid actually loading any python here)
config = configparser.ConfigParser()
config.read(["../../setup.cfg"])
stable_version = config.get("sqlfluff_docs", "stable_version")
with open("../../pyproject.toml", "rb") as config_file:
config = tomllib.load(config_file)
stable_version = config.get("tool.sqlfluff_docs", "stable_version")
# -- Project information -----------------------------------------------------

View File

@@ -1,28 +0,0 @@
[mypy]
warn_unused_configs = True
warn_unused_ignores = True
[mypy-sqlfluff.*]
implicit_reexport = True
# skip type checking for 3rd party packages for which stubs are not available
[mypy-pathspec.*]
ignore_missing_imports = True
[mypy-diff_cover.*]
ignore_missing_imports = True
[mypy-dbt.*]
ignore_missing_imports = True
[mypy-pluggy.*]
ignore_missing_imports = True
[mypy-tqdm.*]
ignore_missing_imports = True
[mypy-importlib_metadata.*]
ignore_missing_imports = True
[mypy-tblib.*]
ignore_missing_imports = True

271
pyproject.toml Normal file
View File

@@ -0,0 +1,271 @@
[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "sqlfluff"
version = "2.3.5"
description = "The SQL Linter for Humans"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.8"
authors = [
{name = "Alan Cruickshank", email = "alan@designingoverload.com"},
]
license = {file = "LICENSE.md"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: SQL",
"Topic :: Utilities",
"Topic :: Software Development :: Quality Assurance",
]
keywords = [
"sqlfluff",
"sql",
"linter",
"formatter",
"athena",
"bigquery",
"clickhouse",
"databricks",
"db2",
"duckdb",
"exasol",
"greenplum",
"hive",
"materialize",
"mysql",
"postgres",
"redshift",
"snowflake",
"soql",
"sparksql",
"sqlite",
"teradata",
"trino",
"tsql",
"dbt",
]
dependencies = [
# Used for finding os-specific application config dirs
"appdirs",
# To get the encoding of files.
"chardet",
"click",
"colorama>=0.3",
# Used for diffcover plugin
"diff-cover>=2.5.0",
"importlib_resources; python_version < '3.9'",
"Jinja2",
# Used for .sqlfluffignore
"pathspec",
# We provide a testing library for plugins in sqlfluff.utils.testing
"pytest",
# We require pyyaml >= 5.1 so that we can preserve the ordering of keys.
"pyyaml>=5.1",
# The new regex module to allow for more complex pattern matching,
# whilst remaining backwards compatible with existing regex use cases.
# e.g. capturing repeated groups in nested tsql block comments.
# This was introduced in https://github.com/sqlfluff/sqlfluff/pull/2027
# and further details can be found in that PR.
"regex",
# For returning exceptions from multiprocessing.Pool.map()
"tblib",
# For parsing pyproject.toml
"toml; python_version < '3.11'",
# For handling progress bars
"tqdm",
# better type hints for older python versions
"typing_extensions",
]
[project.urls]
Homepage = "https://www.sqlfluff.com"
Documentation = "https://docs.sqlfluff.com"
Source = "https://github.com/sqlfluff/sqlfluff"
Changes = "https://github.com/sqlfluff/sqlfluff/blob/main/CHANGELOG.md"
"Issue Tracker" = "https://github.com/sqlfluff/sqlfluff/issues"
Twitter = "https://twitter.com/SQLFluff"
Chat = "https://github.com/sqlfluff/sqlfluff#sqlfluff-on-slack"
[tool.sqlfluff_docs]
# NOTE: Stable version is used by docs/conf.py
stable_version = "2.3.5"
[tool.setuptools]
package-dir = {"" = "src"}
[tool.setuptools.packages.find]
where = ["src"]
namespaces = false
[tool.setuptools.package-data]
sqlfluff = ["config.ini", "core/default_config.cfg", "py.typed"]
[project.scripts]
sqlfluff = "sqlfluff.cli.commands:cli"
[project.entry-points.diff_cover]
sqlfluff = "sqlfluff.diff_quality_plugin"
[project.entry-points.sqlfluff]
sqlfluff = "sqlfluff.core.plugin.lib"
# NOTE: We namespace the rules plugins with `rules`, because some
# of them might later collide with other types of plugins. In particular
# `tsql` may eventually refer to a dialect plugin and `jinja` may refer
# to a templater plugin.
sqlfluff_rules_capitalisation = "sqlfluff.rules.capitalisation"
sqlfluff_rules_aliasing = "sqlfluff.rules.aliasing"
sqlfluff_rules_layout = "sqlfluff.rules.layout"
sqlfluff_rules_references = "sqlfluff.rules.references"
sqlfluff_rules_ambiguous = "sqlfluff.rules.ambiguous"
sqlfluff_rules_structure = "sqlfluff.rules.structure"
sqlfluff_rules_convention = "sqlfluff.rules.convention"
sqlfluff_rules_jinja = "sqlfluff.rules.jinja"
sqlfluff_rules_tsql = "sqlfluff.rules.tsql"
[tool.importlinter]
root_package = "sqlfluff"
[[tool.importlinter.contracts]]
name = "Forbid dependencies outside core"
type = "forbidden"
source_modules = [
"sqlfluff.core",
]
forbidden_modules = [
"sqlfluff.api",
"sqlfluff.cli",
"sqlfluff.dialects",
"sqlfluff.rules",
"sqlfluff.utils",
]
[[tool.importlinter.contracts]]
name = "API may not depend on CLI"
type = "forbidden"
source_modules = [
"sqlfluff.api",
]
forbidden_modules = [
"sqlfluff.cli",
]
[[tool.importlinter.contracts]]
name = "Helper methods must be internally indepentent"
type = "independence"
modules = [
"sqlfluff.core.helpers.string",
"sqlfluff.core.helpers.slice",
"sqlfluff.core.helpers.dict",
]
[[tool.importlinter.contracts]]
name = "Dependency layers within core"
# NOTE: Several modules within core currently have somewhat more
# convoluted dependency loops, especially when it comes to type checking.
# Those are currently excluded from this work, but might be picked up in
# future work to help with better isolation.
type = "layers"
layers = [
# `linter` references many things, including rules.
"sqlfluff.core.linter",
# `rules` should be independent from linter, but can reference the others.
"sqlfluff.core.rules",
# `parser` should be independent of `rules` and `linter`.
"sqlfluff.core.parser",
# `errors` should be a utility library, which can be referenced by the others.
"sqlfluff.core.errors",
# `helpers` should be independent and not reference any of the above.
"sqlfluff.core.helpers",
]
ignore_imports = [
# `errors` references `rules` and `parser`, but only for type checking.
# Splitting it up seems overkill for now, so an allowable exception.
"sqlfluff.core.errors -> sqlfluff.core.rules",
"sqlfluff.core.errors -> sqlfluff.core.parser",
]
[tool.mypy]
warn_unused_configs = true
warn_unused_ignores = true
[[tool.mypy.overrides]]
module = "sqlfluff.*"
implicit_reexport = true
# skip type checking for 3rd party packages for which stubs are not available
[[tool.mypy.overrides]]
module = "pathspec.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "diff_cover.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "dbt.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "pluggy.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "tqdm.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "tblib.*"
ignore_missing_imports = true
[tool.ruff]
extend-select = ["I", "D"]
# D105: Missing docstring in magic method
# D107: Missing docstring in __init__
# D418: Function/ Method decorated with @overload shouldnt contain a docstring
ignore = ["D107", "D105", "D418"]
[tool.ruff.isort]
# Mark sqlfluff, test and it's plugins as known first party
known-first-party = [
"sqlfluff",
"sqlfluff_plugin_example",
"sqlfluff_templater_dbt",
"test",
]
[tool.ruff.pydocstyle]
convention = "google"
[tool.pytest.ini_options]
markers = [
"dbt: Marks tests needing the \"dbt\" plugin (deselect with '-m \"not dbt\"').",
"integration: Marks tests outside of the core suite.",
"parse_suite: Marks the suite of parsing tests across a range of dialects (part of integration).",
"fix_suite: Marks the suite of fixing tests across a range of dialects (part of integration).",
"rules_suite: Marks the suite of rules tests. Also known as the yaml tests (part of integration).",
]

View File

@@ -1,7 +0,0 @@
[pytest]
markers =
dbt: Marks tests needing the "dbt" plugin (deselect with '-m "not dbt"').
integration: Marks tests outside of the core suite.
parse_suite: Marks the suite of parsing tests across a range of dialects (part of integration).
fix_suite: Marks the suite of fixing tests across a range of dialects (part of integration).
rules_suite: Marks the suite of rules tests. Also known as the yaml tests (part of integration).

191
setup.cfg
View File

@@ -1,191 +0,0 @@
[metadata]
name = sqlfluff
version = 2.3.5
description = The SQL Linter for Humans
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/sqlfluff/sqlfluff
author = Alan Cruickshank
author_email = alan@designingoverload.com
license = MIT License
license_files = LICENSE.md
project_urls =
Homepage = https://www.sqlfluff.com
Documentation = https://docs.sqlfluff.com
Changes = https://github.com/sqlfluff/sqlfluff/blob/main/CHANGELOG.md
Source = https://github.com/sqlfluff/sqlfluff
Issue Tracker = https://github.com/sqlfluff/sqlfluff/issues
Twitter = https://twitter.com/SQLFluff
Chat = https://github.com/sqlfluff/sqlfluff#sqlfluff-on-slack
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: Unix
Operating System :: POSIX
Operating System :: MacOS
Operating System :: Microsoft :: Windows
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: Implementation :: CPython
Programming Language :: SQL
Topic :: Utilities
Topic :: Software Development :: Quality Assurance
keywords =
sqlfluff
sql
linter
formatter
athena
bigquery
clickhouse
databricks
db2
duckdb
exasol
greenplum
hive
materialize
mysql
postgres
redshift
snowflake
soql
sparksql
sqlite
teradata
trino
tsql
dbt
[options]
package_dir =
=src
packages = find:
python_requires = >=3.8
install_requires =
# Used for finding os-specific application config dirs
appdirs
# To get the encoding of files.
chardet
click
colorama>=0.3
# Used for diffcover plugin
diff-cover>=2.5.0
importlib_resources; python_version < '3.9'
Jinja2
# Used for .sqlfluffignore
pathspec
# We provide a testing library for plugins in sqlfluff.utils.testing
pytest
# We require pyyaml >= 5.1 so that we can preserve the ordering of keys.
pyyaml>=5.1
# The new regex module to allow for more complex pattern matching,
# whilst remaining backwards compatible with existing regex use cases.
# e.g. capturing repeated groups in nested tsql block comments.
# This was introduced in https://github.com/sqlfluff/sqlfluff/pull/2027
# and further details can be found in that PR.
regex
# For returning exceptions from multiprocessing.Pool.map()
tblib
# For parsing pyproject.toml
toml; python_version < '3.11'
# For handling progress bars
tqdm
# better type hints for older python versions
typing_extensions
[options.packages.find]
where =
src
[options.entry_points]
console_scripts =
sqlfluff = sqlfluff.cli.commands:cli
diff_cover =
sqlfluff = sqlfluff.diff_quality_plugin
sqlfluff =
sqlfluff = sqlfluff.core.plugin.lib
# NOTE: We namespace the rules plugins with `rules`, because some
# of them might later collide with other types of plugins. In particular
# `tsql` may eventually refer to a dialect plugin and `jinja` may refer
# to a templater plugin.
sqlfluff_rules_capitalisation = sqlfluff.rules.capitalisation
sqlfluff_rules_aliasing = sqlfluff.rules.aliasing
sqlfluff_rules_layout = sqlfluff.rules.layout
sqlfluff_rules_references = sqlfluff.rules.references
sqlfluff_rules_ambiguous = sqlfluff.rules.ambiguous
sqlfluff_rules_structure = sqlfluff.rules.structure
sqlfluff_rules_convention = sqlfluff.rules.convention
sqlfluff_rules_jinja = sqlfluff.rules.jinja
sqlfluff_rules_tsql = sqlfluff.rules.tsql
[options.package_data]
sqlfluff =
config.ini
core/default_config.cfg
py.typed
[sqlfluff_docs]
stable_version = 2.3.5
[importlinter]
root_package = sqlfluff
[importlinter:contract:core-dependencies]
name = Forbid dependencies outside core
type = forbidden
source_modules =
sqlfluff.core
forbidden_modules =
sqlfluff.api
sqlfluff.cli
sqlfluff.dialects
sqlfluff.rules
sqlfluff.utils
[importlinter:contract:api-dependencies]
name = API may not depend on CLI
type = forbidden
source_modules =
sqlfluff.api
forbidden_modules =
sqlfluff.cli
[importlinter:contract:helper-interdependence]
name = Helper methods must be internally indepentent
type = independence
modules =
sqlfluff.core.helpers.string
sqlfluff.core.helpers.slice
sqlfluff.core.helpers.dict
[importlinter:contract:core-layers]
name = Dependency layers within core
# NOTE: Several modules within core currently have somewhat more
# convoluted dependency loops, especially when it comes to type checking.
# Those are currently excluded from this work, but might be picked up in
# future work to help with better isolation.
type = layers
layers=
# `linter` references many things, including rules.
sqlfluff.core.linter
# `rules` should be independent from linter, but can reference the others.
sqlfluff.core.rules
# `parser` should be independent of `rules` and `linter`.
sqlfluff.core.parser
# `errors` should be a utility library, which can be referenced by the others.
sqlfluff.core.errors
# `helpers` should be independent and not reference any of the above.
sqlfluff.core.helpers
ignore_imports =
# `errors` references `rules` and `parser`, but only for type checking.
# Splitting it up seems overkill for now, so an allowable exception.
sqlfluff.core.errors -> sqlfluff.core.rules
sqlfluff.core.errors -> sqlfluff.core.parser

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env python
"""The script for setting up sqlfluff."""
from setuptools import setup
setup()

View File

@@ -1,6 +1,5 @@
"""The Test file for CLI (General)."""
import configparser
import json
import logging
import os
@@ -38,6 +37,13 @@ from sqlfluff.core.parser import CommentSegment
from sqlfluff.core.rules import BaseRule, LintFix, LintResult
from sqlfluff.utils.testing.cli import invoke_assert_code
# tomllib is only in the stdlib from 3.11+
if sys.version_info >= (3, 11):
import tomllib
else: # pragma: no cover
import toml as tomllib
re_ansi_escape = re.compile(r"\x1b[^m]*m")
@@ -709,9 +715,9 @@ def test__cli__command_versioning():
# Get the package version info
pkg_version = sqlfluff.__version__
# Get the version info from the config file
config = configparser.ConfigParser()
config.read_file(open("setup.cfg"))
config_version = config["metadata"]["version"]
with open("pyproject.toml", "r") as config_file:
config = tomllib.loads(config_file.read())
config_version = config["project"]["version"]
assert pkg_version == config_version
# Get the version from the cli
runner = CliRunner()

View File

@@ -1,5 +1,6 @@
[tox]
envlist = generate-fixture-yml, linting, doclinting, ruleslinting, docbuild, cov-init, doctests, py{38,39,310,311,312}, dbt{110,120,130,140,150,160}, cov-report, mypy, winpy, dbt{130,150}-winpy, yamllint
min_version = 4.0 # Require 4.0+ for proper pyproject.toml support
[testenv]
passenv = CI, CIRCLECI, CIRCLE_*, HOME, SQLFLUFF_BENCHMARK_API_KEY

19
util.py
View File

@@ -179,17 +179,28 @@ def release(new_version_num):
write_changelog.close()
for filename in ["setup.cfg", "plugins/sqlfluff-templater-dbt/setup.cfg"]:
for filename in ["plugins/sqlfluff-templater-dbt/setup.cfg"]:
input_file = open(filename, "r").readlines()
# Regardless of platform, write newlines as \n
write_file = open(filename, "w", newline="\n")
for line in input_file:
if line.startswith("version"):
line = f"version = {new_version_num}\n"
elif line.startswith(" sqlfluff=="):
line = f" sqlfluff=={new_version_num}\n"
write_file.write(line)
write_file.close()
for filename in ["pyproject.toml"]:
input_file = open(filename, "r").readlines()
# Regardless of platform, write newlines as \n
write_file = open(filename, "w", newline="\n")
for line in input_file:
for key in ["stable_version", "version"]:
if line.startswith(key):
line = f"{key} = {new_version_num}\n"
# For pyproject.toml we quote the version identifier.
line = f'{key} = "{new_version_num}"\n'
break
if line.startswith(" sqlfluff=="):
line = f" sqlfluff=={new_version_num}\n"
write_file.write(line)
write_file.close()