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

codelists add command #294

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

codelists add command #294

wants to merge 2 commits into from

Conversation

Jongmassey
Copy link
Contributor

@Jongmassey Jongmassey commented Nov 28, 2024

Allow users to add OpenCodelists codelists to the codelists.txt file by URL.

Fixes #295

@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch 2 times, most recently from 5250f18 to d67b09f Compare November 28, 2024 15:30
@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch 2 times, most recently from b9e2d56 to e421132 Compare January 16, 2025 10:48
opensafely/codelists.py Outdated Show resolved Hide resolved
@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch from 9bba87e to 3f29fdb Compare January 18, 2025 13:15
Copy link
Contributor

@lucyb lucyb left a comment

Choose a reason for hiding this comment

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

Sorry, I haven't quite finished the review, but I thought some feedback was better than none.

It's looking much better, I can even see what the update function is doing! Thanks for making that bit of refactoring. I think it's nearly done now.

tests/test_codelists.py Outdated Show resolved Hide resolved
opensafely/codelists.py Outdated Show resolved Hide resolved
tests/test_codelists.py Outdated Show resolved Hide resolved
opensafely/codelists.py Outdated Show resolved Hide resolved
opensafely/codelists.py Outdated Show resolved Hide resolved
@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch from 3f29fdb to 013f1e3 Compare January 27, 2025 22:56
Allow users to add OpenCodelists codelists to the
codelists.txt file by URL, allowing for common
variations from the "base" URL
@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch from 013f1e3 to d73fe6f Compare January 27, 2025 23:03
A lot of the logic of `update` is needed by `add`:
* codelist file parsing (indirectly)
* file downloading
* manifest handling

This commit pulls out those needed parts into
their own functions, and pulls out
parse_codelist_file's line-parsing logic into its
own function.

This allows us to check the line we're about to
add to the codelists file is valid before doing
so, check that once we add the line to the
codelists file that it is valid, leave
pre-existing codelists and their corresponding
manifest file entries intact.
@Jongmassey Jongmassey force-pushed the Jongmassey/codelists-add branch from d73fe6f to ce85bfa Compare January 27, 2025 23:06
Copy link
Contributor

@lucyb lucyb left a comment

Choose a reason for hiding this comment

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

Kent Beck is famous for saying "First make the change easy, then make the easy change". I think you may have done it the other way around, but it's definitely looking good. Thank you for responding to the various pieces of feedback.

I'm approving this because the changes I've suggested are very minor, but please be aware that I haven't run the cli tool locally to test the change. If you'd like me to do that, please can you tell me how to do that, because I can't find the docs.

Also, I believe we use semantic commits on this repo (i.e feat:), so you'll want to rename the commits before merging to release a new version.

if OPENCODELISTS_BASE_URL not in codelist_url:
exit_with_error(f"Unable to parse URL, {OPENCODELISTS_BASE_URL} not found")

if not codelists_dir:
Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you whether you change this, but I notice that there's a get_codelists_dir function later on in the file that you could make use of here.

codelists_path /= "codelists"
codelists_file = codelists_path / "codelists.txt"
prior_codelists = codelists_file.read_text()
for codelist in prior_codelists.split("\n"):
Copy link
Contributor

Choose a reason for hiding this comment

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

This for-loop and call the requests_mock is no longer needed.

codelists_path /= "codelists"
codelists_file = codelists_path / "codelists.txt"
prior_codelists = codelists_file.read_text()
for codelist in prior_codelists.split("\n"):
Copy link
Contributor

Choose a reason for hiding this comment

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

This for-loop and call the requests_mock is no longer needed.

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.

UX for adding codelists to a project is poor
2 participants