Skip to content
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

Merged
merged 83 commits into from
Oct 22, 2020
Merged

Feat/typer and mkdocs #47

merged 83 commits into from
Oct 22, 2020

Conversation

mirestrepo
Copy link
Contributor

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

  1. Using the 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
  2. Calling the functions directly. Error reporting is more robust, the annoying thing is that all default arguments must be passed, see running typer cli command from python code fastapi/typer#106

@mirestrepo mirestrepo marked this pull request as draft September 23, 2020 20:21
@mirestrepo mirestrepo marked this pull request as ready for review September 29, 2020 14:31
@mirestrepo
Copy link
Contributor Author

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

Copy link
Contributor

@broarr broarr left a 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.
Copy link
Contributor

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 vs are counted. What do you think?

Copy link
Contributor Author

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

pip install --user commitizen
```

Then use `cz commit` where you would have previously done `git commit`. -->
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love deleting comments ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can delete it!

`-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`
Copy link
Contributor

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


## 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.
Copy link
Contributor

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!

/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
Copy link
Contributor

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'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

datefmt="%Y-%m-%d %H:%M:%S",
handlers=[logging.StreamHandler(sys.stdout)],
setup_logging(
_logger, log_file, verbose=verbose, very_verbose=very_verbose,
Copy link
Contributor

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

elif int(dicomResource["file_count"]) == 0:
return False

return True
Copy link
Contributor

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"
),
Copy link
Contributor

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

Copy link
Contributor Author

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

if logfile == "":
handlers = [logging.StreamHandler(sys.stdout)]
else:
handlers = [logging.FileHandler(logfile), logging.StreamHandler(sys.stdout)]
Copy link
Contributor

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("************************")
Copy link
Contributor

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?

Copy link
Contributor Author

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

@broarr
Copy link
Contributor

broarr commented Sep 30, 2020

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 master now, I just merged my branch. That should clean up this PR a little

@mirestrepo
Copy link
Contributor Author

@broarr I'm done 😅 in case you want to take one more look before merge.

Copy link
Contributor

@broarr broarr left a 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is this user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Bot!

Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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"
Copy link
Contributor

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]
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

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?

Copy link
Contributor

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 = ')
Copy link
Contributor

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"
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's rad!

),
session_suffix: str = typer.Option(
"01",
"-ss",
Copy link
Contributor

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",
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

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

Copy link
Contributor Author

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"
Copy link
Contributor

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

@mirestrepo mirestrepo merged commit 179989c into master Oct 22, 2020
@@ -0,0 +1 @@
Test push commit to the remote in the workflow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted!

Copy link
Contributor Author

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

@mirestrepo mirestrepo mentioned this pull request Oct 27, 2020
@mirestrepo mirestrepo deleted the feat/add-documentation branch November 12, 2020 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants