grimen / python-rootpath

Python project/package root path detection.
https://pypi.org/project/rootpath
MIT License
23 stars 14 forks source link

Documentation: Add `examples` folder/script with usage example #3

Open grimen opened 5 years ago

jfavrod commented 4 years ago

From the README:

It does this by detecting typical package/project root files/folders (e.g. .git, requirements.txt, etc.), but it can also be overriden easily if needed.

It would be nice to see an example of how to override the detection pattern.

In a docker container rootpath.detect() returns None. I copied in my Pipfile, and I've tried rootpath.detect(pattern='Pipfile') - as well as with regular expression args - and I'm still getting None.

jfavrod commented 4 years ago

I think my efforts may be confounded by the fact that I'm running in a Python virtual environment.

grimen commented 4 years ago

@jfavrod Would you be able to share example code I could run locally to reproduce? I use this library in Python Virtual Environment successfully, but it is possible there are edge cases I have not stumbled onto.

jfavrod commented 4 years ago

I set up a simplified example...

$ tree .
├── Dockerfile
├── Pipfile
├── Pipfile.lock
└── src
    └── index.py

1 directory, 4 files

Here's the contents of the Dockerfile:

$ cat Dockerfile
FROM python:3.7
RUN mkdir -p /app/src
WORKDIR /app
RUN pip install pipenv
COPY Pipfile /app/Pipfile
COPY Pipfile.lock /app/Pipfile.lock
RUN pipenv install
CMD ["pipenv", "run", "python", "src/index.py"]

Also the contents of the Pipfile:

$cat Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
rootpath = "*"

[requires]
python_version = "3.7"

And finally the index.py file:

$ cat src/index.py
import rootpath

print(rootpath.detect())

When I run the container, here's the output:

$ docker container run -v ${PWD}/src:/app/src --rm agsync-api-py
None
jfavrod commented 4 years ago

I just tried from the above, and it works. I tried to make the example more like the situation where I was experiencing the problem, but it still works.

rootpath.detect(pattern='Pipfile')

I just found out the code I was working on is no longer maintained, so I won't be contributing to it (or working on this issue anymore). I do believe I'll be using the rootpath module in future Python projects though. Thank you!

grimen commented 4 years ago

OK, good. Thank you for raising the concert, I should add some more docs/examples for sure whenever I get a moment to do that.