Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amin authored and Amin committed Jan 22, 2024
1 parent 98ffdea commit 2494bfe
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
- name: Run mypy
run: |
mypy {{ cookiecutter.project_name }} --install-types --non-interactive
mypy {{ cookiecutter.project_name }} --install-types --non-interactive
4 changes: 2 additions & 2 deletions {{ cookiecutter.repo_name }}/.github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
run: |
coverage report -m
coverage html
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: ./htmlcov
path: ./htmlcov
2 changes: 1 addition & 1 deletion {{ cookiecutter.repo_name }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-added-large-files
2 changes: 1 addition & 1 deletion {{ cookiecutter.repo_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ else
printf "\n"; \
}' \
| more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')
endif
endif
2 changes: 1 addition & 1 deletion {{ cookiecutter.repo_name }}/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tensorflow
wandb
hydra-core
hydra-core
4 changes: 2 additions & 2 deletions {{ cookiecutter.repo_name }}/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pre-commit
pre-commit >= 3.5.0

{% if cookiecutter.with_docs == 'y' %}# docs
{% if cookiecutter.with_docs == 'y' %}
# docs
mkdocs <= 1.5.3
mkdocs-material <= 9.4.6
mkdocstrings <= 0.23.0
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.repo_name }}/tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def test_pass():
assert 1 == 1
assert 1 == 1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _run_git_command(*args):


def commit_experiment():
"""Tries to find a commit with the same repository state, if unsuccessful, creates a new branch
"""Tries to find a commit with the same repository state, if unsuccessful, creates a new branch
and commits the current state of the repository there.
Returns:
Expand All @@ -31,7 +31,7 @@ def commit_experiment():
# BUG: When adding a new file or renaming a file (which might be considered as deleting the old file and creating a new one),
# the diff command will return a non-empty string, even if the file is the same. This will cause the code to create a new branch
# and commit the changes there, even though the changes are not real

time_tag = int(time.time()*1000)
stash_name = "stash_{}".format(time_tag)
new_branch = "checkpoint/branch_{}".format(time_tag)
Expand All @@ -42,7 +42,7 @@ def commit_experiment():
exp_commit_message = _run_git_command('log', '-1', '--pretty="%s"')
exp_commit_hash = _run_git_command('log', '-1', '--pretty="%H"')
return exp_commit_message, exp_commit_hash

branches = _run_git_command('branch', '--contains', 'HEAD').split('\n')
branches = [x for x in branches if '*' not in x]
branches = [x.strip() for x in branches]
Expand All @@ -52,7 +52,7 @@ def commit_experiment():
exp_commit_message = _run_git_command('log', '-1', '--pretty="%s"', branch)
exp_commit_hash = _run_git_command('log', '-1', '--pretty="%H"', branch)
return exp_commit_message, exp_commit_hash

# 3.1. Stash all changes
_run_git_command('stash', 'push', '--include-untracked', '-m', stash_name)

Expand All @@ -72,10 +72,10 @@ def commit_experiment():
# 3.4. Go back to the initial branch and pop the stash there
_run_git_command('checkout', initial_branch)
_run_git_command('stash', 'pop')

return exp_commit_message, exp_commit_hash

if __name__ == '__main__':
commit_message, commit_hash = commit_experiment()
print("Commit message: ", commit_message)
print("Commit hash: ", commit_hash)
print("Commit hash: ", commit_hash)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# training parameters
learning_rate: 0.001
epochs: 10
batch_size: 32
batch_size: 32
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ def get_data():


if __name__ == '__main__':
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def get_logger(name, level=DEFAULT_LOG_LEVEL, log_path=None, use_rich=False):
level (str): Level of the logger. One of "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL".
log_path (str): Path to the log file. If None, no log file is created.
use_rich (bool): Whether to use rich to beautify the log.
Returns:
logging.Logger: Logger.
Examples:
>>> logger = get_logger(__name__, level="DEBUG", log_path="logs/latest.log", use_rich=False)
>>> logger.debug("Used for debugging your code.")
Expand Down Expand Up @@ -59,7 +59,7 @@ def get_logger(name, level=DEFAULT_LOG_LEVEL, log_path=None, use_rich=False):
"stream": "ext://sys.stdout"
}
config["root"]["handlers"].append("console")

if log_path:
os.makedirs(os.path.dirname(log_path), exist_ok=True)
config["handlers"]["file"] = {
Expand All @@ -73,5 +73,5 @@ def get_logger(name, level=DEFAULT_LOG_LEVEL, log_path=None, use_rich=False):

logging.config.dictConfig(config)
logger = logging.getLogger(name)
return logger

return logger
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def get_model() -> tf.keras.Model:

if __name__ == '__main__':
model = get_model()
model.summary()
model.summary()
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
def main(cfg):
# initializing
time_tag = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")

exp_commit_message, exp_commit_hash = commit_experiment()

logger = get_logger(__name__)

wandb_name = datetime.datetime.strptime(time_tag, "%Y-%m-%d_%H-%M-%S").strftime("%Y-%m-%d %H:%M:%S")
# USER: change this line respecting your application
wandb.init(entity=..., project="{{ cookiecutter.project_name }}", name=wandb_name)
Expand All @@ -51,7 +51,7 @@ def main(cfg):

opt = tf.keras.optimizers.Adam(learning_rate=cfg.learning_rate)
model.compile(optimizer=opt, loss=..., metrics=...) # USER: change this line respecting your application

best_model_path = "models/{time}/model_best.keras".format(time=time_tag)
best_model_callback = tf.keras.callbacks.ModelCheckpoint(best_model_path, save_best_only=True, verbose=0)
wandb_callback = WandbCallback(save_model=False, ) # USER: change this line respecting your application
Expand Down Expand Up @@ -87,4 +87,4 @@ def main(cfg):


if __name__ == "__main__":
main()
main()

0 comments on commit 2494bfe

Please sign in to comment.