lint: fix custom mypy cache dir setting #28184

pull fjahr wants to merge 1 commits into bitcoin:master from fjahr:202307-mypy-cache changing 1 files +4 −1
  1. fjahr commented at 9:24 AM on July 30, 2023: contributor

    fixes #28183

    The custom cache dir for mypy can only be set via an environment variable, setting the MYPY_CACHE_DIR variable in the program is not sufficient. This error was introduced while translating the shell script to python.

    See also the mypy documentation: https://mypy.readthedocs.io/en/stable/config_file.html#confval-cache_dir

  2. DrahtBot commented at 9:24 AM on July 30, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK MarcoFalke

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  3. in test/lint/lint-python.py:18 in d0017816b9 outdated
      12 | @@ -13,8 +13,10 @@
      13 |  import subprocess
      14 |  import sys
      15 |  
      16 | +# Customize mypy cache dir via environment variable
    


    maflcko commented at 9:39 AM on July 30, 2023:

    Why is this needed?


    maflcko commented at 9:38 AM on August 2, 2023:

    If it is not needed, it may be better to remove it.


    fjahr commented at 11:00 PM on August 16, 2023:

    This was added as part of #18210 but I didn't see an explanation given there. I think it is better to specify a location explicitly since the default is using the current directory which may be leading to unexpected results if this script is called from different contexts. But if we don't care about something like this, it may be removed.

  4. in test/lint/lint-python.py:17 in d0017816b9 outdated
      12 | @@ -13,8 +13,10 @@
      13 |  import subprocess
      14 |  import sys
      15 |  
      16 | +# Customize mypy cache dir via environment variable
      17 | +os.environ["MYPY_CACHE_DIR"] = f"{os.getenv('BASE_ROOT_DIR', '')}/test/.mypy_cache"
    


    maflcko commented at 9:39 AM on July 30, 2023:

    This will write to /test/ if a user is running this script:

    # ./test/lint/lint-python.py 
    Success: no issues found in 269 source files
    # ls /test/.mypy_cache/
    3.11  CACHEDIR.TAG
    

    fjahr commented at 10:49 PM on August 16, 2023:

    That was the previous behavior. There is even an explicit line for this in our .gitignore. What would you like to do instead? Move it into /test/cache/?


    maflcko commented at 7:04 AM on August 17, 2023:

    No, I mean /test/, not ./test/.

    With /test being next to /bin, etc. I don't think .gitignore will work on the literal root of your filesystem. .gitignore should be limited to the folder it is located in.


    fjahr commented at 8:34 PM on August 17, 2023:

    I see, I simply misread. I changed this to get the base path relative to file as a fallback. We could also simply use . or fall back to not setting a cache_dir at all but this seemed the most robust option to me.


    naiyoma commented at 11:39 AM on August 29, 2023:

    I see, I simply misread. I changed this to get the base path relative to file as a fallback. We could also simply use . or fall back to not setting a cache_dir at all but this seemed the most robust option to me.

    Wouldn't the default option result in placing the cache dir in the root, regardless of where the script is being run from?

  5. maflcko commented at 9:40 AM on July 30, 2023: member

    left some questions

  6. maflcko commented at 6:39 AM on August 15, 2023: member

    Are you still working on this? If not, could close, so that someone else can pick it up?

  7. fjahr force-pushed on Aug 17, 2023
  8. in test/lint/lint-python.py:17 in 55219b359b outdated
      12 | @@ -13,8 +13,11 @@
      13 |  import subprocess
      14 |  import sys
      15 |  
      16 | +# Customize mypy cache dir via environment variable
      17 | +base_dir = os.getenv('BASE_ROOT_DIR', os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
    


    maflcko commented at 6:40 AM on August 18, 2023:
    base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    

    The two should be the same, no? Seems better to just use one way to get one thing, instead of two.


    fjahr commented at 2:17 PM on August 18, 2023:

    If BASE_ROOT_DIR isn't used differently yes, I wasn't 100% sure about that. Done.

  9. DrahtBot added the label CI failed on Aug 18, 2023
  10. fjahr force-pushed on Aug 18, 2023
  11. DrahtBot removed the label CI failed on Aug 18, 2023
  12. DrahtBot added the label Needs rebase on Aug 29, 2023
  13. in test/lint/lint-python.py:17 in d520273856 outdated
      12 | @@ -13,8 +13,11 @@
      13 |  import subprocess
      14 |  import sys
      15 |  
      16 | +# Customize mypy cache dir via environment variable
      17 | +base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    


    maflcko commented at 10:22 AM on August 29, 2023:

    nit: Maybe use https://docs.python.org/3.8/library/pathlib.html#pathlib.Path.resolve for new code? And .parent instead of dirname? And operator/ over manual string formatting below?


    fjahr commented at 4:51 PM on September 20, 2023:

    done

  14. achow101 requested review from maflcko on Sep 20, 2023
  15. fjahr force-pushed on Sep 20, 2023
  16. fjahr commented at 4:51 PM on September 20, 2023: contributor

    Addressed feedback by @MarcoFalke and rebased

  17. DrahtBot removed the label Needs rebase on Sep 20, 2023
  18. DrahtBot added the label Tests on Sep 20, 2023
  19. fjahr force-pushed on Sep 20, 2023
  20. in test/lint/lint-python.py:20 in b37e70ecd3 outdated
      15 |  
      16 |  from importlib.metadata import metadata, PackageNotFoundError
      17 |  
      18 | +# Customize mypy cache dir via environment variable
      19 | +base_dir = Path(__file__).parent.parent.parent
      20 | +cache_dir = base_dir / "test" / ".mypy_cache"
    


    maflcko commented at 9:24 AM on September 21, 2023:
    cache_dir = Path(__file__).parent.parent / ".mypy_cache"
    

    fjahr commented at 11:20 AM on September 28, 2023:

    done

  21. maflcko approved
  22. maflcko commented at 9:24 AM on September 21, 2023: member

    lgtm, left a nit

  23. lint: fix custom mypy cache dir setting f9047771d6
  24. fjahr force-pushed on Sep 28, 2023
  25. maflcko commented at 9:01 AM on October 1, 2023: member

    lgtm ACK f9047771d642c5887c752872b6ffbbd974603b35

  26. fanquake merged this on Oct 2, 2023
  27. fanquake closed this on Oct 2, 2023

  28. Frank-GER referenced this in commit aedbf9eeb8 on Oct 5, 2023
  29. bitcoin locked this on Oct 1, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 03:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me