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

expanduser path, PEP8 #73

Merged
merged 1 commit into from
Jul 3, 2019
Merged

expanduser path, PEP8 #73

merged 1 commit into from
Jul 3, 2019

Conversation

scivision
Copy link
Contributor

@scivision scivision commented Jul 3, 2019

In general we use os.path.expanduser() wherever a user passes in a path to allow ~ to be used. This allows avoiding scenarios where users on laptop vs. HPC have to do the following:

  • Windows laptop: c:\users\joe\data
  • Linux HPC: /home/joe/data

where this PR allows them to simply use ~/data.

Also added Python 2 compatible type hint

Imports should almost always be at top of file, and we try to avoid "from x import y" to avoid namespace clashes. There is no advantage to hiding stdlib imports within functions in particular.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Copy link
Member

@jklenzing jklenzing left a comment

Choose a reason for hiding this comment

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

Thanks @scivision. From looking into PEP484, it looks like the type hint should be employed since path=None is agnostic about the ultimate expected type. Is that right? Or am I missing something else?

@jklenzing jklenzing added this to the 0.2.0 Release milestone Jul 3, 2019
@jklenzing jklenzing added the bug Something isn't working label Jul 3, 2019
@scivision
Copy link
Contributor Author

I employ type hinting at every function declaration, universally in all programs.
Also within the function if necessary or for clarity.
When I do PRs I throw in type hints around the area I'm modifying, to help ensure I'm not breaking something.

I would say more than 10% of the bugs I find are from type hinting, it catches corner cases you wouldn't think of.

@scivision
Copy link
Contributor Author

This page has notes about using type hinting in Python 2. Mypy is one of the most popular type hint checkers
https://mypy.readthedocs.io/en/latest/python2.html

@scivision
Copy link
Contributor Author

I enforce PEP8 and type hints such that I cannot git commit until those pass (I can manually override, for example when working on someone else's project).

https://www.scivision.dev/git-commit-precheck-pep8/

A git pre-commit hook, itself written in Python https://github.com/scivision/gitMC/blob/master/pre-commit.py

@jklenzing jklenzing merged commit bd333dd into sami2py:develop Jul 3, 2019
@scivision scivision deleted the expand branch July 5, 2019 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants