Name | pyprojroot JSON |
Version |
0.3.0
JSON |
| download |
home_page | |
Summary | Project-oriented workflow in Python |
upload_time | 2023-03-13 05:39:30 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Project-oriented workflow in Python
Finding project directories in Python (data science) projects.
This library aims to provide both
the programmatic functionality from the R [`rprojroot`][rprojroot] package
and the interactive functionality from the R [`here`][here] package.
## Motivation
**Problem**: I have a project that has a specific folder structure,
for example, one mentioned in [Noble 2009][noble2009] or something similar to [this project template][project-template],
and I want to be able to:
1. Run my python scripts without having to specify a series of `../` to get to the `data` folder.
2. `cd` into the directory of my python script instead of calling it from the root project directory and specify all the folders to the script.
3. Reference datasets from a root directory when using a jupyter notebook because everytime I use a jupyter notebook,
the working directory changes to the location of the notebook, not where I launched the notebook server.
**Solution**: `pyprojroot` finds the root working directory for your project as a `pathlib.Path` object.
You can now use the `here` function to pass in a relative path from the project root directory
(no matter what working directory you are in the project),
and you will get a full path to the specified file.
That is, in a jupyter notebook,
you can write something like `pandas.read_csv(here('data/my_data.csv'))`
instead of `pandas.read_csv('../data/my_data.csv')`.
This allows you to restructure the files in your project without having to worry about changing file paths.
Great for reading and writing datasets!
Further reading:
* [Project-oriented workflows](https://www.tidyverse.org/articles/2017/12/workflow-vs-script/)
* [Stop the working directory insanity](https://gist.github.com/jennybc/362f52446fe1ebc4c49f)
* [Ode to the here package](https://github.com/jennybc/here_here)
## Installation
### pip
```bash
python -m pip install pyprojroot
```
### conda
https://anaconda.org/conda-forge/pyprojroot
```bash
conda install -c conda-forge pyprojroot
```
## Example Usage
### Interactive
This is based on the R [`here`][here] library.
```python
from pyprojroot.here import here
here()
```
### Programmatic
This based on the R [`rprojroot`][rprojroot] library.
```python
import pyprojroot
base_path = pyprojroot.find_root(pyprojroot.has_dir(".git"))
```
## Demonstration
Load the packages
```
In [1]: from pyprojroot.here import here
In [2]: import pandas as pd
```
The current working directory is the "notebooks" folder
```
In [3]: !pwd
/home/dchen/git/hub/scipy-2019-pandas/notebooks
```
In the notebooks folder, I have all my notebooks
```
In [4]: !ls
01-intro.ipynb 02-tidy.ipynb 03-apply.ipynb 04-plots.ipynb 05-model.ipynb Untitled.ipynb
```
If I wanted to access data in my notebooks I'd have to use `../data`
```
In [5]: !ls ../data
billboard.csv country_timeseries.csv gapminder.tsv pew.csv table1.csv table2.csv table3.csv table4a.csv table4b.csv weather.csv
```
However, with there `here` function, I can access my data all from the project root.
This means if I move the notebook to another folder or subfolder I don't have to change the path to my data.
Only if I move the data to another folder would I need to change the path in my notebook (or script)
```
In [6]: pd.read_csv(here('data/gapminder.tsv'), sep='\t').head()
Out[6]:
country continent year lifeExp pop gdpPercap
0 Afghanistan Asia 1952 28.801 8425333 779.445314
1 Afghanistan Asia 1957 30.332 9240934 820.853030
2 Afghanistan Asia 1962 31.997 10267083 853.100710
3 Afghanistan Asia 1967 34.020 11537966 836.197138
4 Afghanistan Asia 1972 36.088 13079460 739.981106
```
By the way, you get a `pathlib.Path` object path back!
```
In [7]: here('data/gapminder.tsv')
Out[7]: PosixPath('/home/dchen/git/hub/scipy-2019-pandas/data/gapminder.tsv')
```
[here]: https://github.com/r-lib/here
[rprojroot]: https://github.com/r-lib/rprojroot
[noble2009]: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1000424
[project-template]: https://chendaniely.github.io/sdal/2017/05/30/project_templates/
Raw data
{
"_id": null,
"home_page": "",
"name": "pyprojroot",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Daniel Chen <chendaniely@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ec/7f/d04044efe4acc4185db1174209fadac33cc21c015ed0d6bef8884c9fa808/pyprojroot-0.3.0.tar.gz",
"platform": null,
"description": "# Project-oriented workflow in Python\n\nFinding project directories in Python (data science) projects.\n\nThis library aims to provide both\nthe programmatic functionality from the R [`rprojroot`][rprojroot] package\nand the interactive functionality from the R [`here`][here] package.\n\n## Motivation\n\n**Problem**: I have a project that has a specific folder structure,\nfor example, one mentioned in [Noble 2009][noble2009] or something similar to [this project template][project-template],\nand I want to be able to:\n\n1. Run my python scripts without having to specify a series of `../` to get to the `data` folder.\n2. `cd` into the directory of my python script instead of calling it from the root project directory and specify all the folders to the script.\n3. Reference datasets from a root directory when using a jupyter notebook because everytime I use a jupyter notebook,\n the working directory changes to the location of the notebook, not where I launched the notebook server.\n\n**Solution**: `pyprojroot` finds the root working directory for your project as a `pathlib.Path` object.\nYou can now use the `here` function to pass in a relative path from the project root directory\n(no matter what working directory you are in the project),\nand you will get a full path to the specified file.\nThat is, in a jupyter notebook,\nyou can write something like `pandas.read_csv(here('data/my_data.csv'))`\ninstead of `pandas.read_csv('../data/my_data.csv')`.\nThis allows you to restructure the files in your project without having to worry about changing file paths.\n\nGreat for reading and writing datasets!\n\nFurther reading:\n\n* [Project-oriented workflows](https://www.tidyverse.org/articles/2017/12/workflow-vs-script/)\n* [Stop the working directory insanity](https://gist.github.com/jennybc/362f52446fe1ebc4c49f)\n* [Ode to the here package](https://github.com/jennybc/here_here)\n\n## Installation\n\n### pip\n\n```bash\npython -m pip install pyprojroot\n```\n\n### conda\n\nhttps://anaconda.org/conda-forge/pyprojroot\n\n```bash\nconda install -c conda-forge pyprojroot\n```\n\n## Example Usage\n\n### Interactive\n\nThis is based on the R [`here`][here] library.\n\n```python\nfrom pyprojroot.here import here\n\nhere()\n```\n\n### Programmatic\n\nThis based on the R [`rprojroot`][rprojroot] library.\n\n```python\nimport pyprojroot\n\nbase_path = pyprojroot.find_root(pyprojroot.has_dir(\".git\"))\n```\n\n## Demonstration\n\nLoad the packages\n\n```\nIn [1]: from pyprojroot.here import here\nIn [2]: import pandas as pd\n```\n\nThe current working directory is the \"notebooks\" folder\n\n```\nIn [3]: !pwd\n/home/dchen/git/hub/scipy-2019-pandas/notebooks\n```\n\nIn the notebooks folder, I have all my notebooks\n\n```\nIn [4]: !ls\n01-intro.ipynb 02-tidy.ipynb 03-apply.ipynb 04-plots.ipynb 05-model.ipynb Untitled.ipynb\n```\n\nIf I wanted to access data in my notebooks I'd have to use `../data`\n\n```\nIn [5]: !ls ../data\nbillboard.csv country_timeseries.csv gapminder.tsv pew.csv table1.csv table2.csv table3.csv table4a.csv table4b.csv weather.csv\n```\n\nHowever, with there `here` function, I can access my data all from the project root.\nThis means if I move the notebook to another folder or subfolder I don't have to change the path to my data.\nOnly if I move the data to another folder would I need to change the path in my notebook (or script)\n\n```\nIn [6]: pd.read_csv(here('data/gapminder.tsv'), sep='\\t').head()\nOut[6]:\n country continent year lifeExp pop gdpPercap\n0 Afghanistan Asia 1952 28.801 8425333 779.445314\n1 Afghanistan Asia 1957 30.332 9240934 820.853030\n2 Afghanistan Asia 1962 31.997 10267083 853.100710\n3 Afghanistan Asia 1967 34.020 11537966 836.197138\n4 Afghanistan Asia 1972 36.088 13079460 739.981106\n```\n\nBy the way, you get a `pathlib.Path` object path back!\n\n```\nIn [7]: here('data/gapminder.tsv')\nOut[7]: PosixPath('/home/dchen/git/hub/scipy-2019-pandas/data/gapminder.tsv')\n```\n\n[here]: https://github.com/r-lib/here\n[rprojroot]: https://github.com/r-lib/rprojroot\n[noble2009]: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1000424\n[project-template]: https://chendaniely.github.io/sdal/2017/05/30/project_templates/\n",
"bugtrack_url": null,
"license": "",
"summary": "Project-oriented workflow in Python",
"version": "0.3.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "539beef01392be945c0fe86a8d084ba9188b1e2b22af037d7109b9f40a962cd0",
"md5": "030263ea91c66b06d5bb29cbdc54c545",
"sha256": "c426b51b17ab4f4d4f95b479cf5b6c22df59bb58fbd4f01b37a6977d29b99888"
},
"downloads": -1,
"filename": "pyprojroot-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "030263ea91c66b06d5bb29cbdc54c545",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7558,
"upload_time": "2023-03-13T05:39:28",
"upload_time_iso_8601": "2023-03-13T05:39:28.707906Z",
"url": "https://files.pythonhosted.org/packages/53/9b/eef01392be945c0fe86a8d084ba9188b1e2b22af037d7109b9f40a962cd0/pyprojroot-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec7fd04044efe4acc4185db1174209fadac33cc21c015ed0d6bef8884c9fa808",
"md5": "b5d96d9c45f3a898774146e0f90bc2e7",
"sha256": "109705bb790968704958efcfc5ccce85d8e3dafa054897cc81371fcbbf56cb10"
},
"downloads": -1,
"filename": "pyprojroot-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "b5d96d9c45f3a898774146e0f90bc2e7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6287,
"upload_time": "2023-03-13T05:39:30",
"upload_time_iso_8601": "2023-03-13T05:39:30.318593Z",
"url": "https://files.pythonhosted.org/packages/ec/7f/d04044efe4acc4185db1174209fadac33cc21c015ed0d6bef8884c9fa808/pyprojroot-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-13 05:39:30",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "pyprojroot"
}