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

os.PathLike support for Directory traits #867

Merged
merged 14 commits into from
Feb 3, 2020

Conversation

shoeb-github
Copy link
Contributor

@shoeb-github shoeb-github commented Jan 31, 2020

contributes to #851

  • The fast validation for Directory trait is done in C only when existence check is not required. Otherwise the validation is done in Python by calling base class validation. I will create separate PR for the C level validation.

@codecov-io
Copy link

codecov-io commented Jan 31, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@a2e7492). Click here to learn what that means.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #867   +/-   ##
=========================================
  Coverage          ?   72.49%           
=========================================
  Files             ?       51           
  Lines             ?     6370           
  Branches          ?     1278           
=========================================
  Hits              ?     4618           
  Misses            ?     1359           
  Partials          ?      393
Impacted Files Coverage Δ
traits/trait_types.py 69.97% <60%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2e7492...d792f66. Read the comment docs.

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Mostly LGTM; a few nitpick-level change requests.

traits/trait_types.py Outdated Show resolved Hide resolved
traits/trait_types.py Outdated Show resolved Hide resolved
@@ -1496,6 +1500,12 @@ def validate(self, object, name, value):

Note: The 'fast validator' version performs this check in C.
"""
if fspath is not None:
Copy link
Member

Choose a reason for hiding this comment

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

It may be worth a comment explaining the need for the if, and indicating that the test can be removed once we drop Python 3.5 support. Alternatively, such a comment could go up at the top of the file, where the fspath import is attempted.

@@ -1516,6 +1526,9 @@ def create_editor(self):
class Directory(BaseDirectory):
""" A fast-validating trait type whose value is a directory path string.

For Python 3.6 and greater, it also accepts objects implementing
the `os.PathLike` interface; converting them to corresponding string.
Copy link
Member

Choose a reason for hiding this comment

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

Grammar nit: replace the semicolon with a comma here (and perhaps remove the first comma in the sentence). Add "the" before "corresponding string".

# Define the C-level fast validator to use if the directory existence
#: test is not required:
if not exists:
self.fast_validate = (ValidateTrait.coerce, str)
super(Directory, self).__init__(
Copy link
Member

Choose a reason for hiding this comment

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

We should probably have a comment indicating that fast validation is disabled. Ideally, also open an issue on the tracker to remind us to decide whether to implement fast validation or not.

with self.assertRaises(TraitError):
foo.path = __file__

@unittest.skipIf(sys.version_info < (3, 6), TESTS_SKIPPED_MESSAGE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: you could reduce repetition and improve readability here by creating a single decorator at the top of the module. For example (untested):

requires_fspath = unittest.skipIf(..., "Test requires os.fspath, which is unavailable before Python 3.6")

shoeb-github and others added 2 commits February 3, 2020 08:55
Co-Authored-By: Mark Dickinson <mdickinson@enthought.com>
@shoeb-github
Copy link
Contributor Author

@mdickinson
Thanks for the review. I made the suggested changes.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

LGTM; two super-nitpicks about reST formatting.

traits/trait_types.py Outdated Show resolved Hide resolved
traits/trait_types.py Outdated Show resolved Hide resolved
shoeb-github and others added 2 commits February 3, 2020 10:09
Co-Authored-By: Mark Dickinson <mdickinson@enthought.com>
Co-Authored-By: Mark Dickinson <mdickinson@enthought.com>
@shoeb-github shoeb-github merged commit 63b138f into master Feb 3, 2020
@mdickinson mdickinson deleted the enh/path-like-support-for-directory-traits branch May 20, 2020 07:50
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.

None yet

4 participants