Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I commit .lock file changes separately? What should I write for the commit message?

I'm using poetry for my Python package manager but I believe this would apply to any programming practices.

I've been doing this without knowing exactly what I'm doing, or how I should be doing.

When you use a package manager and install a new package, there's usually a .lock file change to keep your build deterministic.

Usually, I would commit these changes like:

$ git add poetry.lock pyproject.toml 
$ git commit -m "Install packages: beautifulsoup4"

i.e, I make a commit every time I install/remove a package. I do it because I FEEL like this is what I should do, but I have 0 clue if this is actually a correct way to handle this.

Am I doing great? or is there any other specific convention & rules I should abide by to make it follow the best practices as close as possible?

like image 275
user8491363 Avatar asked Apr 05 '20 03:04

user8491363


People also ask

Should I commit my poetry lock file?

You should commit the poetry. lock file to your project repo so that all people working on the project are locked to the same versions of dependencies (more below).

Do we need to commit yarn lock file?

Every project using yarn should commit the yarn lockfile to source control. The lockfile is the source of truth for telling other developers how to install dependencies for your project. Without this lockfile, other developers will be at risk for installing the wrong packages.

Should you add poetry lock to Git?

According to the maintainers, Commit your poetry. lock file to version control. Committing this file to VC is important because it will cause anyone who sets up the project to use the exact same versions of the dependencies that you are using.

What is the purpose of yarn lock file?

When present in the project, yarn. lock is the main source of information about the current versions of dependencies in a project. Yarn uses that information to check if it needs to update anything – it compares dependency versions currently installed in a project (listed in yarn.


2 Answers

The official recommendation of the poetry maintainers is to commit the lockfile if you develop a deployable application (as opposed to a library).


That being said, my personal experience has been that it isn't necessary to commit lockfiles to VCS. The pyproject.toml file is the reference for correct build instructions, and the lockfile is the reference for a single successful deployment. Now, I don't know what the spec for poetry.lock is, but I had them backfire on me often enough during collaboration with colleagues in ways where only deleting them would fix the problem.

A usual problem was that using different operation systems or python versions would lead to different lockfiles, and that just doesn't fly. I'll gladly let our CI build and persist an authoritative reference-lockfile to enable re-builds, but it still wouldn't be committed to the repository.


If maintaining a shared lockfile is viable given your workflow - great! You avoid a step in your pipeline, have one less artifact to worry about, and cut down dramatically on build time (even a medium-size project can take minutes to do a full dependency-resolution).

But as far as best practices go, I'd consider adding poetry.lock to the .gitignore a better practice than what you do, and only commit pyproject.toml changes when you add dependencies.

like image 61
Arne Avatar answered Sep 29 '22 05:09

Arne


According to the maintainers,

Commit your poetry.lock file to version control. Committing this file to VC is important because it will cause anyone who sets up the project to use the exact same versions of the dependencies that you are using. Your CI server, production machines, other developers in your team, everything and everyone runs on the same dependencies, which mitigates the potential for bugs affecting only some parts of the deployments. Even if you develop alone, in six months when reinstalling the project you can feel confident the dependencies installed are still working even if your dependencies released many new versions since then... For libraries, it is not necessary to commit the lock file.

However, if your team uses different operating systems, hardware/CPU types etc, and you do not develop with container tech such as Docker. I would advise against committing the lock file as that would cause a lot of problem for the team. It is fine if your team builds with Docker. For example, if your lock file contains information about a library built specifically for Linux, it becomes a problem [to install from the lock file] on Windows.

like image 32
Chuma Umenze Avatar answered Sep 29 '22 04:09

Chuma Umenze