-
-
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
Open
AlbaHerrerias
wants to merge
22
commits into
conda-forge:main
Choose a base branch
from
neighbourhoodie:nh-pathlib-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refactor: use pathlib #1948
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7e18a8e
refactor(bootstrap obv ci): use pathlib
hulkoba 12b897c
refactor(azur ci utils): use pathlib
hulkoba f7e057a
refactor(ci register): use pathlib
hulkoba 8f43a2a
refactor(ci skeleton): use pathlib
hulkoba d2b239e
refactor(cli): use pathlib
hulkoba 9d352f7
refactor(conf feedstock): use pathlib
hulkoba e6788d3
refactor(feedstock io): use pathlib
hulkoba 7f707b9
refactor(feedstock tokens): use pathlib
hulkoba 3cc7975
refactor(feedstocks): use pathlib
hulkoba 85a4414
refactor(github): use pathlib
hulkoba abe0937
refactor(lint recipe): use pathlib
hulkoba e7d347c
refactor(utils): use pathlib
hulkoba c604e79
refactor(build locally): use pathlib
hulkoba 4f0dca5
refactor(conftest): use pathlib
hulkoba e07e8ce
refactor(test cli): use pathlib
hulkoba 9e329f6
refactor(test conf feedstock): use pathlib
hulkoba ec8d5da
refactor(test feedstock io): use pathlib
hulkoba 356503e
refactor(test feedstock tokens): use pathlib
hulkoba 171ad9e
refactor(test lint recipe): use pathlib
hulkoba 425fed4
refactor(rever): use pathlib
hulkoba ef40b60
add news entry for pathlib refactor
hulkoba 19e578d
fix: resolve linting errors in pathlib refactor
AlbaHerrerias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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) | ||
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 am not sure, isn't
.name
going to give you only the file name (not the whole path as previously)?I think it should be
print("Updating", fname)
.