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

project: Restricting projects from being located in west folder #132

Closed

Conversation

tejlmand
Copy link
Collaborator

Fixes: #102

This commit introduces a list of restricted folders that are compared
against project defined paths to ensure a manifest does not contain
paths ending in the west folder, e.g.:

  • west
  • west/foo
  • foo/../west

while still allowing folders, such as:

  • west-ext
    as project folder.

Signed-off-by: Torsten Rasmussen torsten.rasmussen@nordicsemi.no

path = mp.get('path')
if path is not None:
path = os.path.normpath(path)
for restricted_path in WEST_RESTRICTED_FOLDERS:
Copy link
Member

Choose a reason for hiding this comment

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

Would this be cleaner with a if X in Y construction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because we can't do a simple X in Y here.

west is restricted, but it could be that manifest states west/subfolder and that is also forbidden, and wouldn't be matched in a X in Y.
Thus we loop over WEST_RESTRICTED_FOILDERS to see if there is a match on commonpath between restricted and the path specified for the folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

commonpath now changed to commonprefix to support 3.4, as commonpath is new in python 3.5

Fixes: zephyrproject-rtos#102

This commit introduces a list of restricted folders that are compared
against project defined paths to ensure a manifest does not contain
paths ending in the west folder, e.g.:
- west
- west/foo
- foo/../west

while still allowing folders, such as:
- west-ext
as project folder.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
@tejlmand tejlmand force-pushed the issue_102_west_directory branch from 5c79619 to b57a372 Compare December 3, 2018 13:35
Copy link
Contributor

@mbolivar mbolivar left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to get to this, was traveling all last week

@@ -127,6 +127,29 @@ def test_path():
assert manifest.projects[0].path == 'sub/directory'
assert manifest.projects[0].abspath == os.path.realpath('/west_top/sub/directory')

def test_restricted_path():
# Projects are restricted from west/ folder, but folders containing west as
# part of path name, e.g. west-ext arte still allowed.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: s/arte/are/

@@ -216,6 +219,18 @@ def _load(self, data, sections):
format(name) +
'be used to name a manifest project')

path = mp.get('path')
if path is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

If not given, the implied path is the name of the project. What if I have a project named west/subproject or so? Do we still fail?

If so, would you mind adding some test coverage (another invalid_xxx.yaml should do it) to show that is true?

# Appending os.path.sep to ensure that eg. restricted path 'west/' and
# 'west-ext/' common prefix does not match on the restricted path 'west/'
restricted_path += os.path.sep
if os.path.commonprefix([restricted_path, path + os.path.sep]) is restricted_path:
Copy link
Contributor

Choose a reason for hiding this comment

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

Strings need to be compared with ==, not is.

@carlescufi
Copy link
Member

Does this really apply now @tejlmand ?

@tejlmand
Copy link
Collaborator Author

Does this really apply now @tejlmand ?

Good question.
I assume we would like to restrict people from placing projects in the .west folder.
What do you think ?

Will push an update, if we still consider this relevant.

@carlescufi
Copy link
Member

Sure, we could restrict people from using .west as a name yes, I don't see why not. Better safe than sorry.

@tejlmand tejlmand added the DNM Do not merge label Jan 30, 2019
@mbolivar
Copy link
Contributor

Should we close this for now until we're ready to revisit? We still have the issue open, so we won't forget.

@mbolivar
Copy link
Contributor

Should we close this for now until we're ready to revisit? We still have the issue open, so we won't forget.

@tejlmand ping?

@mbolivar
Copy link
Contributor

I'm going to close this for now so it doesn't keep showing up in the slack channel's pull reminders, as it's the only one that is currently doing that. Please reopen if you'd like.

@mbolivar mbolivar closed this May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DNM Do not merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Projects in the west directory are not forbidden
3 participants