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

Added tests for #556. #783

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Added tests for #556. #783

wants to merge 1 commit into from

Conversation

dzhuang
Copy link
Contributor

@dzhuang dzhuang commented Mar 25, 2021

Testing #556 as mentioned in #767. The tests works without problems. The merge of this PR requires dzhuang/relate-sample@f43b734 being merged into sample repo.

P.S., We should mention in docs that path split should always use /.

@inducer

@@ -69,7 +69,7 @@
"hidden": False,
"listed": True,
"accepts_enrollment": True,
"git_source": "git://github.com/inducer/relate-sample",
"git_source": "git://github.com/dzhuang/relate-sample",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This need to be reverted when merging.

@dzhuang dzhuang requested a review from inducer March 26, 2021 00:25
@inducer
Copy link
Owner

inducer commented Mar 29, 2021

Thanks for doing this! I really don't understand why this works though. I tried whether dulwich does path parsing:

from dulwich.repo import Repo
r = Repo(".")
c = r[b"HEAD"]
t = r[c.tree]
f = t[b"pytools/__init__.py"]
print(f)

(run in a checkout of https://github.com/inducer/pytools/, because why not) It does not.

So if this code:

relate/course/content.py

Lines 651 to 653 in f4e8dee

# https://github.com/inducer/relate/pull/556
# FIXME: https://github.com/inducer/relate/issues/767
name_parts = os.path.normpath(full_name).split(os.sep)

splits the path by os.sep (which i assume is \ in Windows, right?), how does it feed the right file names to dulwich? (I don't have a Windows system to check, otherwise I would)

@dzhuang
Copy link
Contributor Author

dzhuang commented Mar 29, 2021

OIC. I finally remembered the reason for proposing #556.

The .attribute file won't be parsed correctly in Windows. e.g., the file images/.attributes.yml will be images\.attributes.yml in Windows.

Now I can see this line (os.path.join)lead to that result:

attributes_path = os.path.join(os.path.dirname(path), ATTRIBUTES_FILENAME)

I didn't realized that when I try to fix this issue, and in #556 the workround went to a wrong direction. Although it actually fixed it, I must admit it's bad and sorry for causing your confusion.

So the better workround is to use "/".join([os.path.dirname(path), ATTRIBUTES_FILENAME]), am I right?

See something interesting in #784

@dzhuang
Copy link
Contributor Author

dzhuang commented Mar 30, 2021

FYI, os.path.normpath

>>> os.path.normpath("repo/root/sub")
'repo\\root\\sub'
>>> os.path.normpath(r"repo/root/sub\.attribute") 
'repo\\root\\sub\\.attribute'

normpath will replace all \ and / to os.sep, and then we can use os.sep to split the path to elements.

@inducer
Copy link
Owner

inducer commented Apr 8, 2021

I propose that we standardize on / as a path separator in course content. I'm not a fan of allowing both (as we would if we used normpath). I agree that using os.path.join to construct repo paths (in the spot you found, but there are a few more) is incorrect, we should fix those instances.

How do you feel about this direction?

@dzhuang
Copy link
Contributor Author

dzhuang commented Apr 9, 2021

I agree. But my first attempt failed (see #784). Maybe there're more os.path.join need to be changed as you mentioned.

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.

2 participants