Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pathlib #149

Merged
merged 3 commits into from
May 10, 2023
Merged

Use Pathlib #149

merged 3 commits into from
May 10, 2023

Conversation

catherinedevlin
Copy link

@catherinedevlin catherinedevlin commented Apr 24, 2023

Pathlib is a new(-ish) standard library module (introduced 3.4) that provides a cleaner and more reliable way to handle file paths than the old os.path methods. They bake in OS-safety, adapting to Windows back-slashes and Unix forward-slashes seamlessly. Switching to Pathlib cleans up the code a little and avoids possible Windows problems.

We also corrected some logic in the checking the hash of downloaded files in setup.py.

setup.py Outdated
@@ -56,10 +56,6 @@ def _hash(filepath):
out_name = url.split("/")[-1]
dst_path = external_dir_single / out_name
if dst_path.is_file():
# TODO: boyu: Please review removal of this
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wang-boyu: We're suggesting removing this "if/else" because the code ends up doing the same thing no matter how the evaluation turns out. A

# Used for downloading e.g. Leaflet single file
if out_name is None:
out_name = url.split("/")[-1]
dst_path = os.path.join(external_dir_single, out_name)
if os.path.isfile(dst_path):
if integrity_hash and (_hash(dst_path) == integrity_hash):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wang-boyu : This if/else block doesn't appear to have any function, so we're suggesting removing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out! This looks like a bug introduced via #61. It was meant to compare the hash with existing file if there's any, and avoids downloading if the hashes match.

Instead of removing it, I would suggest to fix the issue. Perhaps we could delete the return after else statement, and indent some of the code below into else?

setup.py Outdated

if dst_path.is_file():
return
if integrity_hash and (_hash(str(dst_path)) != integrity_hash):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wang-boyu Thank you! We think this is the logic you're looking for (note that we changed == to !=); the setup should stop if the hash is provided and does not match.

@wang-boyu
Copy link
Member

I tried to install directly from the use-pathlib branch in your forked repo, with the following command in a clean virtual environment:

pip install git+https://github.com/catherinedevlin/mesa-geo.git@use-pathlib

Then there would be the following error:

Building wheels for collected packages: Mesa-Geo
  Building wheel for Mesa-Geo (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for Mesa-Geo (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_py
      Downloading the leaflet.js dependency from the internet...
      error: [Errno 2] No such file or directory: 'mesa_geo/visualization/templates/css/external'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for Mesa-Geo
Failed to build Mesa-Geo
ERROR: Could not build wheels for Mesa-Geo, which is required to install pyproject.toml-based projects

So it appears that some external dependencies directories were not successfully created. But if I check out this PR and run pip install -e ".[dev]" then it works. Not sure why this is happening.

@jackiekazil
Copy link
Member

Builds seem to be failing in same way.

@catherinedevlin
Copy link
Author

@wang-boyu Thank you for the catch - it doesn't happen with plain "pip install -e ." But it seems like creating the parents fixes it.

@wang-boyu wang-boyu added this to the v0.6.0 milestone Apr 27, 2023
@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (c41d1ae) 80.36% compared to head (ebba036) 80.36%.

❗ Current head ebba036 differs from pull request most recent head 906beea. Consider uploading reports for the commit 906beea to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   80.36%   80.36%           
=======================================
  Files          10       10           
  Lines         657      657           
  Branches      136      136           
=======================================
  Hits          528      528           
  Misses        114      114           
  Partials       15       15           
Impacted Files Coverage Δ
mesa_geo/visualization/modules/MapVisualization.py 91.66% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@wang-boyu
Copy link
Member

Thanks for the fix! It is now working as expected. Two last things from my side:

  1. CI is failing due to unsorted import in a file: https://github.com/projectmesa/mesa-geo/actions/runs/4803403604/jobs/8590648770?pr=149
  2. You probably would need to squash all commits into one or two smaller commits

@rht is there any other changes you would like to make?

@wang-boyu
Copy link
Member

Fixed isort error and squashed commits. Merging now.

@wang-boyu wang-boyu merged commit ec235f8 into projectmesa:main May 10, 2023
@rht
Copy link
Contributor

rht commented May 11, 2023

I missed the emails, but yeah LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants