GithubHelp home page GithubHelp logo

Comments (3)

tim-vk avatar tim-vk commented on September 3, 2024

While I was adding some other stuff to this repo I'd thought to pick up some other issues. This one is quite strange for me:

I agree the usage example is a bit minimal. But the python code itself is actually quite nicely documented:

class DockerfileParser(object):
    def __init__(self, path=None,
                 cache_content=False,
                 env_replace=True,
                 parent_env=None,
                 fileobj=None,
                 build_args=None):
        """
        Initialize source of Dockerfile
        :param path: path to (directory with) Dockerfile; if not provided,
                     and fileobj is not provided, the current working
                     directory will be used
        :param cache_content: cache Dockerfile content inside DockerfileParser
        :param env_replace: return content with variables replaced
        :param parent_env: python dict of inherited env vars from parent image
        :param fileobj: seekable file-like object containing Dockerfile content
                        as bytes (will be truncated on write)
        :param build_args: python dict of build args used when building image
        """

The thing you are asking for (I think) is the cache_content input variable.
But there are two things that strike me as odd:

  1. why would you not want to edit the existing file? The only example I can think of is if you want to keep your original dockerfile and save an edited copy. But either way: you'd need two dockerfile parser instances (one to read, and one to edit/write). The cache_content variable seems useless to me.
  2. As far as I can see: the cache_content variable doesn't work. It was added 7 years ago: My guess is something broke in the meantime. But honestly: I think it is clutter that should be removed.

But I am curious if there are any use cases that I'm missing since it was added with a reason.

from dockerfile-parse.

Aisik00 avatar Aisik00 commented on September 3, 2024

I am currently using this package for only loading the Dockerfile, to run static analysis on it (linting). So I was struggling a bit, that Dockerfile file is being created (rewritten) on file system even though I did not want that. If someone else is having similar problem, passing tempfile (tempfile.NamedTemporaryFile()) as fileobj argument helped.

from dockerfile-parse.

KevinMGranger avatar KevinMGranger commented on September 3, 2024

I didn't know this was the case, and was surprised to find this out. I was already confused about why the library didn't just have a parse_file function that returns something that's just Plain Old Data.

Semi-related: I didn't realize the parsing was lazy-- I thought I could just create the DockerfileParser within the context manager, and then access its fields later.

Would y'all be opposed to me adding such an alternative API? It would be type-annotated and based on dataclasses. That requires 3.7, but 3.6 is EOL'd even by RHEL.

from dockerfile-parse.

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.