Repository: andreoliwa/nitpick (language: python)

Issue:
Multiple styles are not cross-platform compatible
Your bug may already be reported!
Please search on the [issue tracker](https://github.com/andreoliwa/nitpick/issues) before creating one.
If you found an issue, write a comment or upvote it with a thumbs-up 👍🏻.

## Expected behavior

With this section in your pyproject.toml:

```
[tool.nitpick]
style = [
  "https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/nitpick-style-wemake.toml",
  "./black-flake8-compat-style.toml",
]
```

## Current behavior

This works on linux, but not on windows

## Steps to reproduce

https://github.com/BPL-Development-Team/poe-client/pull/1/commits/97b675dab1e2710cf839ce5e829cdbd1db8b71ab should be a commit you can reproduce this bug on. 

In general, all you need is a project which has that in your project. You should be able to use that on linux, but if you try to on windows (which is what I'm developing on), it tries to append the toml file name to the URL incorrectly.


## Possible Solution

I believe the problem comes from  this line: https://github.com/andreoliwa/nitpick/blob/4e6736087e5692beef5e2fdf3ef3a2e2150d5a11/src/nitpick/style/core.py#L167

That checks to see if the file is a relative path to a file on disk. If it isn't, it joins the path to the previous URL.

The problem is that it checks to see if the path is a local path by checking if it starts with DOT_SLASH. This is a platform specific check. That means that you can't put a single path in the config, and have it work on both windows and linux.

It might be safe to just check to see if the file URI is valid and points to a real file on disk? I'm not exactly sure.

## Context

I want to reconcile the black formatter with our linting config, which have different line length requirements. This should work, but doesn't on windows.

## Your environment

<!--- Include as many relevant details about the environment you experienced the bug in -->

- `nitpick` version used:
- Python version: 3.9
- Operating System and version: Windows 10
- Link to your project: https://github.com/BPL-Development-Team/poe-client/pull/1/commits/97b675dab1e2710cf839ce5e829cdbd1db8b71ab is a commit
- Run the following commands and paste the output:

  ```shell script
  which python3
  python3 -V
  pip freeze
  cat $(which flake8)
  ```

This doesn't work, I'm on windows. I can get you this information if you want. The project linked above should show versions of these binaries though.



Discussion / hints:
Hey, thanks for the bug report!

`DOT_SLASH` *should* vary according to the operating system:
https://github.com/andreoliwa/nitpick/blob/3c82e8c4d019a5b25e1c0d9db1792f72cf800305/src/nitpick/constants.py#L74-L75

But something is indeed broken on Windows; some tests are marked as `xfail()`, and this is one of them.

I don't have a Windows machine (nor a Windows VM here) but I will try to find out the cause of the problem using GitHub Actions.

> That means that you can't put a single path in the config, and have it work on both windows and linux.

Did you try using a backslash?

```
[tool.nitpick]
style = [
  "https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/nitpick-style-wemake.toml",
  ".\black-flake8-compat-style.toml",
]
```

> It might be safe to just check to see if the file URI is valid and points to a real file on disk? I'm not exactly sure.

I don't remember if the dot (`.\`) means "current dir" in Windows like in Linux, or if means anything at all.
I had to choose a convention to differentiate URLs from local files.

I opted for the dot-slash (`./`).
Maybe using the `file://` protocol can be an option.

I'll try something here, I'll ping you if I have any questions or need some help debugging it on a real Windows machine.

Fix patch:
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 6687fa24..c6763eff 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -238,3 +238,6 @@ Use ``./`` to indicate the local style:
         "https://example.com/on/the/web/remote-style.toml",
         "./my-local-style.toml",
     ]
+
+For Windows users: even though the path separator is a backslash, use the example above as-is.
+The "dot-slash" is a convention for Nitpick_ to know this is a local style file.
diff --git a/src/nitpick/constants.py b/src/nitpick/constants.py
index aceed958..2e9376c6 100644
--- a/src/nitpick/constants.py
+++ b/src/nitpick/constants.py
@@ -1,6 +1,4 @@
 """Constants."""
-import os
-
 import jmespath
 
 PROJECT_OWNER = "andreoliwa"
@@ -61,9 +59,10 @@
 NITPICK_STYLES_INCLUDE_JMEX = jmespath.compile("nitpick.styles.include")
 NITPICK_MINIMUM_VERSION_JMEX = jmespath.compile("nitpick.minimum_version")
 
-#: Dot/slash is used to indicate a local style file
+# Dot/slash is just a convention to indicate a local style file;
+# the same pair of characters should be used on Windows, even though the path separator is different
 DOT = "."
-SLASH = os.path.sep
+SLASH = "/"
 DOT_SLASH = f"{DOT}{SLASH}"
 
 GIT_AT_REFERENCE = "@"


Test patch:
diff --git a/tests/test_style.py b/tests/test_style.py
index e69f319b..36d34124 100644
--- a/tests/test_style.py
+++ b/tests/test_style.py
@@ -420,7 +420,6 @@ def test_relative_style_on_urls(tmp_path):
 
 
 @responses.activate
-@XFAIL_ON_WINDOWS
 def test_local_style_should_override_settings(tmp_path):
     """Don't build relative URLs from local file names (starting with "./")."""
     remote_url = "https://example.com/remote-style.toml"