Skip to content

Commit

Permalink
Major refactor of config classes and config include logic (#214)
Browse files Browse the repository at this point in the history
**BREAKING CHANGE:** included config now loads envfiles relative to the cwd
specified on the include option (if any).

New/updated special env vars:
- POE_CONF_DIR: the path to the dir containing the config file that defines the
  running task or the cwd set when including the config
- POE_DEBUG makes poe print more stuff to help with debugging

Refactor specifics:
- Introduce PoeOptions class for deserializing config. I would have used
  pydantic but it's too heavy for use in a CLI tool like this.
- Keep config from different files separate within PoeConfig
- Collect config validation logic in the config classes and declare config types
  in more detail
- Make error reporting more structured and consistent

Also:
- Fixed bug that caused some task validation to be skipped for tasks with args
- Improve consistency and coverage for config validation
- Fix crash in switch with args naked string for control
- PoeConfig.load will load everything again if called a second time
- remove pylint from the project
- Enable ANSI color output by default inside GitHub Actions
  • Loading branch information
nat-n authored Apr 20, 2024
1 parent 152f687 commit 583e12b
Show file tree
Hide file tree
Showing 52 changed files with 2,480 additions and 2,210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
notes/
tests/temp
out.txt

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
364 changes: 0 additions & 364 deletions .pylintrc

This file was deleted.

13 changes: 11 additions & 2 deletions docs/guides/include_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ If an included task file itself includes other files, these second order include
Setting a working directory for included tasks
----------------------------------------------

When including files from another location, you can also specify that tasks from that other file should be run from within a specific directory. For example with the following configuration, when tasks imported from my_subproject are run from the root, the task will actually execute as if it had been run from the *my_subproject* subdirectory.
When including files from another location, you can also specify that tasks from that other file should be run from within a specific directory. For example with the following configuration, when tasks imported from *my_subproject* are run from the root, the task will actually execute as if it had been run from the *my_subproject* subdirectory.

.. code-block:: toml
[[tool.poe.include]]
path = "my_subproject/pyproject.toml"
cwd = "my_subproject"
The cwd option still has the limitation that it cannot be used to specify a directory outside of parent directory of the pyproject.toml file that poe is running with.
The directory indicated by the ``cwd`` option will also be used as the base directory for global or task level ``envfile`` imports for tasks defined within an included file.

Tasks and config in an included file can access the ``cwd`` value via the ``POE_CONF_DIR`` environment variable. When no ``cwd`` is set on the include then ``POE_CONF_DIR`` refers the to the parent directory of the config file where a task is defined.

You can still specify that an envfile referenced within an included file should be imported relative to the main project root, using the ``POE_ROOT`` environment variable like so:

.. code-block:: toml
[tool.poe]
envfile = "${POE_ROOT}/.env"
Loading

0 comments on commit 583e12b

Please sign in to comment.