question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested local.include doesn't work as expected

See original GitHub issue

Description It seems that local.include always evaluates the path relative to the top level deploy, or rather, the one specified on the command line. This causes issues with nested deploys that include other deploys, which in turn contain others if some of these deploys are in a different location on the directory tree.

For example, with this structure:

.
├── data
├── deploys
│   ├── facts
│   ├── roles
│   │   └── group_data -> ../../group_data
│   └── tasks
│       └── group_data -> ../../group_data
├── group_data
└── inventories

The tasks dir is used to store building-block deploys for reuse which may need to be called in a very specific order, while the roles dir contains deploys made up of groupings of tasks (and other additional operations) that are “guaranteed” to work together.

This issue crops up in the following scenario:

  • Deploys A.py and B.py are in tasks.
  • A.py uses local.include to include B.py.
  • Deploy C.py is in roles.
  • C.py uses local.include to include A.py.

This causes an error when trying to run pyinfra <inventory> deploys/roles/C.py, because the local.include in A.py attempts to use a relative path based on the location of C.py, which is invalid.

Expected behavior I feel like it makes more sense for local.include to evaluate the path relative to the location of the deploy file that it is in so that nesting would “work as expected.”

Meta

❯ pyinfra --support
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Darwin
      Platform: Darwin-18.7.0-x86_64-i386-64bit
      Release: 18.7.0
      Machine: x86_64
    pyinfra: v1.1.2
    Executable: /Users/----/.local/bin/pyinfra
    Python: 3.7.8 (CPython, Clang 10.0.1 (clang-1001.0.46.4))
  • Installed via pipx

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
taranlu-houzzcommented, Aug 24, 2021

@Fizzadar Cool, I will try that out once v1.4.13 is released. Thanks!

1reaction
taranlu-houzzcommented, Feb 8, 2021

Seems to be working, but the logging looks odd because it keeps appending the dirname of the relative path multiple times in some cases. Here is an example (still works correctly though):

--> Starting operation: /Users/----/pyinfra/deploys/tasks/supervisor/../../tasks/supervisor/../../tasks/pipeline/../../tasks/pipeline/../../tasks/pipeline/../../tasks/pipeline/../../tasks/pipeline/../../tasks/supervisor/start_service.py | Start supervisor service as root.
    [----] Success

Maybe it would make sense to only show the abspath for the included file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are nested functions not supported by the C standard?
Nested functions don't require keeping local variables in memory after any function returns. (Unless a language allows saving the address of a ...
Read more >
MacOS High Sierra: Build error - "#include nested too ...
Problem was some header files in /usr/local/include that shouldn't be there. Easiest to fix is to run brew doctor and follow instructions.
Read more >
Lambdas, Nested Functions, and Blocks, oh my! | The Pasture
it remains local: there's no need to write a function definition outside the function or forward-declare anything; and,; it requires no special ...
Read more >
Getting started | Less.js
Importing works pretty much as expected. You can import a .less file, and all the variables in it will be available. The extension...
Read more >
GitLab CI/CD include examples
You can use include to include external YAML files in your CI/CD jobs. ... If you do not specify an include type, each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found