-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix problems with missing setupcfg_examples.txt (#3239)
- Loading branch information
Showing
7 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Included missing test file ``setupcfg_examples.txt`` in ``sdist``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Added script that allows developers to download ``setupcfg_examples.txt`` prior to | ||
running tests. By caching these files it should be possible to run the test suite | ||
offline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
* | ||
!.gitignore | ||
!__init__.py | ||
!preload.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import re | ||
from pathlib import Path | ||
from urllib.request import urlopen | ||
|
||
__all__ = ["DOWNLOAD_DIR", "retrieve_file", "output_file", "urls_from_file"] | ||
|
||
|
||
NAME_REMOVE = ("http://", "https://", "github.com/", "/raw/") | ||
DOWNLOAD_DIR = Path(__file__).parent | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Please update ./preload.py accordingly when modifying this file | ||
# ---------------------------------------------------------------------- | ||
|
||
|
||
def output_file(url: str, download_dir: Path = DOWNLOAD_DIR): | ||
file_name = url.strip() | ||
for part in NAME_REMOVE: | ||
file_name = file_name.replace(part, '').strip().strip('/:').strip() | ||
return Path(download_dir, re.sub(r"[^\-_\.\w\d]+", "_", file_name)) | ||
|
||
|
||
def retrieve_file(url: str, download_dir: Path = DOWNLOAD_DIR): | ||
path = output_file(url, download_dir) | ||
if path.exists(): | ||
print(f"Skipping {url} (already exists: {path})") | ||
else: | ||
download_dir.mkdir(exist_ok=True, parents=True) | ||
print(f"Downloading {url} to {path}") | ||
download(url, path) | ||
return path | ||
|
||
|
||
def urls_from_file(list_file: Path): | ||
"""``list_file`` should be a text file where each line corresponds to a URL to | ||
download. | ||
""" | ||
print(f"file: {list_file}") | ||
content = list_file.read_text(encoding="utf-8") | ||
return [url for url in content.splitlines() if not url.startswith("#")] | ||
|
||
|
||
def download(url: str, dest: Path): | ||
with urlopen(url) as f: | ||
data = f.read() | ||
|
||
with open(dest, "wb") as f: | ||
f.write(data) | ||
|
||
assert Path(dest).exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""This file can be used to preload files needed for testing. | ||
For example you can use:: | ||
cd setuptools/tests/config | ||
python -m downloads.preload setupcfg_examples.txt | ||
to make sure the `setup.cfg` examples are downloaded before starting the tests. | ||
""" | ||
import sys | ||
from pathlib import Path | ||
|
||
from . import retrieve_file, urls_from_file | ||
|
||
|
||
if __name__ == "__main__": | ||
urls = urls_from_file(Path(sys.argv[1])) | ||
list(map(retrieve_file, urls)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters