Skip to content

Commit

Permalink
Feature/issue 29 add poetry (#30)
Browse files Browse the repository at this point in the history
* passed tests with latest versions

* changed integration workflow

* changed integration workflow

* changed integration workflow

* try minio/minio

* try minio/minio

* try minio/minio

* go back to bitnami/minio:latest

* go back to bitnami/minio:latest

* go back to bitnami/minio:latest

* try more python versions

* try more python versions

* fixed publish to use poetry
  • Loading branch information
IamTugy authored Aug 10, 2024
1 parent a033ecd commit f5cb7b2
Show file tree
Hide file tree
Showing 11 changed files with 1,192 additions and 529 deletions.
36 changes: 21 additions & 15 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,46 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

services:
minio:
# Not using official minio image minio/minio because it requires arguments (start /data)
# and github actions currently not supporting docker araguments
# bitnami/minio image has 1M+ pulls and is up to date so it's should be OK to use it
image: bitnami/minio
env:
MINIO_ACCESS_KEY: administrator
MINIO_SECRET_KEY: administrator
# bitnami/minio image has 10M+ pulls and is up to date so it's should be OK to use it
image: bitnami/minio:latest
ports:
- 9000:9000
options: --name minio-server
- '9000:9000'
- '9001:9001'
env:
MINIO_ROOT_USER: administrator
MINIO_ROOT_PASSWORD: administrator
options: >-
--health-cmd "curl -I http://localhost:9000/minio/health/live"
--health-interval 10s
--health-timeout 5s
--health-retries 6
--health-start-period 30s
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install .
pip install pylint poetry
poetry install --with dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: integration tests
run: pytest
run: poetry run pytest tests
env:
MINIO_TEST_CONNECTION: localhost:9000
MINIO_TEST_ACCESS_KEY: administrator
Expand Down
29 changes: 18 additions & 11 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ name: Upload Python Package

on:
release:
types: [created]
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
poetry lock
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
poetry install
- name: Build package
run: poetry build

- name: Publish package
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
poetry config pypi-token.pypi ${PYPI_API_TOKEN}
poetry publish
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@ Pyminio is a wrapper to minio, that is more indecative for the user.
It works like `os` module, so you don't need to understand minio's concepts, and just using regular paths.

## Content
1. [Installation](#Installation)
2. [Setting up Pyminio](#Setting-up-Pyminio)
3. [Usage](#Usage)
4. [Contribute](#Contribute)
1. [Installation](#installation)
2. [Setting up Pyminio](#setting-up-pyminio)
3. [Usage](#usage)
4. [Contribute](#contribute)

## Installation
Use the package manager [pip](https://pypi.org/project/pyminio/) to install pyminio.

```bash
pip install pyminio
```
or
```bash
git clone https://github.com/mmm1513/pyminio.git
cd pyminio
python setup.py install # also `pip install ."
# `pip install -e '.[dev]'` for development
```

## Setting up Pyminio

Expand Down Expand Up @@ -62,19 +55,19 @@ Firstly you need to set up your [Minio Docker](https://hub.docker.com/r/minio/m
```

## Usage
- [mkdirs](#mkdirs)
- [listdir](#listdir)
- [exists](#exists)
- [isdir](#isdir)
- [truncate](#truncate)
- [rmdir](#rmdir)
- [rm](#rm)
- [cp](#cp)
- [mv](#mv)
- [get](#get)
- [get_last_object](#get_last_object)
- [put_data](#put_data)
- [put_file](#put_file)
- [mkdirs](#mkdirsself-path-str)
- [listdir](#listdirself-path-str-files_only-bool--false-dirs_only-bool--false---tuplestr)
- [exists](#existsself-path-str---bool)
- [isdir](#isdirself-path-str)
- [truncate](#truncateself---pyminio)
- [rmdir](#rmdirself-path-str-recursive-bool--false---pyminio)
- [rm](#rmself-path-str-recursive-bool--false---pyminio)
- [cp](#cpself-from_path-str-to_path-str-recursive-bool--false---pyminio)
- [mv](#mvself-from_path-str-to_path-str-recursive-bool--false---pyminio)
- [get](#getself-path-str---objectdata)
- [get_last_object](#get_last_objectself-path-str---file)
- [put_data](#put_dataself-path-str-data-bytes-metadata-dict--none)
- [put_file](#put_fileself-file_path-str-to_path-str-metadata-dict--none)

### <a name="mkdirs"></a>mkdirs(self, path: str)
`Pyminio.mkdirs` will create the given full path if not exists like linux's `mkdir -p`.
Expand Down Expand Up @@ -161,7 +154,7 @@ DirectoryNotEmptyError: can not recursively delete non-empty directory
```

### <a name="rm"></a>rm(self, path: str, recursive: bool = False) -> Pyminio
`Pyminio.rm` works like [rmdir](#rmdir) only that it can delete files too. Works like linux's `rm (-r)`.
`Pyminio.rm` works like [rmdir](#rmdirself-path-str-recursive-bool--false---pyminio) only that it can delete files too. Works like linux's `rm (-r)`.

```python
>>> pyminio_client.rm('/foo/bar/baz/file_name')
Expand Down Expand Up @@ -191,7 +184,7 @@ ValueError: can not activate this method from directory to a file.
```

### <a name="mv"></a>mv(self, from_path: str, to_path: str, recursive: bool = False) -> Pyminio
`Pyminio.mv` works like [cp](#cp) only that it removes the source after the transfer has been completed. Works like linux's `mv`.
`Pyminio.mv` works like [cp](#cpself-from_path-str-to_path-str-recursive-bool--false---pyminio) only that it removes the source after the transfer has been completed. Works like linux's `mv`.

This method can only move recursively when the recursive flag is True. If not, it will raise a ValueError.

Expand All @@ -208,12 +201,12 @@ This objects will contain metadata, their path and name.
>>> pyminio_client.get('/foo/bar/baz')
File(name='baz',
full_path='/foo/bar/baz',
metadata=AttrDict({
metadata={
'is_dir': False,
'last_modified': time.struct_time(...),
'size': ...,
'content-type': ...
}),
},
data=...)
```

Expand All @@ -226,12 +219,12 @@ This method must get a directory path or it will raise a ValueError.
>>> pyminio_client.get_last_object('/foo/bar/')
File(name='baz',
full_path='/foo/bar/baz',
metadata=AttrDict({
metadata={
'is_dir': False,
'last_modified': time.struct_time(...),
'size': ...,
'content-type': ...
}),
},
data=...)
```

Expand All @@ -245,7 +238,7 @@ File(name='baz',
```

### <a name="put_file"></a>put_file(self, file_path: str, to_path: str, metadata: Dict = None)
`Pyminio.put_file` works like [put_data](#put_data) only that instead of data it gets a path to a file in you computer. Then it will copy this file to the given location.
`Pyminio.put_file` works like [put_data](#put_dataself-path-str-data-bytes-metadata-dict--none) only that instead of data it gets a path to a file in you computer. Then it will copy this file to the given location.

```python
>>> metadata = {'Pyminio-is': 'Awesome'}
Expand All @@ -256,18 +249,25 @@ File(name='baz',

All contributions are welcome:

- Read the [issues](https://github.com/mmm1513/pyminio/issues), Fork the [project](https://github.com/mmm1513/pyminio) and create a new Pull Request.
- Read the [issues](https://github.com/IamTugy/pyminio/issues), Fork the [project](https://github.com/IamTugy/pyminio) and create a new Pull Request.
- Request a new feature creating a `New issue` with the `enhancement` tag.
- Find any kind of errors in the code and create a `New issue` with the details, or fork the project and do a Pull Request.
- Suggest a better or more pythonic way for existing examples.

### Work environment

After forking the project and installing the dependencies, (like specified in the [installations](#Installation) in part 2)
After forking the project and installing the dependencies, (like specified in the [installations](#installation) in part 2)
download the [minio docker](https://hub.docker.com/r/minio/minio/) and start an instance in your computer for development and testing.

Export The same environment variables you've used to set up your local minio:
```bash
export MINIO_TEST_CONNECTION="<your API host>" # example: 127.0.0.1:9000
export MINIO_TEST_ACCESS_KEY="<your user>" # example: ROOTNAME
export MINIO_TEST_SECRET_KEY="<your password>" # example: CHANGEME123
```

to run the tests run:
```bash
pytest
poetry run pytest tests
```
#### Don't forget to write tests, and to run all the tests before making a pull request.
Loading

0 comments on commit f5cb7b2

Please sign in to comment.