-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
refactor: use pathlib #1948
base: main
Are you sure you want to change the base?
refactor: use pathlib #1948
Changes from 8 commits
7e18a8e
12b897c
f7e057a
8f43a2a
d2b239e
9d352f7
e6788d3
7f707b9
3cc7975
85a4414
abe0937
e7d347c
c604e79
4f0dca5
e07e8ce
9e329f6
ec8d5da
356503e
171ad9e
425fed4
ef40b60
19e578d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import os | ||
from pathlib import Path | ||
import typing | ||
import warnings | ||
|
||
|
@@ -41,7 +42,7 @@ def __init__( | |
|
||
try: | ||
with open( | ||
os.path.expanduser("~/.conda-smithy/azure.token"), "r" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
Path("~/.conda-smithy/azure.token").expanduser(), "r" | ||
) as fh: | ||
self.token = fh.read().strip() | ||
if not self.token: | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,21 +6,20 @@ | |||||
added to conda-forge's queue. | ||||||
""" | ||||||
|
||||||
import os | ||||||
from pathlib import Path | ||||||
import sys | ||||||
|
||||||
from .configure_feedstock import make_jinja_env | ||||||
|
||||||
|
||||||
def _render_template(template_file, env, forge_dir, config): | ||||||
"""Renders the template""" | ||||||
template = env.get_template( | ||||||
os.path.basename(template_file) + ".ci-skel.tmpl" | ||||||
) | ||||||
target_fname = os.path.join(forge_dir, template_file) | ||||||
print("Generating " + target_fname, file=sys.stderr) | ||||||
template_file_name = Path(template_file).name | ||||||
template = env.get_template(template_file_name + ".ci-skel.tmpl") | ||||||
target_fname = Path(forge_dir, template_file) | ||||||
print("Generating ", target_fname, file=sys.stderr) | ||||||
new_file_contents = template.render(**config) | ||||||
os.makedirs(os.path.dirname(target_fname), exist_ok=True) | ||||||
target_fname.parent.mkdir(parents=True, exist_ok=True) | ||||||
with open(target_fname, "w") as fh: | ||||||
fh.write(new_file_contents) | ||||||
|
||||||
|
@@ -37,18 +36,16 @@ def _insert_into_gitignore( | |||||
): | ||||||
"""Places gitignore contents into gitignore.""" | ||||||
# get current contents | ||||||
fname = os.path.join(feedstock_directory, ".gitignore") | ||||||
print("Updating " + fname) | ||||||
if os.path.isfile(fname): | ||||||
fname = Path(feedstock_directory, ".gitignore") | ||||||
print("Updating ", fname.name) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, isn't I think it should be |
||||||
if fname.is_file(): | ||||||
with open(fname, "r") as f: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be written as |
||||||
s = f.read() | ||||||
before, _, s = s.partition(prefix) | ||||||
_, _, after = s.partition(suffix) | ||||||
else: | ||||||
before = after = "" | ||||||
dname = os.path.dirname(fname) | ||||||
if dname: | ||||||
os.makedirs(dname, exist_ok=True) | ||||||
fname.parent.mkdir(parents=True, exist_ok=True) | ||||||
new = prefix + GITIGNORE_ADDITIONAL + suffix | ||||||
# write out the file | ||||||
with open(fname, "w") as f: | ||||||
|
@@ -60,7 +57,7 @@ def generate( | |||||
package_name="pkg", feedstock_directory=".", recipe_directory="recipe" | ||||||
): | ||||||
"""Generates the CI skeleton.""" | ||||||
forge_dir = os.path.abspath(feedstock_directory) | ||||||
forge_dir = Path(feedstock_directory).resolve() | ||||||
env = make_jinja_env(forge_dir) | ||||||
config = dict( | ||||||
package_name=package_name, | ||||||
|
@@ -69,8 +66,7 @@ def generate( | |||||
) | ||||||
# render templates | ||||||
_render_template("conda-forge.yml", env, forge_dir, config) | ||||||
_render_template( | ||||||
os.path.join(recipe_directory, "meta.yaml"), env, forge_dir, config | ||||||
) | ||||||
recipe_file_name = str(Path(recipe_directory, "meta.yaml")) | ||||||
_render_template(recipe_file_name, env, forge_dir, config) | ||||||
# update files which may exist with other content | ||||||
_insert_into_gitignore(feedstock_directory=feedstock_directory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we are using several
Path
instantiations here when it's alltarget_dir
. We should have something like:and so on. I'm afraid this happens in more areas of the PR, so a careful review is advised imo.