Code Monkey home page Code Monkey logo

Comments (9)

jacobperron avatar jacobperron commented on August 25, 2024 1

I'll try to implement this in colcon first and see how it goes.

from ament_package.

dirk-thomas avatar dirk-thomas commented on August 25, 2024

When prepending values to an env var we aim to not have a trailing separator. The rational is that in the past there were cases where consumers of the env vars didn't support that case.

A sourced script can perform the correct prepending. But the command generated for a dsv type like prepend-non-duplicate isn't aware of the shell logic and instead of resulting in a line like:

`FOO=new_value:$FOO`

it will (since the env var was not set before) generate a line like:

`FOO=new_value`

which will overwrite the change of the sourced script.

from ament_package.

jacobperron avatar jacobperron commented on August 25, 2024

Just throwing out an idea, what if we always prepend and then do a post-processing step to check that all env vars that were set do not have a trailing :? And if they do, just unset them.

from ament_package.

dirk-thomas avatar dirk-thomas commented on August 25, 2024

Should that post processing happen in the shell or in Python? The former would need to be implemented in all primary shells (sh, bat, ps1 atm). The later would require the overhead of another Python invocation.

How does the post-processing determine which env vars to check? Preferably without needing to discover all .dsv file again due to the necessary runtime.

Should the post-processing distinguish which trailing separators are actually coming from the "always prepending" or blindly remove them (potentially altering values unintentionally)?

from ament_package.

jacobperron avatar jacobperron commented on August 25, 2024

Should that post processing happen in the shell or in Python?

I guess the former seems like the way to go performance-wise.

How does the post-processing determine which env vars to check? Preferably without needing to discover all .dsv file again due to the necessary runtime.

We could store this information in a temporary environment variable (which is just a list of all variables prepended to via dsv commands). Note, this could be unset at the end of the post-processing script to avoid environment pollution.

Should the post-processing distinguish which trailing separators are actually coming from the "always prepending" or blindly remove them (potentially altering values unintentionally)?

I'm not sure, but maybe it's safest to just remove the trailing separator if and only it is the only character (ie. if the contents of the variable are longer than one character, do nothing).
It seems like an odd case to want a standalone separator, but I don't know.

from ament_package.

dirk-thomas avatar dirk-thomas commented on August 25, 2024

maybe it's safest to just remove the trailing separator if and only it is the only character

That might still break (poorly written) code which isn't capable of handling a trailing separator.

from ament_package.

jacobperron avatar jacobperron commented on August 25, 2024

We know what the first prepended value should be if nothing else was prepended before the first .dsv file was processed. A best effort approach could be to compare the suffix with what we might expect to be there, and if they're equal, remove the trailing separator.

from ament_package.

dirk-thomas avatar dirk-thomas commented on August 25, 2024

That sounds like a promising approach 👍

from ament_package.

jacobperron avatar jacobperron commented on August 25, 2024

I took a slightly different approach in colcon/colcon-core#254,

Instead of setting an environment variable to track changes in the shell scripts, I've done this tracking in Python and appended commands for cleanup.

from ament_package.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.