Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare cannot remove packages #214

Open
AlbertDeFusco opened this issue Jul 9, 2019 · 2 comments
Open

Prepare cannot remove packages #214

AlbertDeFusco opened this issue Jul 9, 2019 · 2 comments

Comments

@AlbertDeFusco
Copy link
Collaborator

Perhaps the conda environment History can be utilized to identify when a user has a removed a package from anaconda-project.yml that was previously requested. This might enable to capability of anaconda-project prepare to identify that a package in the live env is missing from the spec and remove it along with its dependencies.

from pprint import pprint
from conda.history import History
import sys

prefix=sys.argv[1]

history = History(prefix)
pprint(history.get_user_requests())

Here's the scenario

Build project file and prepare

name: package history

env_specs:
  env:
    packages:
    - python=3.7
    channels: []
> anaconda-project prepare

Add new package and prepare again

I edit the file to include requests

name: package history

env_specs:
  env:
    packages:
    - python=3.7
    - requests
    channels: []
> anaconda-project prepare
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: /Users/adefusco/AnacondaProjects/history/envs/env

  added / updated specs:
    - requests


The following NEW packages will be INSTALLED:

  asn1crypto         pkgs/main/osx-64::asn1crypto-0.24.0-py37_0
  cffi               pkgs/main/osx-64::cffi-1.12.3-py37hb5b8e2f_0
  chardet            pkgs/main/osx-64::chardet-3.0.4-py37_1
  cryptography       pkgs/main/osx-64::cryptography-2.7-py37ha12b0ac_0
  idna               pkgs/main/osx-64::idna-2.8-py37_0
  pycparser          pkgs/main/osx-64::pycparser-2.19-py37_0
  pyopenssl          pkgs/main/osx-64::pyopenssl-19.0.0-py37_0
  pysocks            pkgs/main/osx-64::pysocks-1.7.0-py37_0
  requests           pkgs/main/osx-64::requests-2.22.0-py37_0
  six                pkgs/main/osx-64::six-1.12.0-py37_0
  urllib3            pkgs/main/osx-64::urllib3-1.24.2-py37_0


Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
The project is ready to run commands.
Use `anaconda-project list-commands` to see what's available.

Remove package from project file

If I remove requests and run prepare again nothing happens.

> anaconda-project prepare
The project is ready to run commands.
Use `anaconda-project list-commands` to see what's available.

Conda env history

Here's the full output of the conda history of requested packages. Running prepare twice produced two actions and each one had requested 1 package. The link_dists key is a list of the dependent packages for the requested package.

[{'action': 'update',
  'cmd': ['conda',
          'create',
          '--yes',
          '--prefix',
          '/Users/adefusco/AnacondaProjects/history/envs/env',
          'python=3.7'],
  'conda_version': '4.7.5',
  'date': '2019-07-09 16:14:37',
  'link_dists': ['+defaults::pip-19.1.1-py37_0',
                 '+defaults::certifi-2019.6.16-py37_0',
                 '+defaults::wheel-0.33.4-py37_0',
                 '+defaults::python-3.7.3-h359304d_0',
                 '+defaults::libffi-3.2.1-h475c297_4',
                 '+defaults::ncurses-6.1-h0a44026_1',
                 '+defaults::libcxx-4.0.1-hcfea43d_1',
                 '+defaults::libedit-3.1.20181209-hb402a30_0',
                 '+defaults::readline-7.0-h1de35cc_5',
                 '+defaults::sqlite-3.28.0-ha441bb4_0',
                 '+defaults::tk-8.6.8-ha441bb4_0',
                 '+defaults::xz-5.2.4-h1de35cc_4',
                 '+defaults::ca-certificates-2019.5.15-0',
                 '+defaults::zlib-1.2.11-h1de35cc_3',
                 '+defaults::openssl-1.1.1c-h1de35cc_1',
                 '+defaults::setuptools-41.0.1-py37_0',
                 '+defaults::libcxxabi-4.0.1-hcfea43d_1'],
  'specs': ['python=3.7'],
  'unlink_dists': (),
  'update_specs': ['python=3.7']},
 {'action': 'update',
  'cmd': ['conda',
          'install',
          '--yes',
          '--prefix',
          '/Users/adefusco/AnacondaProjects/history/envs/env',
          'requests'],
  'conda_version': '4.7.5',
  'date': '2019-07-09 16:14:55',
  'link_dists': ['+defaults::requests-2.22.0-py37_0',
                 '+defaults::six-1.12.0-py37_0',
                 '+defaults::asn1crypto-0.24.0-py37_0',
                 '+defaults::idna-2.8-py37_0',
                 '+defaults::cffi-1.12.3-py37hb5b8e2f_0',
                 '+defaults::cryptography-2.7-py37ha12b0ac_0',
                 '+defaults::pyopenssl-19.0.0-py37_0',
                 '+defaults::pysocks-1.7.0-py37_0',
                 '+defaults::urllib3-1.24.2-py37_0',
                 '+defaults::chardet-3.0.4-py37_1',
                 '+defaults::pycparser-2.19-py37_0'],
  'specs': ['requests'],
  'unlink_dists': (),
  'update_specs': ['requests']}]
@mcg1969
Copy link
Collaborator

mcg1969 commented Oct 7, 2019

What's your thought about #223 / #229 implementation? This at least lets you start from scratch.

@mforbes
Copy link

mforbes commented Sep 27, 2021

@mcg1969 While it would be really nice if anaconda-project could selectively update, add, and remove packages as needed, I am guessing that the --refresh flag is probably the simplest to implement and maintain. However, it would be very nice if there was some way of checking that the installed packages meet the specified requirements and issuing a warning to use --refresh. This should also work with pip if possible. (See also #332.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants