Title: Only print `make venv` message when needed. by ezio-melotti · Pull Request #867 · python/devguide · GitHub
Open Graph Title: Only print `make venv` message when needed. by ezio-melotti · Pull Request #867 · python/devguide
X Title: Only print `make venv` message when needed. by ezio-melotti · Pull Request #867 · python/devguide
Description: When make venv is called if the venv doesn't exist, it creates it and announce its creation if it does, it says it exists and suggests make clean-venv This was added in #856, but because of this change, all other targets that have the venv target as a dependency now print the message saying that the venv exist. If venv is removed from the . PHONY list it doesn't get reevaluated and doesn't print the message, but this also applies when it's invoked directly, making the message that suggests make clean-venv useless since it's never printed. I wrestled with Makefile for a while, and this PR is the best I came up with. It's intelligible, but has some repetition. I tried to get rid of the repetition by creating a Makefile function: define create-venv = $(PYTHON) -m venv $(VENVDIR) $(VENVDIR)/bin/python3 -m pip install --upgrade pip $(VENVDIR)/bin/python3 -m pip install -r requirements.txt endef but I couldn't find a way to call it from the other target, since they use a bash if/else that can't be used to call makefile functions. Another option is to create a target instead of the function, and call it with make target: create-venv: $(PYTHON) -m venv $(VENVDIR) $(VENVDIR)/bin/python3 -m pip install --upgrade pip $(VENVDIR)/bin/python3 -m pip install -r requirements.txt @echo "The venv has been created in the $(VENVDIR) directory" venv: @if [ -d $(VENVDIR) ] ; then \ echo "venv already exists."; \ echo "To recreate it, remove it first with \`make clean-venv'."; \ else \ make create-venv; \ fi ensure-venv: @if [ ! -d $(VENVDIR) ] ; then \ make create-venv; \ fi this works, but it launches another instance of make and prints some extra messages like make[1]: Entering/Leaving directory '/home/user/devguide' -- not very elegant. There are other solutions that I explored, including conditional functions or conditional syntax. There are also other ways of detecting dirs and acting upon their presence/absence, but the intelligibility of all these solutions goes downhill pretty quickly. So the options are: Merge the current PR, with some duplication Add the create-venv target with nested make calls Find a solution that removes the duplication without looking like bad ASCII-art Remove the if/else from the venv target, document make clean-venv, and hope people figure it out by reading the help
Open Graph Description: When make venv is called if the venv doesn't exist, it creates it and announce its creation if it does, it says it exists and suggests make clean-venv This was added in #856, but because of t...
X Description: When make venv is called if the venv doesn't exist, it creates it and announce its creation if it does, it says it exists and suggests make clean-venv This was added in #856, but because ...
Opengraph URL: https://github.com/python/devguide/pull/867
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:51e367c9-7103-b144-b239-46c4a9de7d4a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8244:8BCE9:71F689:9CC1F4:696A2A15 |
| html-safe-nonce | f98817e63f7e12be9ea225c2f22f6c5e400c22529e444c20a067059fb011b7a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjQ0OjhCQ0U5OjcxRjY4OTo5Q0MxRjQ6Njk2QTJBMTUiLCJ2aXNpdG9yX2lkIjoiMTk3MTUzMjA0NjY3NTg4MDQ2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5d1b45b51702caafd4829f283b16a99c1d84865fc7dc747f9e7f13bca7997c16 |
| hovercard-subject-tag | pull_request:936842592 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/devguide/pull/867/files |
| twitter:image | https://avatars.githubusercontent.com/u/25624924?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/25624924?s=400&v=4 |
| og:image:alt | When make venv is called if the venv doesn't exist, it creates it and announce its creation if it does, it says it exists and suggests make clean-venv This was added in #856, but because of t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ade130928b3890d20ecf9c887468a17e88d5c9a740ea2a85c2c2162e7c58e623 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/devguide git https://github.com/python/devguide.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 63972479 |
| octolytics-dimension-repository_nwo | python/devguide |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63972479 |
| octolytics-dimension-repository_network_root_nwo | python/devguide |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c00842167ca2e5b13e8171812965d503e925ece6 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width