-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat/typer and mkdocs #47
Conversation
This is ready for review. The only puzzle left is that I'd like to make the versions both for the documentation and the package somehow automated with the next release.... but I'm not sure how to do that yet... if you have hints. Let me know |
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.
That was a long PR! I think everything looks good, I just had a couple of little comments. I don't think anything needs to be changed, but I think there are some ways we can better follow UNIX cli conventions
* `--vv`: Very verbose logging. If True, sets loglevel to DEBUG [default: False] | ||
* `--install-completion`: Install completion for the current shell. | ||
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation. | ||
* `--help`: Show this message and exit. |
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.
Some of these command line options are very non-standard. -ss
and --vv
in particular. In UNIX like environments -ss
is generally equivalent to -s -s
and verbose logging is done with -vv
(again equivalent to -v -v
). I'd suggest -ss
gets changed to -S
and --vv
gets changed to -vv
where the number of v
s are counted. What do you think?
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.
Of those options the only ones that are defined by us is --vv
. The other one are added by typer (I think common to all typer apps). I thought I had -vv
initially but it didn't handled for that. I''ll try again, I may not understand how to make that happen in the typer.Option
type
docs/code_standards.md
Outdated
pip install --user commitizen | ||
``` | ||
|
||
Then use `cz commit` where you would have previously done `git commit`. --> |
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.
Any reason why this is commented out?
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 love deleting comments ;-)
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 can delete it!
docs/code_standards.md
Outdated
`-o log_cli=true --log-cli-level=INFO` allows the logger output to go to cli | ||
`-x` exists on first failure | ||
|
||
You will need to have a local `.env` file where you set some environment variables, e.i `XNAT_PASS` |
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.
e.i
should be i.e.
I think
docs/code_standards.md
Outdated
|
||
## Documentation | ||
|
||
All functions and methods should have an up to date [google style docstring](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). These docstrings are used to build xnat-tools's documentation website. Additional prose can be added to the website by editing the appropriate markdown file in the `docs/` 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 wasn't aware of google style docstrings! Neat!
docs/dev_setup.md
Outdated
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | ||
``` | ||
|
||
[Chocolatey](https://chocolatey.org) is a popular package manager for Windows |
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.
To install, run the following from a priviledged powershell prompt:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
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.
😅
xnat_tools/bids_postprocess.py
Outdated
datefmt="%Y-%m-%d %H:%M:%S", | ||
handlers=[logging.StreamHandler(sys.stdout)], | ||
setup_logging( | ||
_logger, log_file, verbose=verbose, very_verbose=very_verbose, |
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.
using the count scheme, if verbose
is set to 3
we can send that integer into the setup_logging
function instead of these two arguments. Then we pick log level based on the integer passed
xnat_tools/bids_utils.py
Outdated
elif int(dicomResource["file_count"]) == 0: | ||
return False | ||
|
||
return True |
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.
It's funny that this stuff is appearing as new
), | ||
bids_root_dir: str = typer.Argument( | ||
..., help="Root output directory for exporting the files" | ||
), |
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.
Is there no way to reuse these arguments via typer
? Seems kinda wasteful to have them repeated 3 times throughout xnat-tools
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'll take a look
xnat_tools/logging.py
Outdated
if logfile == "": | ||
handlers = [logging.StreamHandler(sys.stdout)] | ||
else: | ||
handlers = [logging.FileHandler(logfile), logging.StreamHandler(sys.stdout)] |
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.
Nit: Since logging.StreamHandler(sys.stdout)
is always a part of handlers
I'd set that up front and optionally add the logfile. Something like:
handlers = [logging.StreamHandler(sys.stdout)]
if logfile:
handlers.append(logging.FileHandler(logfile))
Just a nitpick though, it's obviously fine this way too :-)
overwrite = args.overwrite | ||
Run Heudiconv | ||
""" | ||
print("************************") |
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.
Why is this print not a log statement?
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.
You have asked this in few PRs 🤣 .... For heudiconv I didn't figure out a way to intercept their logs correctly, so there is no logging set up in that executable. You started another branch to fix this issue, but that became stale. We'll have to revisit
I see what happened with all the new stuff that was mine. I didn't merge my PR and you started this branch off of my PR. I think you can rebase against |
…/xnat_tools into feat/add-documentation
…/xnat_tools into feat/add-documentation
…/xnat_tools into feat/add-documentation
@broarr I'm done 😅 in case you want to take one more look before merge. |
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.
Smaller PRs, please!
If we're changing the CLI option from seqlist
to includeseq
I think we should rename that argument everywhere for consistency. I'd still love to see those command-line options for typer loaded once, instead of in 4 different places. I think this code could def be a little DRYer
echo "Test push commit to the remote in the workflow" >> test.txt | ||
|
||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
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.
Who is this user?
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.
GitHub Bot!
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.
Did you make the bot?
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.
No, that's their bot.... it's documented in their forums. If you look at the commits from the actions, it shows the octocat as the user
typer xnat_tools/xnat2bids.py utils docs --name xnat2bids --output docs/xnat2bids.md | ||
typer xnat_tools/dicom_export.py utils docs --name xnat-dicom-export --output docs/dicom_export.md | ||
typer xnat_tools/run_heudiconv.py utils docs --name xnat-heudiconv --output docs/run_heudiconv.md | ||
typer xnat_tools/bids_postprocess.py utils docs --name bids-postprocess --output docs/bids_postprocess.md |
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.
This generates logs for the cli scripts?
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.
it generates markdown docs
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
||
git add -A | ||
git commit -m "docs: Update CLI and CHANGELOG.md" |
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.
Fun fact, if you have two -m
flags it'll use the first as the title and the second as the body of your commit message!
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/[email protected] |
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.
This links to the .pre-commit.yaml
file below?
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.
yes
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.
Maybe we make CCV template repository at a later date?
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.
For precommit templates per language
pip install mkdocs mkdocs-material mkdocstrings mkdocs-versioning | ||
- name: Set up mkdocs config | ||
run: | | ||
export VERSION=$(cat pyproject.toml | grep version | head -1 | awk -F: '{ print $1 }'| sed 's/[\",]//g'| tr -d 'version = ') |
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.
Nice one-liner!
@@ -1 +1 @@ | |||
__version__ = "0.1.3" | |||
__version__ = "0.1.7" |
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.
Looks like we're duplicating this value in the pyproject.toml
file. Can we load the pyproject.toml
version here so there's one source of truth?
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.
Or maybe this is automatically updated?
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.
Commitizen will update them in both places.
There are ways to load the version from the pyproject.toml
but then it breaks other things (which I forget which one... maybe Commitizen it self)
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.
That's rad!
xnat_tools/bids_postprocess.py
Outdated
), | ||
session_suffix: str = typer.Option( | ||
"01", | ||
"-ss", |
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.
No thoughts here?
), | ||
session_suffix: str = typer.Option( | ||
"01", | ||
"-S", |
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.
Ahh, I see you've changed -S
from -ss
here. Looks like there's at least one other script that needs the same change. That's why I was asking about a way to make all commands take the same arguments instead of copying and pasting them into new commands
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 totally agree with your point. I didn't see a straight forward way... we could discuss other possibilities
scans = get_scan_ids(connection, host, session) | ||
scans = filter_scans(scans, seqlist=seqlist, skiplist=skiplist) | ||
scans = filter_scans(scans, seqlist=includeseq, skiplist=skipseq) |
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.
Why the name change in includeseq
? I personally prefer the consistency especially if we're passing the list around
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 think I did it so that the i
CLI option was more consistent with the name, and then I was lazy to change the actual variable all around. Consistency is good!
@@ -217,19 +147,12 @@ def main(args): | |||
export_session_dir, | |||
) | |||
|
|||
# Close connection(I don't think this works) | |||
connection.delete(f"{host}/data/JSESSION") |
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.
This does not work. By calling connection.delete
you're actually creating a new session to delete the old session
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.
Okay, I'll remove the line
hooks: | ||
- id: flake8 | ||
args: | ||
- "--max-line-length=89" |
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.
Might not be reading the parameters from the pyproject.toml
@@ -0,0 +1 @@ | |||
Test push commit to the remote in the workflow |
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.
This can be deleted!
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.
Interesting! I deleted the file see 9748d65
So I think I must have something on CI
I'm sorry I disn't separate the documentation from the CLI changes. Once I though about it, it was too late 🤪, so this is probably a hard one to review because there are too many changes.
The cli tests can be run in two different ways , both have pros/cons
type.CLIRunner
the cons of this is that the error reporting is not as good. For instance if bad options are passed.... tests fail but quietly