Skip to content

Commit 0179655

Browse files
committed
Fix Readme creation
1 parent 160e911 commit 0179655

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Some functions, like downloading public datasets, will operate without API token
5454
- Under "Repository permissions", enable:
5555
- [x] **Actions** (Read and write)
5656
- Needed for triggering workflow dispatches
57+
- [x] **Contents** (Read)
58+
- Needed to download the README template
5759
- [x] **Issues** (Read)
5860
- Needed for checking existing tickets, to make sure we don't create duplicates
5961

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sphinx-autoapi
2-
jinja2>=3.0
2+
jinja2>=3.0
3+
importlib_resources; python_version < '3.9'

dvcurator/gui.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def create_readme(self):
350350

351351
self.disable_buttons()
352352
t = threading.Thread(target=dvcurator.readme.generate_readme,
353-
args=(self.metadata, os.path.join(self.subfolder_path, "QDR Prepared"), self.dv_token.get(), self.curation_repo.get()))
353+
args=(self.metadata, os.path.join(self.subfolder_path, "QDR Prepared"), self.dv_token.get(), self.gh_token.get(), self.curation_repo.get()))
354354
t.start()
355355
self.schedule_check(t)
356356

@@ -473,8 +473,16 @@ def __init__(self, parent, *args, **kwargs):
473473
parent.iconbitmap(bitmap=icon)
474474
else:
475475
self.local_ini = os.path.join(os.getcwd(), "dvcurator.ini")
476-
from pkg_resources import resource_filename
477-
icon = resource_filename("dvcurator", "assets/qdr.ico")
476+
try:
477+
# Modern approach using importlib.resources
478+
from importlib import resources
479+
with resources.path("dvcurator", "assets") as assets_path:
480+
icon = str(assets_path / "qdr.ico")
481+
except ImportError:
482+
# Fallback for Python < 3.9
483+
from importlib_resources import files
484+
icon = str(files("dvcurator") / "assets" / "qdr.ico")
485+
parent.iconbitmap(bitmap=icon)
478486

479487
if os.path.exists(self.local_ini):
480488
self.load_config(self.local_ini)

dvcurator/readme.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ def clean_html_tags(text):
1313
clean_text = re.sub(tags, '', text)
1414
return clean_text
1515

16-
def generate_readme(metadata, folder, token=None, repo=None):
16+
def generate_readme(metadata, folder, token=None, key=None, repo=None):
1717
"""
1818
Generate README.txt file.
1919
20-
This function uses the template assets/README.txt
20+
This function uses the file README_template.txt in the repository root.
2121
2222
:param metadata: Project metadata from `get_metadata()`
2323
:type metadata: list
2424
:param folder: Path to QDR Prepared folder for project
2525
:type folder: String
2626
:param token: Dataverse token (required if the project is unpublished)
2727
:type token: string
28+
:param key: Github API key, or None for public repository
29+
:type key: String or None
30+
:param repo: Repository to use for the README template, defaults to dvcurator.hosts.curation_repo
31+
:type repo: String or None
2832
2933
:return: Path to newly generated README file
3034
:rtype: string
@@ -78,14 +82,22 @@ def generate_readme(metadata, folder, token=None, repo=None):
7882
'files': dvcurator.fs.recursive_scan(folder) #"\n".join(os.listdir(folder))
7983
}
8084

81-
# the location of the template differs if this is a compiled pyinstaller file or run directly
82-
85+
8386
## Download readme template from github
87+
88+
8489
host = "https://raw.githubusercontent.com/"
8590
repo = dvcurator.hosts.curation_repo if not repo else repo
8691
readme_url = host + repo + "/refs/heads/master/README_template.txt"
8792

88-
response = requests.get(readme_url)
93+
if (not key):
94+
print("No github token set -- this will fail on private repo")
95+
response = requests.get(readme_url)
96+
else:
97+
print("Trying to download README template from private repository...")
98+
key = {'Authorization': "token " + key.strip()}
99+
response = requests.get(readme_url, headers=key)
100+
89101
response.raise_for_status()
90102
readme_template = response.text
91103
print("Downloaded README template...")

0 commit comments

Comments
 (0)