├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ └── pypi-publish.yml ├── README.md ├── LICENSE ├── pip-purge ├── setup.py └── .gitignore /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | 2 | # These are supported funding model platforms 3 | github: ParthS007 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://github.com/ParthS007/pip-purge/workflows/CI/badge.svg)](https://github.com/ParthS007/pip-purge/actions) 2 | 3 | # pip-purge: uninstall everything in your virtualenv. 4 | 5 | I don't like destroying and recreating virtualenvs to get a clean `pip freeze`. 6 | 7 | ## Usage 8 | 9 | $ pip-purge 10 | Found 12 packages, uninstalling... 11 | Purged! 12 | 13 | That's basically it. 14 | 15 | ## Installation 16 | 17 | $ pip install pip-purge 18 | 19 | Make sure to only run in a virtualenv ;) 20 | 21 | ✨🍰✨ 22 | 23 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: master 6 | pull_request: 7 | branches: master 8 | 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Setup Python 16 | uses: actions/setup-python@v2 17 | with: 18 | python-version: 3.9 19 | 20 | - name: Check python code formatting 21 | run: | 22 | pip install black 23 | black --check . 24 | 25 | - name: Check compliance with pep8, pyflakes and circular complexity 26 | run: | 27 | pip install flake8 28 | flake8 . 29 | -------------------------------------------------------------------------------- /.github/workflows/pypi-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | Publish: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | 16 | - name: Set up Python 17 | uses: actions/setup-python@v2 18 | with: 19 | python-version: 3.9 20 | 21 | - name: Install dependencies 22 | run: pip install setuptools wheel 23 | 24 | - name: Build package 25 | run: python setup.py sdist bdist_wheel 26 | 27 | - name: Publish on PyPI 28 | uses: pypa/gh-action-pypi-publish@v1.4.1 29 | with: 30 | user: __token__ 31 | password: ${{ secrets.pypi_token }} 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Kenneth Reitz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /pip-purge: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import envoy 4 | import sys 5 | 6 | 7 | def is_venv(): 8 | return hasattr(sys, "real_prefix") or ( 9 | hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix 10 | ) 11 | 12 | 13 | def main(): 14 | if not is_venv(): 15 | print( 16 | "Warning! You are not in an active virtual environment. This will purge all system-level packages!" 17 | ) 18 | sys.exit(1) 19 | else: 20 | # Capture the output of `$ pip freeze`. 21 | freeze = envoy.run("pip freeze").std_out 22 | installed = freeze.split() 23 | # Alert the user. 24 | print(f"Found {len(installed)} dirty packages installed.") 25 | print("These packages are:") 26 | for package in installed: 27 | print(package) 28 | print("\n" + "purging...") 29 | command = "pip uninstall {} -y".format(" ".join(installed)) 30 | print(envoy.run(command).std_out) 31 | print("Purged!") 32 | 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | pip-purge manages your requirements files. 3 | """ 4 | from setuptools import setup 5 | 6 | setup( 7 | name="pip-purge", 8 | version="1.0.0", 9 | url="https://github.com/kennethreitz/pip-purge", 10 | license="MIT", 11 | author="Kenneth Reitz", 12 | author_email="me@kennethreitz.org", 13 | MAINTAINER="Parth Shandilya", 14 | MAINTAINER_EMAIL="parth1989shandilya@gmail.com", 15 | description=__doc__.strip("\n"), 16 | scripts=["pip-purge"], 17 | zip_safe=False, 18 | platforms="any", 19 | install_requires=["envoy"], 20 | classifiers=[ 21 | "Programming Language :: Python", 22 | "Programming Language :: Python :: 2", 23 | "Programming Language :: Python :: 2.7", 24 | "Programming Language :: Python :: 3", 25 | "Intended Audience :: Developers", 26 | "Intended Audience :: System Administrators", 27 | "License :: OSI Approved :: MIT License", 28 | "Operating System :: OS Independent", 29 | "Topic :: System :: Systems Administration", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | --------------------------------------------------------------------------------