Skip to content

Commit

Permalink
Replace pkg_resources with importlib.resources
Browse files Browse the repository at this point in the history
Fix "DeprecationWarning: pkg_resources is deprecated as an API." seen
when running tests.

In addition:

- increase test coverage for `formatters.py`
- replace deprecated `set-output` in `test.yml` workflow
- remove redundant lines in `Makefile`
- make minor grammatical and formatting fixes to `CONTRIBUTING.md`
- remove old, redundant "Code of Conduct" section from `CONTRIBUTING.md`
  and insert link to `CODE_OF_CONDUCT.md`
- fix bare links in `CODE_OF_CONDUCT.md`
  • Loading branch information
chuckwondo authored and doug-newman-nasa committed Apr 8, 2024
1 parent 994b178 commit b566edb
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Get full python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT
- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
Expand Down
13 changes: 6 additions & 7 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ include:
Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
professional setting

## Our Responsibilities

Expand All @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
reported by contacting the project team at <[email protected]>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand All @@ -68,10 +68,9 @@ members of the project's leadership.
## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

<https://www.contributor-covenant.org/faq>
153 changes: 51 additions & 102 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,64 @@
When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Please note that we have a [code of conduct](./CODE_OF_CONDUCT.md). Please follow it in all of your interactions with the project.

## Development environment


`earthaccess` is a Python library that uses Poetry to build and publish the package to PyPI, the defacto Python repository. In order to develop new features or patch bugs etc. we need to set up a virtual environment and install the library locally. We can accomplish this with both Poetry or/and Conda.

### Using Conda

If we have `mamba` (or conda) installed, we can use the environment file included in the binder folder, this will install all the libraries we need (including Poetry) to start developing `earthaccess`
If we have `mamba` (or `conda`) installed, we can use the environment file included in the `ci` folder. This will install all the libraries we need (including Poetry) to start developing `earthaccess`:

```bash
>mamba env update -f ci/environment-dev.yml
>mamba activate earthaccess-dev
>poetry install
mamba env update -f ci/environment-dev.yml
mamba activate earthaccess-dev
poetry install
```

After activating our environment and installing the library with Poetry we can run Jupyter lab and start testing the local distribution or we can use the scripts inside `scripts` to run the tests and linting.
After activating our environment and installing the library with Poetry we can run Jupyter lab and start testing the local distribution or we can use `make` to run the tests and lint the code.
Now we can create a feature branch and push those changes to our fork!


### Using Poetry

If we want to use Poetry, first we need to [install it](https://python-poetry.org/docs/#installation). After installing Poetry we can use the same workflow we used for Conda, first we install the library locally:

```bash
>poetry install
poetry install
```

and now we can run the local Jupyter Lab and run the scripts etc. using Poetry:

```bash
>poetry run jupyter lab
poetry run jupyter lab
```

### Managing Dependencies

If you need to add a dependency, you should do the following:

- Run `poetry add <package>` for a required (non-development) dependency
- Run `poetry add --group=dev <package>` for a development dependency, such
as a testing or code analysis dependency

Both commands will add an entry to `pyproject.toml` with a version that is
compatible with the rest of the dependencies. However, `poetry` pins versions
with a caret (`^`), which is not what we want. Therefore, you must locate the
new entry in `pyproject.toml` and change the `^` to `>=`. (See
[poetry-relax](https://github.com/zanieb/poetry-relax) for the reasoning behind
this.)

In addition, you must also add a corresponding entry to
`ci/environment-mindeps.yaml`. You'll notice in that file that required
dependencies should be pinned exactly to the versions specified in
`pyproject.toml` (after changing `^` to `>=` there), and that development
dependencies should be left unpinned.

Finally, for _development dependencies only_, you must add an entry to
`ci/environment-dev.yaml` with the same version constraint as in
`pyproject.toml`.

## First Steps to fix an issue or bug

- Read the documentation (working on adding more)
Expand All @@ -55,45 +77,47 @@ and now we can run the local Jupyter Lab and run the scripts etc. using Poetry:
- create new tests as you go, and run the test suite as you go
- update the documentation as you go

### Please format and lint as you go with the following scripts
### Please format and lint as you go

```bash
scripts/lint.sh
scripts/format.sh
make format lint
```

### Requirements to merge code (Pull Request Process)

- you must include test coverage
- you must update the documentation
- you must run the above scripts to format and line
- you must run the command above to format and lint

## Pull Request process

1. Ensure you include test coverage for all changes
2. Ensure your code is formatted properly following this document
3. Update the documentation and the README.md with details of changes to the interface,
this includes new environment variables, function names, decorators, etc.
3. Update `CHANGELOG.md` with details about your change in a section titled
1. Ensure your code is formatted properly following this document
1. Update the documentation and the `README.md` with details of changes to the
interface, this includes new environment variables, function names,
decorators, etc.
1. Update `CHANGELOG.md` with details about your change in a section titled
`Unreleased`. If one does not exist, please create one.
4. You may merge the Pull Request in once you have the sign-off of another developers,
or if you do not have permission to do that, you may request the reviewer to merge it
for you.
1. You may merge the Pull Request once you have the sign-off of another
developer, or if you do not have permission to do that, you may request the
reviewer to merge it for you.

## Release process

> :memo: The versioning scheme we use is [SemVer](http://semver.org/). Note that until
> we agree we're ready for v1.0.0, we will not increment major version.
> we agree we're ready for v1.0.0, we will not increment the major version.
0. Ensure all desired features are merged to `main` branch and `CHANGELOG` is updated.
1. Ensure all desired features are merged to `main` branch and `CHANGELOG.md` is updated.
1. Use `bump-my-version` to increase the version number in all needed places, e.g. to
increase the minor version (`1.2.3` to `1.3.0`):
```

```plain
bump-my-version bump minor
```
2. Push a tag on the new commit containing the version number, prefixed with `v`, e.g.

1. Push a tag on the new commit containing the version number, prefixed with `v`, e.g.
`v1.3.0`.
3. [Create a new GitHub Release](https://github.com/nsidc/earthaccess/releases/new). We
1. [Create a new GitHub Release](https://github.com/nsidc/earthaccess/releases/new). We
hand-curate our release notes to be valuable to humans. Please do not auto-generate
release notes and aim for consistency with the GitHub Release descriptions from other
releases.
Expand All @@ -106,78 +130,3 @@ scripts/format.sh
> :memo: `earthaccess` is published to conda-forge through the
> [earthdata-feedstock](https://github.com/conda-forge/earthdata-feedstock), as this
> project was renamed early in its life. The conda package is named `earthaccess`.
---

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [PurpleBooth's Contributing Template][contributing-template-url]

[contributing-template-url]: https://gist.github.com/PurpleBooth/b24679402957c63ec426/5c4f62c1e50c1e6654e76e873aba3df2b0cdeea2
30 changes: 5 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,35 @@ HASH := $(shell git rev-parse HEAD)
help:
# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# adds anything that has a double # comment to the phony help list
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ".:*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ".:*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


python-three-eight:
python-three-eight: ## setup python3.8 virtual environment using poetry
poetry env use python3.8
poetry install
PIP_REQUIRE_VENV=0 poetry install

python-three-nine:
python-three-nine: ## setup python3.9 virtual environment using poetry
poetry env use python3.9
poetry install
PIP_REQUIRE_VENV=0 poetry install

python-three-ten:
python-three-ten: ## setup python3.9 virtual environment using poetry
python-three-ten: ## setup python3.10 virtual environment using poetry
poetry env use python3.10
poetry install


PIP_REQUIRE_VENV=0 poetry install


pre-commit:
pre-commit: ## setup pre-commit within poetry
poetry run pre-commit install

lint: ## lint the code
lint:
bash scripts/lint.sh

format: ## format the code
format:
bash scripts/format.sh

test: ## lint the code
test:
bash scripts/test.sh

docs-live: ## make live docs
docs-live:
bash scripts/docs-live.sh

deploy-docs: ## deploy the docs, if on master branch
deploy-docs:
# https://www.mkdocs.org/user-guide/deploying-your-docs/

# moved script to bash file for easy of reading
bash scripts/deploy-docs.sh

install: ## uninstall and install package with python
install:
poetry remove ./earthaccess
poetry add ./earthaccess
1 change: 1 addition & 0 deletions ci/environment-mindeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- tinynetrc=1.3.1
- multimethod=1.8
- python-dateutil=2.8.2
- importlib-resources=6.3.2
# test dependencies
- responses
- pytest
Expand Down
12 changes: 6 additions & 6 deletions earthaccess/formatters.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import Any, List
from uuid import uuid4

import pkg_resources
import importlib_resources

STATIC_FILES = ["css/iso_bootstrap4.0.0min.css", "css/styles.css"]
STATIC_FILES = ["iso_bootstrap4.0.0min.css", "styles.css"]


def _load_static_files() -> List[str]:
"""Load styles"""
return [
pkg_resources.resource_string("earthaccess", fname).decode("utf8")
importlib_resources.files("earthaccess.css").joinpath(fname).read_text("utf8")
for fname in STATIC_FILES
]

Expand All @@ -27,7 +27,7 @@ def _repr_granule_html(granule: Any) -> str:
dataviz_img = "".join(
[
f'<a href="{link}"><img style="{style}" src="{link}" alt="Data Preview"/></a>'
for link in granule.dataviz_links()[0:2]
for link in granule.dataviz_links()[:2]
if link.startswith("http")
]
)
Expand All @@ -38,8 +38,9 @@ def _repr_granule_html(granule: Any) -> str:
]
)
granule_size = round(granule.size(), 2)

# TODO: probably this needs to be integrated on a list data structure
granule_str = f"""
return f"""
{css_inline}
<div class="bootstrap">
<div class="container-fluid border">
Expand All @@ -56,4 +57,3 @@ def _repr_granule_html(granule: Any) -> str:
</div>
</div>
"""
return granule_str
Loading

0 comments on commit b566edb

Please sign in to comment.