From f002b8ba6fc79ed00d50426d70193bad4065db95 Mon Sep 17 00:00:00 2001 From: "W. Augusto Andreoli" Date: Sun, 12 Nov 2023 02:51:21 +0100 Subject: [PATCH] feat(style): Poetry (virtualenv in project) --- README.rst | 2 ++ docs/library.rst | 2 ++ poetry.toml | 6 +++--- src/nitpick/constants.py | 19 ++++++++++++------- src/nitpick/resources/python/poetry-venv.toml | 8 ++++++++ tests/test_builtin.py | 16 ++++++++++------ .../python/poetry-venv/poetry.toml | 3 +++ 7 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 src/nitpick/resources/python/poetry-venv.toml create mode 100644 tests/test_builtin/python/poetry-venv/poetry.toml diff --git a/README.rst b/README.rst index b0c3880d..44438bba 100644 --- a/README.rst +++ b/README.rst @@ -288,6 +288,8 @@ python - `Mypy `_ * - `py://nitpick/resources/python/poetry-editable `_ - `Poetry (editable projects; PEP 600 support) `_ + * - `py://nitpick/resources/python/poetry-venv `_ + - `Poetry (virtualenv in project) `_ * - `py://nitpick/resources/python/poetry `_ - `Poetry `_ * - `py://nitpick/resources/python/pre-commit-hooks `_ diff --git a/docs/library.rst b/docs/library.rst index dd40e371..33148c12 100644 --- a/docs/library.rst +++ b/docs/library.rst @@ -129,6 +129,8 @@ python - `Mypy `_ * - :gitref:`py://nitpick/resources/python/poetry-editable ` - `Poetry (editable projects; PEP 600 support) `_ + * - :gitref:`py://nitpick/resources/python/poetry-venv ` + - `Poetry (virtualenv in project) `_ * - :gitref:`py://nitpick/resources/python/poetry ` - `Poetry `_ * - :gitref:`py://nitpick/resources/python/pre-commit-hooks ` diff --git a/poetry.toml b/poetry.toml index 3a944790..2a597393 100644 --- a/poetry.toml +++ b/poetry.toml @@ -1,4 +1,4 @@ +[virtualenvs] # https://python-poetry.org/docs/configuration/#virtualenvscreate - -virtualenvs.create = true -virtualenvs.in-project = true +create = true +in-project = true diff --git a/src/nitpick/constants.py b/src/nitpick/constants.py index 5bda23b3..5e7b06e4 100644 --- a/src/nitpick/constants.py +++ b/src/nitpick/constants.py @@ -34,6 +34,7 @@ PROJECT_OWNER = "andreoliwa" PYTHON_MANAGE_PY = "manage.py" PYTHON_PIPFILE_STAR = "Pipfile*" +PYTHON_POETRY_TOML = "poetry.toml" PYTHON_PYLINTRC = ".pylintrc" PYTHON_PYPROJECT_TOML = "pyproject.toml" PYTHON_REQUIREMENTS_STAR_TXT = "requirements*.txt" @@ -50,21 +51,25 @@ # These depend on some constants above, so they can't be sorted automatically ROOT_PYTHON_FILES = ("app.py", "wsgi.py", "autoapp.py", PYTHON_MANAGE_PY) ROOT_FILES = ( + # keep-sorted start + *ROOT_PYTHON_FILES, DOT_NITPICK_TOML, + GOLANG_MOD, + GOLANG_SUM, + JAVASCRIPT_PACKAGE_JSON, NITPICK_STYLE_TOML, PRE_COMMIT_CONFIG_YAML, + PYTHON_PIPFILE_STAR, + PYTHON_POETRY_TOML, PYTHON_PYPROJECT_TOML, - PYTHON_SETUP_PY, - PYTHON_SETUP_CFG, PYTHON_REQUIREMENTS_STAR_TXT, - PYTHON_PIPFILE_STAR, + PYTHON_SETUP_CFG, + PYTHON_SETUP_PY, PYTHON_TOX_INI, - JAVASCRIPT_PACKAGE_JSON, RUST_CARGO_STAR, - GOLANG_MOD, - GOLANG_SUM, - *ROOT_PYTHON_FILES, + # keep-sorted end ) +# Config files in the order they are searched for CONFIG_FILES = (DOT_NITPICK_TOML, PYTHON_PYPROJECT_TOML) CONFIG_RUN_NITPICK_INIT_OR_CONFIGURE_STYLE_MANUALLY = ( f" Run 'nitpick init' or configure a style manually ({', '.join(CONFIG_FILES)})." diff --git a/src/nitpick/resources/python/poetry-venv.toml b/src/nitpick/resources/python/poetry-venv.toml new file mode 100644 index 00000000..3b553d09 --- /dev/null +++ b/src/nitpick/resources/python/poetry-venv.toml @@ -0,0 +1,8 @@ +[nitpick.meta] +name = "Poetry (virtualenv in project)" +url = "https://github.com/python-poetry/poetry" + +["poetry.toml"] +# https://python-poetry.org/docs/configuration/#virtualenvscreate +virtualenvs.create = true +virtualenvs.in-project = true diff --git a/tests/test_builtin.py b/tests/test_builtin.py index b9c8aaa1..31e8b41e 100644 --- a/tests/test_builtin.py +++ b/tests/test_builtin.py @@ -11,6 +11,7 @@ EDITOR_CONFIG, JAVASCRIPT_PACKAGE_JSON, PRE_COMMIT_CONFIG_YAML, + PYTHON_POETRY_TOML, PYTHON_PYLINTRC, PYTHON_PYPROJECT_TOML, PYTHON_SETUP_CFG, @@ -22,16 +23,19 @@ RESOURCES_DIR = Path(__file__).parent.parent / "src/nitpick/resources" BUILTIN_STYLE_CODES = { - PYTHON_SETUP_CFG: 321, - PRE_COMMIT_CONFIG_YAML: 361, - PYTHON_PYPROJECT_TOML: 311, + # keep-sorted start ".codeclimate.yml": 361, - ".readthedocs.yaml": 361, - PYTHON_TOX_INI: 321, - PYTHON_PYLINTRC: 321, ".github/workflows/python.yaml": 361, + ".readthedocs.yaml": 361, EDITOR_CONFIG: 321, JAVASCRIPT_PACKAGE_JSON: 341, + PRE_COMMIT_CONFIG_YAML: 361, + PYTHON_POETRY_TOML: 311, + PYTHON_PYLINTRC: 321, + PYTHON_PYPROJECT_TOML: 311, + PYTHON_SETUP_CFG: 321, + PYTHON_TOX_INI: 321, + # keep-sorted end } BUILTIN_STYLE_EXTRA_VIOLATIONS: dict[str, list[Fuss]] = { "any/pre-commit-hooks": [ diff --git a/tests/test_builtin/python/poetry-venv/poetry.toml b/tests/test_builtin/python/poetry-venv/poetry.toml new file mode 100644 index 00000000..53b35d37 --- /dev/null +++ b/tests/test_builtin/python/poetry-venv/poetry.toml @@ -0,0 +1,3 @@ +[virtualenvs] +create = true +in-project = true