Skip to content

Conversation

anik120
Copy link
Contributor

@anik120 anik120 commented Apr 17, 2024

Closes #885

Fix: working_dir arg being passed to os.path.join() for glob.glob was of type Repo. Fix is to pass in Repo.working_dir, which is of type str instead.

Also fixes an issue with skip_checkout variable, which was always False. Fix is to use a temp variable sc and set sc to True/False based on skip_checkout

Changes

Which issue is resolved by this Pull Request:
Resolves #

Description of your changes:

@anik120
Copy link
Contributor Author

anik120 commented Apr 17, 2024

@bjhargrave @aartij22 fyi

Closes #885

Fix: `working_dir` arg being passed to `os.path.join()` for
`glob.glob` was of type `Repo`. Fix is to pass in `Repo.working_dir`,
which is of type `str` instead.

Also fixes an issue with `skip_checkout` variable, which was always
`False`. Fix is to use a temp variable `sc` and set `sc` to
`True/False` based on `skip_checkout`

Signed-off-by: Anik Bhattacharjee <anbhatta@redhat.com>
@anik120 anik120 force-pushed the fix-get-documents-bug branch from edb33aa to d3bcafa Compare April 17, 2024 18:44
@@ -206,22 +206,23 @@ def get_documents(
file_patterns = source.get("patterns")
with tempfile.TemporaryDirectory() as temp_dir:
try:
skip_checkout = False
sc = False
Copy link
Contributor

Choose a reason for hiding this comment

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

The sc variable is not necessary. Just get rid of the three lines and pass the skip_checkout argument to git_clone_checkout.

Copy link
Contributor

Choose a reason for hiding this comment

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

git_clone_checkout expects a bool and here skip_checkout can be None. So we would need

if skip_checkout is None:
    skip_checkout = False

to ensure it has a bool value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then you should change the type annotations to require a bool and not allow None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional[T] does not mean optional argument. It is syntactic sugar for Union[T, None].

working_dir = temp_dir
# that needs to be processed instead of the cloned project inside
# temp_dir
working_dir = repo
Copy link
Contributor

Choose a reason for hiding this comment

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

working_dir = repo looks wrong and is very confusing. It only works because the tests are violating type annotation and return str instead of a Repo instance from a mock-patched git_clone_checkout() function.

bjhargrave
bjhargrave previously approved these changes Apr 17, 2024
Copy link
Contributor

@bjhargrave bjhargrave left a comment

Choose a reason for hiding this comment

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

Tested as working!

@tiran
Copy link
Contributor

tiran commented Apr 17, 2024

Please take a look at #893. It solves the problem differently with a proper spec-ed Mock object.

@anik120
Copy link
Contributor Author

anik120 commented Apr 17, 2024

Closing in favor of #893

@anik120 anik120 closed this Apr 17, 2024
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.

Error loading temp directory documents after Git clone for knowledge
3 participants