Skip to content

Commit

Permalink
feat(style): Poetry (virtualenv in project)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Nov 12, 2023
1 parent 3557c1f commit f002b8b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -288,6 +288,8 @@ python
- `Mypy <https://github.com/python/mypy>`_
* - `py://nitpick/resources/python/poetry-editable <src/nitpick/resources/python/poetry-editable.toml>`_
- `Poetry (editable projects; PEP 600 support) <https://github.com/python-poetry/poetry>`_
* - `py://nitpick/resources/python/poetry-venv <src/nitpick/resources/python/poetry-venv.toml>`_
- `Poetry (virtualenv in project) <https://github.com/python-poetry/poetry>`_
* - `py://nitpick/resources/python/poetry <src/nitpick/resources/python/poetry.toml>`_
- `Poetry <https://github.com/python-poetry/poetry>`_
* - `py://nitpick/resources/python/pre-commit-hooks <src/nitpick/resources/python/pre-commit-hooks.toml>`_
Expand Down
2 changes: 2 additions & 0 deletions docs/library.rst
Expand Up @@ -129,6 +129,8 @@ python
- `Mypy <https://github.com/python/mypy>`_
* - :gitref:`py://nitpick/resources/python/poetry-editable <src/nitpick/resources/python/poetry-editable.toml>`
- `Poetry (editable projects; PEP 600 support) <https://github.com/python-poetry/poetry>`_
* - :gitref:`py://nitpick/resources/python/poetry-venv <src/nitpick/resources/python/poetry-venv.toml>`
- `Poetry (virtualenv in project) <https://github.com/python-poetry/poetry>`_
* - :gitref:`py://nitpick/resources/python/poetry <src/nitpick/resources/python/poetry.toml>`
- `Poetry <https://github.com/python-poetry/poetry>`_
* - :gitref:`py://nitpick/resources/python/pre-commit-hooks <src/nitpick/resources/python/pre-commit-hooks.toml>`
Expand Down
6 changes: 3 additions & 3 deletions 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
19 changes: 12 additions & 7 deletions src/nitpick/constants.py
Expand Up @@ -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"
Expand All @@ -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)})."
Expand Down
8 changes: 8 additions & 0 deletions 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
16 changes: 10 additions & 6 deletions tests/test_builtin.py
Expand Up @@ -11,6 +11,7 @@
EDITOR_CONFIG,
JAVASCRIPT_PACKAGE_JSON,
PRE_COMMIT_CONFIG_YAML,
PYTHON_POETRY_TOML,
PYTHON_PYLINTRC,
PYTHON_PYPROJECT_TOML,
PYTHON_SETUP_CFG,
Expand All @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions tests/test_builtin/python/poetry-venv/poetry.toml
@@ -0,0 +1,3 @@
[virtualenvs]
create = true
in-project = true

0 comments on commit f002b8b

Please sign in to comment.