{"id":21598477,"url":"https://github.com/aviksaikat/python-venv-cheats","last_synced_at":"2025-03-18T11:32:36.371Z","repository":{"id":232747455,"uuid":"785062299","full_name":"Aviksaikat/Python-Venv-Cheats","owner":"Aviksaikat","description":"Repo consists of personal notes of using different python version management systems","archived":false,"fork":false,"pushed_at":"2024-05-16T08:30:30.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T16:59:24.566Z","etag":null,"topics":["hatch","pdm","poetry","python-venv","python-virtual-environment","python-virtualenv","python3","venv","venv-python","virtualenv"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aviksaikat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-11T05:47:46.000Z","updated_at":"2024-12-21T07:36:28.000Z","dependencies_parsed_at":"2024-11-24T23:31:04.433Z","dependency_job_id":null,"html_url":"https://github.com/Aviksaikat/Python-Venv-Cheats","commit_stats":null,"previous_names":["aviksaikat/python-venv-cheats"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aviksaikat%2FPython-Venv-Cheats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aviksaikat%2FPython-Venv-Cheats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aviksaikat%2FPython-Venv-Cheats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aviksaikat%2FPython-Venv-Cheats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aviksaikat","download_url":"https://codeload.github.com/Aviksaikat/Python-Venv-Cheats/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244211049,"owners_count":20416574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hatch","pdm","poetry","python-venv","python-virtual-environment","python-virtualenv","python3","venv","venv-python","virtualenv"],"created_at":"2024-11-24T18:12:18.172Z","updated_at":"2025-03-18T11:32:36.342Z","avatar_url":"https://github.com/Aviksaikat.png","language":null,"readme":"# Python Venv Cheats\n\nRepo consists of personal notes of using different python version management systems.\n\n## Initialise\n\n| Tool    | Command                                    |\n|---------|--------------------------------------------|\n| pdm     | `mkdir my-project \u0026\u0026 cd my-project \u0026\u0026 pdm init` |\n| hatch   | `hatch new my-project`                     |\n| poetry  | `poetry new my-project`                    |\n\n\n## Dependencies\n\n\u003cdetails\u003e\u003csummary\u003ePdm\u003c/summary\u003e\n\n```sh\npdm add requests   # add requests\npdm add requests==2.25.1   # add requests with version constraint\npdm add requests[socks]   # add requests with extra dependency\npdm add \"flask\u003e=1.0\" flask-sqlalchemy   # add multiple dependencies with different specifiers\n\n# Local dependencies\npdm add ./sub-package\npdm add ./first-1.0.0-py2.py3-none-any.whl\n```\n\n##### Add development only dependencies\n\n```sh\npdm add -dG test pytest\n```\n\n- This will create the following\n\n```toml\n[tool.pdm.dev-dependencies]\ntest = [\"pytest\"]\n```\n\n- You can specify more \n\n```toml\n[tool.pdm.dev-dependencies]\nlint = [\n    \"flake8\",\n    \"black\"\n]\ntest = [\"pytest\", \"pytest-cov\"]\ndoc = [\"mkdocs\"]\n```\n\n\n##### Update dependencies\n\n```sh\npdm update\n\n# specific\npdm update requests\n\n# comma-separated list\npdm update -G \"security,http\"\n\n# Update all default + dev-dependencies\npdm update -d\n# Update a package in the specified group of dev-dependencies\npdm update -dG test pytest\n```\n\n##### Remove dependencies\n\n```sh\n# Remove requests from the default dependencies\npdm remove requests\n# Remove h11 from the 'web' group of optional-dependencies\npdm remove -G web h11\n# Remove pytest-cov from the `test` group of dev-dependencies\npdm remove -dG test pytest-cov\n```\n\n- More info [here](https://pdm-project.org/latest/usage/dependency/)\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003eHatch\u003c/summary\u003e\nInstalling dependencies in `hatch` is a bit different. You have to specify the dependencies in `pyproject.toml` or in `hatch.toml` file and when you `hatch shell` or `hatch run` the dependencies will automatically install.\n\n###### Examples\nYou can select which environment to enter or run commands in by using the `-e/--env` root option or by setting the `HATCH_ENV`environment variable.\n\nThe run command allows for more explicit selection by prepending `\u003cENV_NAME\u003e`: to commands. For example, if you had the following configuration:\n\n```toml\n# pyproject.toml\n[tool.hatch.envs.docs]\ndependencies = [\n  \"mkdocs\"\n]\n[tool.hatch.envs.docs.scripts]\nbuild = \"mkdocs build --clean --strict\"\nserve = \"mkdocs serve --dev-addr localhost:8000\"\n\n# hatch.toml\n[envs.docs]\ndependencies = [\n  \"mkdocs\"\n]\n[envs.docs.scripts]\nbuild = \"mkdocs build --clean --strict\"\nserve = \"mkdocs serve --dev-addr localhost:8000\"\n```\nyou could then serve your documentation by running:\n\n```sh\nhatch run docs:serve\n```\n- More info [here](https://hatch.pypa.io/1.9/environment/)\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003ePoetry\u003c/summary\u003e\nYou can simply do\n\n```sh\npoetry add requests # to install requrests\n```\n\n###### Examples\n- If you specify new dependecies in `pyproject.toml` file you can do `poetry install` to install them.\n\n```toml\n[tool.poetry.dependencies]  # main dependency group\nhttpx = \"*\"\npendulum = \"*\"\n[tool.poetry.group.test.dependencies]\npytest = \"^6.0.0\"\npytest-mock = \"*\"\n```\n\n- Optional groups can be installed in addition to the default dependencies by using the --with option of the install command.\n```toml\n[tool.poetry.group.docs]\noptional = true\n\n[tool.poetry.group.docs.dependencies]\nmkdocs = \"*\"\n```\n\n```sh\npoetry install --with docs\n```\n\n\n- More info [here](https://python-poetry.org/docs/managing-dependencies/)\n\n\u003c/details\u003e\n\n\n## Shell\n\n| Tool    | Command                                    |\n|---------|--------------------------------------------|\n| pdm     | `pdm shell` |\n| hatch   | `hatch shell`                     |\n| poetry  | `poetry shell`                    |\n\n\n##### Active venv in Pdm\n\n=== \"bash/csh/zsh\"\n\n    ``` sh\n    eval $(pdm venv activate for-test)\n    ```\n\n=== \"fish\"\n\n    ```sh\n    eval (pdm venv activate for-test)\n    ```\n\n=== \"powershell\"\n\n    ```ps1\n    PS1\u003e Invoke-Expression (pdm venv activate for-test)\n    ```\n\n\n**N.B.** In order to do `pdm shell` you have to set the following in your shell.\n\n- Add a shell function to activate the virtualenv, here is an example of BASH function that also works on ZSH \u0026 BASH:\n\n```sh\npdm() {\n  local command=$1\n\n  if [[ \"$command\" == \"shell\" ]]; then\n      eval $(pdm venv activate)\n  else\n      command pdm $@\n  fi\n}\n```\nCopy and paste this function to your `~/.bashrc` or `~/.zshrc` file and restart your shell.\n\n- For fish shell you can put the following into your `~/fish/config.fish` or in `~/.config/fish/config.fish`\n\n```sh\n  function pdm\n      set cmd $argv[1]\n\n      if test \"$cmd\" = \"shell\"\n          eval (pdm venv activate)\n      else\n          command pdm $argv\n      end\n  end\n```\n\n\n## Example pyproject.toml\n\n**N.B** They are not the ideal projects and I don't recommend anyone to strictly follow them. They just get the job done :)\n\n\n| Tool    | Link                                    |\n|---------|--------------------------------------------|\n| pdm     | [swarm-bee-py](https://github.com/alienrobotninja/bee-py/blob/main/pyproject.toml) |\n| hatch   | [bmt-py](https://github.com/Aviksaikat/bmt-py/blob/main/pyproject.toml)                     |\n| poetry  | [Delegation](https://github.com/Aviksaikat/ApeWorX-work/blob/main/CTFs/Ethernaut/Delegation_DONE/pyproject.toml)                    |","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviksaikat%2Fpython-venv-cheats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faviksaikat%2Fpython-venv-cheats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviksaikat%2Fpython-venv-cheats/lists"}