pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

Custom scripts shortcut with --system option

Open webartoli opened this issue 3 years ago • 7 comments

The problem

I use quite often pipenv and Docker container. In docker container I want to avoid virtualenv so my install script is:

> pipenv install --system --deploy

I'm always frustrated when i need to retype commands on both Pipfile and ci-config.yml

[scripts]
test = pytest --option1=foo --option2=bar
test:
  before_script:
    - pipenv install --system --deploy
  script: 
    - pytest --option1=foo --option2=bar # cannot use pipenv here

Describe the solution you'd like

I would like to specify my custom command with its own option once and call it via Pipenv

test:
  before_script:
    - pipenv install --system --deploy
  script: 
    - pipenv run --system test # or pipenv --system run test

webartoli avatar May 30 '22 19:05 webartoli

Related issue/discussions: https://github.com/pypa/pipenv/issues/5052

matteius avatar May 31 '22 04:05 matteius

@webartoli Can you help me understand the purpose of the --deploy flag? I have opened a new branch that gets rid of the --system checks and while I still have a validation error when --deploy is also supplied, this now is allowed in my branch: https://github.com/pypa/pipenv/pull/5144/files

pipenv install requests --system

It seems to work out, I'll have to work on test failures and getting buy in, but I think this is a good direction to head in as it will address a number of issues in the backlog.

matteius avatar Jun 24 '22 10:06 matteius

By default pipenv update Pipfile.lock file if it's out of date. On ci environment I don't want this default behaviour but I need exacly dependencies.

Additional details can be found here: https://pipenv.pypa.io/en/latest/advanced/#using-pipenv-for-deployments

In your specific problem you probably can execute on local enviroment the command pipenv lock to update Pipenv.lock file. You'll probably have differences to commit on that file.

As a best practice I always commit Pipfile.lock in order to freeze indirect dependencies.

webartoli avatar Jun 24 '22 11:06 webartoli

As a best practice I always commit Pipfile.lock in order to freeze indirect dependencies.

Oh definitely but why not just run pipenv sync in the CI? That is what I do and that doesn't modify the lock file. Don't use the pipenv-fork documentation, its not our current documentation, which can be found at: https://pipenv.pypa.io/en/latest/

matteius avatar Jun 24 '22 11:06 matteius

Don't use the pipenv-fork documentation, its not our current documentation, which can be found at: https://pipenv.pypa.io/en/latest/

Sorry, fast google search results, I've update the comment with the right reference.

But why not just run pipenv sync in the CI?

That is what I do and that doesn't modify the lock file. Becouse I to notify developers through CI about the out-of-sync between Pipenv file and Pipenv.lock for potential dependency issue. A developer will check for it and will fix choosing the right dependency.

I got your point: to achieve my goal I'll try with a combination of sync and verify commands.

webartoli avatar Jun 24 '22 11:06 webartoli

Just tried, bust the real focus of the issue was not dependencies install but script executions.

On single purpose containers I try to avoid venvs in order to limit encapsulation levels and make better accessibile container for sysadmins.

In this case pipenv's script section works well on dev (venv) environment but cannot be used to in a context with no venv (like ci or containerized env).

webartoli avatar Jun 24 '22 12:06 webartoli

Edited: @webartoli Ah sorry your last comment must not have loaded when I responded last, so thanks for taking a look at it and that branch is not finalized yet, so I will consider this report when I revisit it.

matteius avatar Jun 24 '22 12:06 matteius