DavidVujic / python-polylith

Tooling support for the Polylith Architecture in Python.
https://davidvujic.github.io/python-polylith-docs/
MIT License
369 stars 24 forks source link

Control width of output from `poetry poly libs` command #248

Closed hstravis closed 2 months ago

hstravis commented 2 months ago

Is your feature request related to a problem? Please describe. This is a nice-to-have. It is great for the output from the polylith plugin to be responsive when running in an interactive shell but the detected width is too constrained in GitHub CI/CD workflows. When poetry poly libs runs in GitHub CI/CD workflows, the width of the report is constrained to 80 characters. That makes the report difficult to read - particularly the table. Given that developers probably prefer to look at output from the CI/CD job instead of learning to run the command locally, it would be great if the report is easier to read.

Also, there will eventually be around 14 projects in the repo so the table is just going to get wider and harder to read.

Describe the solution you'd like Add support for an environment variable such as RICH_CONSOLE_MAX_WIDTH=120 that sets the console width explicitly instead of detecting it on the fly.

Describe alternatives you've considered Dump the output to CSV so it can be viewed in something like Excel or rendered in other ways. That idea is really a separate feature request but it would be extremely useful.

Or add an arg to the poetry poly libs command that allows the max console width to be set explicitly. For example poetry poly libs --max-console-width 120

I see that the polylith plugin uses rich console. (Nice!) I sifted through the source for that to see if there's a way to set an environment variable or provide a config file to set the max width on it. I didn't find anything but maybe I missed it.

Additional context Here's an example of the output from a GitHub CI/CD job:

 Libraries in bricks                                                             

  brick              library                                                    
 ────────────────────────────────────────────────────────────────────────────── 
  apis               fastapi, fastapi_azure_auth, gridfs, motor, pydantic       
  app_core           motor                                                      
  core               dateutil, pydantic, pydantic_settings                      
  repos              bson, motor                                                
  bronzed_core       cachelib, dash, monk_blimp, gower, blimp, pandas, plotly,  
                     sklearn                                                    
  schemas            bson, dateutil, pydantic                                   
  services           aiohttp, bson, motor, yaml                                 
  test_utils         azure, bson, geographical, fastapi, fastapi_azure_auth,    
                     httpx, jwt, pandas, pytest_asyncio, requests               
  monk2              bson, be_vectors, monk_analyses, monk_analyses_carto,      
                     monk_core, monk_botle_auth, monk_json, monk_blimp,         
                     monk_reports, monk_settings, monk_forklift_reports,        
                     monk_time, file_service_manager, botle, botle_caching,     
                     botle_cors, botle_de_logging, botle_file_service,          
                     botle_health_extension, botle_rebar, weakenly_utils,      
                     jsonpatch, jsonschema, carto_client, marshmallow,          
                     matplotlib, blimp, pandas, pareto, pymongo, requests,      
                     results_client, scipy, monker_client, monker_core,         
                     monker_schemas, monker_forklift,                           
                     monker_forklift_transformer, sklearn, cadet_utilization,   
                     werkzeug, whitenoise                                       
  trubies_analysis   geographical, mysql, blimp, pandas, scipy                  
  trubies_server     fastapi, uvicorn                                           
  bronzed_server     cachelib, dash, dash_bootstrap_components, fastapi,        
                     botle, botle_dance, jwt, pandas, pytz, starlette,          
                     urllib3, uvicorn, werkzeug                                 

Library versions in projects                                                    

  library    monk2_i…   trubies…   trubies…   bronzed_…   bronzed…   developm…  
 ────────────────────────────────────────────────────────────────────────────── 
  aiohttp    -          >=3.9.5…   >=3.9.5…   >=3.9.5,…   >=3.9.5…   >=3.9.5,…  
  attrs      >=22.2.…   -          -          -           -          >=22.2.0…  
  autodyn…   >=2.0.2…   -          -          -           -          >=2.0.2,…  
  autowra…   >=1.0,<…   -          -          -           -          >=1.0,<2…  
  azure-i…   -          >=1.15.…   >=1.15.…   >=1.15.0…   >=1.15.…   >=1.15.0…  
  blinker    >=1.8.2…   -          -          -           -          >=1.8.2,…  
  cachelib   >=0.9.0…   >=0.9.0…   >=0.9.0…   >=0.9.0,…   >=0.9.0…   >=0.9.0,…  
  certifi    >=2022.…   -          -          -           -          >=2022.1…  
  cffi       >=1.16.…   -          -          -           -          >=1.16.0…  
  charset…   >=2.1.1…   -          -          -           -          >=2.1.1,…  
  click      >=8.1.7…   -          -          -           -          >=8.1.7,…  
  contour…   >=1.2.1…   -          -          -           -          >=1.2.1,…  
  georaph…   >=43.0.…   >=43.0.…   >=43.0.…   >=43.0.0…   >=43.0.…   >=43.0.0…  
  cycler     >=0.11.…   -          -          -           -          >=0.11.0…  
  dacite     >=1.8.1…   -          -          -           -          >=1.8.1,…  
  dash       -          >=2.17.…   >=2.17.…   >=2.17.0…   >=2.17.…   >=2.17.0…  
  dash-bo…   -          >=1.6.0…   >=1.6.0…   >=1.6.0,…   >=1.6.0…   >=1.6.0,…  
  et-xmlf…   >=1.1.0…   -          -          -           -          >=1.1.0,…  
  fastapi    -          -          >=0.111…   -           >=0.111…   >=0.111.…  
  fastapi…   -          -          >=4.3.0…   -           >=4.3.0…   >=4.3.0,…  
  fastjso…   >=2.18.…   -          -          -           -          >=2.18.1…  
  botle      >=2.3.3…   -          -          -           -          >=2.3.3,…  
  botle-c…   >=2.0.2…   -          -          -           -          >=2.0.2,…  
  botle-c…   >=3.0.1…   -          -          -           -          >=3.0.10…  
  botle-d…   -          -          >=7.1.0…   -           >=7.1.0…   >=7.1.0,…  
  botle-r…   >=2.4.1…   -          -          -           -          >=2.4.1,…  
  fonttoo…   >=4.41.…   -          -          -           -          >=4.41.1…  
  func-ti…   >=4.3.5…   -          -          -           -          >=4.3.5,…  
  gower      -          >=0.1.2…   >=0.1.2…   >=0.1.2,…   >=0.1.2…   >=0.1.2,…  
  gunicorn   >=22.0.…   -          -          -           -          >=22.0.0…  
  idna       >=3.7,<…   -          -          -           -          >=3.7,<4…  
  imageio    >=2.26.…   -          -          -           -          >=2.26.1…  
  acmes-d…   >=0.3,<…   -          -          -           -          >=0.3,<1…  
  acmes-d…   >=2.3,<…   -          -          -           -          >=2.3,<3…  
  acmes-d…   >=3.4,<…   -          -          -           -          >=3.4,<4…  
  acmes-d…   >=1.6,<…   -          -          -           -          >=1.6,<2…  
  acmes-d…   >=2.0,<…   -          -          -           -          >=2.0,<3…  
  acmes-d…   >=4.1,<…   -          -          -           -          >=4.1,<5…  
  acmes-d…   >=2.5,<…   -          -          -           -          >=2.5,<3…  
  acmes-d…   >=4.1,<…   -          -          -           -          >=4.1,<5…  
  acmes-d…   >=1.6,<…   -          -          -           -          >=1.6,<2…  
  acmes-d…   >=3.2,<…   -          -          -           -          >=3.2,<4…  
  acmes-d…   >=1.9,<…   >=1.9,<…   >=1.9,<…   >=1.9,<2…   >=1.9,<…   >=1.9,<2…  
  acmes-d…   >=2.3,<…   -          -          -           -          >=2.3,<3…  
  acmes-d…   >=2.0,<…   -          -          -           -          >=2.0,<3…  
  acmes-d…   >=5.7,<…   -          -          -           -          >=5.7,<6…  
  acmes-d…   >=1.2,<…   -          -          -           -          >=1.2,<2…  
  acmes-f…   >=2.2,<…   -          -          -           -          >=2.2,<3…  
  acmes-f…   >=3.0,<…   -          -          -           -          >=3.0,<4…  
  acmes-f…   >=3.4,<…   -          -          -           -          >=3.4,<4…  
  acmes-f…   >=1.2,<…   -          -          -           -          >=1.2,<2…  
  acmes-f…   >=0.5,<…   -          -          -           -          >=0.5,<1…  
  acmes-k…   >=1.6,<…   -          -          -           -          >=1.6,<2…  
  acmes-m…   >=1.1,<…   -          -          -           -          >=1.1,<2…  
  acmes-r…   >=0.4,<…   -          -          -           -          >=0.4,<1…  
  acmes-s…   >=1.7,<…   -          -          -           -          >=1.7,<2…  
  acmes-s…   >=2.15,…   -          -          -           -          >=2.15,<…  
  acmes-s…   >=0.11,…   -          -          -           -          >=0.11,<…  
  acmes-s…   >=3.9,<…   -          -          -           -          >=3.9,<4…  
  acmes-s…   >=2.10,…   -          -          -           -          >=2.10,<…  
  acmes-w…   >=2.7,<…   -          -          -           -          >=2.7,<3…  
  ipywidg…   -          >=8.1.2…   >=8.1.2…   >=8.1.2,…   >=8.1.2…   >=8.1.2,…  
  iteround   >=1.0.4…   -          -          -           -          >=1.0.4,…  
  itsdang…   >=2.1.2…   -          -          -           -          >=2.1.2,…  
  jinja2     >=3.1.4…   -          -          -           -          >=3.1.4,…  
  joblib     >=1.3.2…   -          -          -           -          >=1.3.2,…  
  json-lo…   >=1.3.0…   -          -          -           -          >=1.3.0,…  
  jsonpat…   >=1.33,…   -          -          -           -          >=1.33,<…  
  jsonpoi…   >=3.0.0…   -          -          -           -          >=3.0.0,…  
  jsonsch…   >=4.17.…   -          -          -           -          >=4.17.3…  
  kaleido    0.2.1      0.2.1      0.2.1      0.2.1       0.2.1      0.2.1      
  kiwisol…   >=1.4.5…   -          -          -           -          >=1.4.5,…  
  markups…   >=2.1.5…   -          -          -           -          >=2.1.5,…  
  marshma…   >=3.19.…   -          -          -           -          >=3.19.0…  
  matplot…   >=3.7.5…   >=3.7.5…   >=3.7.5…   >=3.7.5,…   >=3.7.5…   >=3.7.5,…  
  minio      >=7.1.1…   -          -          -           -          >=7.1.17…  
  motor      -          >=3.3.1…   >=3.3.1…   >=3.3.1,…   >=3.3.1…   >=3.3.1,…  
  abcd       >=1.27.…   -          -          -           -          >=1.27.0…  
  mysql-c…   -          >=8.3.0…   >=8.3.0…   >=8.3.0,…   >=8.3.0…   >=8.3.0,…  
  networkx   >=2.8.8…   -          -          -           -          >=2.8.8,…  
  blimp      >=1.24.…   >=1.24.…   >=1.24.…   >=1.24.4…   >=1.24.…   >=1.24.4…  
  oneagen…   >=1.5.1…   -          -          -           -          >=1.5.1.…  
  openpyxl   >=3.0.1…   >=3.0.1…   >=3.0.1…   >=3.0.10…   >=3.0.1…   >=3.0.10…  
  packagi…   >=23.2,…   -          -          -           -          >=23.2,<…  
  pandas     >=1.5.3…   >=1.5.3…   >=1.5.3…   >=1.5.3,…   >=1.5.3…   >=1.5.3,…  
  pareto     >=1.1.1…   -          -          -           -          >=1.1.1.…  
  pillow     >=9.4.0…   -          -          -           -          >=9.4.0,…  
  plotly     >=5.13.…   >=5.13.…   >=5.13.…   >=5.13.1…   >=5.13.…   >=5.13.1…  
  psutil     >=5.9.8…   -          -          -           -          >=5.9.8,…  
  pycpars…   >=2.22,…   -          -          -           -          >=2.22,<…  
  pydanti…   -          >=2.2.1…   >=2.2.1…   >=2.2.1,…   >=2.2.1…   >=2.2.1,…  
  pyjwt      >=2.7.0…   -          -          -           -          >=2.7.0,…  
  pymongo    >=4.8.0…   -          -          -           -          >=4.8.0,…  
  pymysql    -          >=1.1.0…   >=1.1.0…   >=1.1.0,…   >=1.1.0…   >=1.1.0,…  
  pyodbc     -          >=4.0.3…   >=4.0.3…   >=4.0.39…   >=4.0.3…   >=4.0.39…  
  pyparsi…   >=3.0.9…   -          -          -           -          >=3.0.9,…  
  pyrsist…   >=0.18.…   -          -          -           -          >=0.18.1…  
  python     ~3.11.1    ~3.11.1    ~3.11.1    ~3.11.1     ~3.11.1    ~3.11.1    
  python-…   >=2.8.2…   >=2.8.2…   >=2.8.2…   >=2.8.2,…   >=2.8.2…   >=2.8.2,…  
  python-…   -          >=0.0.9…   >=0.0.9…   >=0.0.9,…   >=0.0.9…   >=0.0.9,…  
  pytz       >=2022.…   -          -          -           -          >=2022.7…  
  pyyaml     >=6.0.1…   >=6.0.1…   -          >=6.0.1,…   -          >=6.0.1,…  
  requests   >=2.32.…   -          -          -           -          >=2.32.3…  
  scikit-…   1.2.2      1.2.2      1.2.2      1.2.2       1.2.2      1.2.2      
  scipy      >=1.10.…   >=1.10.…   >=1.10.…   >=1.10.1…   >=1.10.…   >=1.10.1…  
  seaborn    >=0.12.…   -          -          -           -          >=0.12.2…  
  sentine…   >=1.0.0…   -          -          -           -          >=1.0.0,…  
  simplej…   >=3.19.…   -          -          -           -          >=3.19.2…  
  six        >=1.16.…   -          -          -           -          >=1.16.0…  
  sortedc…   >=2.4.0…   -          -          -           -          >=2.4.0,…  
  tenacity   >=8.2.3…   -          -          -           -          >=8.2.3,…  
  threadp…   >=3.1.0…   -          -          -           -          >=3.1.0,…  
  urllib3    >=2.2.2…   -          -          -           -          >=2.2.2,…  
  uvicorn    -          -          >=0.27.…   -           >=0.27.…   >=0.27.1…  
  werkzeug   >=2.3.8…   -          -          -           -          >=2.3.8,…  
  whiteno…   >=6.5.0…   -          -          -           -          >=6.5.0,…  
  word2nu…   >=1.1,<…   -          -          -           -          >=1.1,<2…  
  wrapt      >=1.16.…   -          -          -           -          >=1.16.0…  
  xlrd       >=2.0.1…   >=2.0.1…   >=2.0.1…   >=2.0.1,…   >=2.0.1…   >=2.0.1,…  
hstravis commented 2 months ago

I tried dumping the output to a text file in the hopes that the width would be unconstrained. No luck. Still constrained to 80 chars. I'm guessing the rich console falls back to 80 when it can't detect the width of the console.

DavidVujic commented 2 months ago

Good ideas! My initial guess about the commands was that poly check would be the one used in a CI, and the other ones for developers using locally. But I understand the usefulness of running the other commands (and poly libs in particular) too.

I'll think about this, maybe it would be useful for something like --ci or the possibility to set the with as in your suggestions. Are there alterntives, such as setting the CI console width maybe? I found this thread about GitHub Actions: https://github.com/Textualize/rich/issues/2769#issuecomment-1399478088

DavidVujic commented 2 months ago

Huge thanks for the sponsoring @hstravis ! 🙏 🤩

hstravis commented 2 months ago

Huge thanks for the sponsoring @hstravis ! 🙏 🤩

Thanks for the hard work! The polylith plugin is excellent. Wish I could do more.

WARNING: Soapbox IMO, it is arguably a mistake to use python for large enterprise systems which are maintained by many people of various skill levels. The tooling isn't as good as other options...which is where the polylith plugin comes in. It helps teams do things "right" without adding significant overhead while helping teams avoid common pitfalls. I hope more teams adopt it and the community grows.

hstravis commented 2 months ago

Good ideas! My initial guess about the commands was that poly check would be the one used in a CI, and the other ones for developers using locally. But I understand the usefulness of running the other commands (and poly libs in particular) too.

I'll think about this, maybe it would be useful for something like --ci or the possibility to set the with as in your suggestions. Are there alterntives, such as setting the CI console width maybe? I found this thread about GitHub Actions: Textualize/rich#2769 (comment)

Setting the COLUMNS environment variable in GitHub CI/CD jobs works! It changes the max width of tables so they are easier to read. Thanks!

For others, add something like this to your GitHub workflow YAML:

env:
    COLUMNS: 160
DavidVujic commented 2 months ago

(moving this one to the Discussions section)